From 639239b96c31c8a0b02f9e2ee3e13573b015cb46 Mon Sep 17 00:00:00 2001 From: capdiem Date: Fri, 9 Aug 2024 10:33:15 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(OtpInput):=20failed=20to=20l?= =?UTF-8?q?oad=20initial=20value=20(#2085)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/OtpInput/MOtpInput.razor.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Masa.Blazor/Components/OtpInput/MOtpInput.razor.cs b/src/Masa.Blazor/Components/OtpInput/MOtpInput.razor.cs index 6d5d54dcde..5857df10cf 100644 --- a/src/Masa.Blazor/Components/OtpInput/MOtpInput.razor.cs +++ b/src/Masa.Blazor/Components/OtpInput/MOtpInput.razor.cs @@ -92,30 +92,6 @@ protected override async Task OnParametersSetAsync() } #endif - if (_prevValue != Value) - { - Value ??= string.Empty; - var prevValueLength = _prevValue?.Length ?? 0; - var valueLength = Value.Length; - _prevValue = Value; - - for (var i = 0; i < Math.Max(prevValueLength, valueLength); i++) - { - if (i >= _otp.Count) - { - continue; - } - - _otp[i] = i < valueLength ? Value[i].ToString() : string.Empty; - } - - if (Value != ComputedValue) - { - _prevValue = ComputedValue; - await ValueChanged.InvokeAsync(_prevValue); - } - } - if (_prevLength != Length) { _prevLength = Length; @@ -141,6 +117,30 @@ protected override async Task OnParametersSetAsync() } } } + + if (_prevValue != Value) + { + Value ??= string.Empty; + var prevValueLength = _prevValue?.Length ?? 0; + var valueLength = Value.Length; + _prevValue = Value; + + for (var i = 0; i < Math.Max(prevValueLength, valueLength); i++) + { + if (i >= _otp.Count) + { + continue; + } + + _otp[i] = i < valueLength ? Value[i].ToString() : string.Empty; + } + + if (Value != ComputedValue) + { + _prevValue = ComputedValue; + await ValueChanged.InvokeAsync(_prevValue); + } + } } protected override async Task OnAfterRenderAsync(bool firstRender)