Skip to content

Commit

Permalink
🐛 fix(OtpInput): failed to load initial value (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Aug 9, 2024
1 parent eb32a2c commit 639239b
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/Masa.Blazor/Components/OtpInput/MOtpInput.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 639239b

Please sign in to comment.