Skip to content

Commit

Permalink
fix(AutoFill): support numberpad enter key (#4634)
Browse files Browse the repository at this point in the history
* feat: 增加 IsEnterKey 判断

* refactor: 使用 IsEnterKey 判断键值

* refactor: 增加小键盘支持

* test: 增加小键盘单元测试
  • Loading branch information
ArgoZhang authored Nov 9, 2024
1 parent 67c2e18 commit 6aa8f4d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public virtual async Task OnKeyUp(string key)
await OnEscAsync(Value);
}
}
else if (key == "Enter")
else if (IsEnterKey(key))
{
if (!string.IsNullOrEmpty(CurrentSelectedItem))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function init(id, invoke) {
EventHandler.on(input, 'keyup', debounce(e => {
invoke.invokeMethodAsync('OnKeyUp', e.code)
}, duration, e => {
return ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Escape', 'Enter'].indexOf(e.key) > -1
return ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Escape', 'Enter', 'NumpadEnter'].indexOf(e.key) > -1
}))
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
/// </summary>
/// <returns></returns>
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop);

/// <summary>
/// 判断是否为回车键
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
protected bool IsEnterKey(string key) => key == "Enter" || key == "NumpadEnter";
}
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public virtual async Task OnKeyUp(string key)
await OnEscAsync(Value);
}
}
else if (key == "Enter")
else if (IsEnterKey(key))
{
ActiveSelectedItem ??= _filterItems.FirstOrDefault();
if (ActiveSelectedItem != null)
Expand Down
5 changes: 3 additions & 2 deletions test/UnitTest/Components/AutoCompleteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public class AutoCompleteTest : BootstrapBlazorTestBase
[Fact]
public void Parameter_Ok()
{
var items = new List<string>() { "test1", "test2" };
var cut = Context.RenderComponent<AutoComplete>(builder =>
{
builder.Add(a => a.Items, new string[] { "test1", "test2" });
builder.Add(a => a.Items, items);
builder.Add(a => a.NoDataTip, "test3");
builder.Add(a => a.ShowNoDataTip, true);
builder.Add(a => a.DisplayCount, 10);
Expand Down Expand Up @@ -175,7 +176,7 @@ public void Enter_Test()

cut.InvokeAsync(() => cut.Instance.OnKeyUp("t"));
cut.InvokeAsync(() => cut.Instance.OnKeyUp("ArrowDown"));
cut.InvokeAsync(() => cut.Instance.OnKeyUp("Enter"));
cut.InvokeAsync(() => cut.Instance.OnKeyUp("NumpadEnter"));
Assert.True(enter);
}

Expand Down

0 comments on commit 6aa8f4d

Please sign in to comment.