Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix(OtpInput): failed to load initial value #2085

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading