Skip to content

Commit

Permalink
πŸ› fix(TextField): ensure getting the latest value in OnEnter event (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Dec 18, 2024
1 parent 1b8bdad commit 28170fa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Masa.Blazor/Components/TextField/MTextField.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ public virtual async Task HandleOnKeyDownAsync(KeyboardEventArgs args)
{
if (args.Key is KeyCodes.Enter or KeyCodes.NumpadEnter)
{
await UpdateValueImmediatelyAsync();

if (OnEnter.HasDelegate)
{
await OnEnter.InvokeAsync();
Expand All @@ -748,6 +750,19 @@ public virtual async Task HandleOnKeyDownAsync(KeyboardEventArgs args)
}
}

/// <summary>
/// Update the bound value immediately.
/// For some scenarios, like OnEnter event and inner icon click event,
/// we need to update the value immediately.
/// </summary>
[MasaApiPublicMethod]
public async Task UpdateValueImmediatelyAsync()
{
var originValue = await Js.InvokeAsync<string>(JsInteropConstants.GetProp, InputElement, "value");

await HandleOnInputOrChangeEvent(new ChangeEventArgs { Value = originValue }, OnChange, nameof(OnChange));
}

public virtual async Task HandleOnClearClickAsync(MouseEventArgs args)
{
UpdateInternalValue(default, InternalValueChangeType.InternalOperation);
Expand Down

0 comments on commit 28170fa

Please sign in to comment.