Skip to content

Commit 88ca87b

Browse files
authored
fix(AutoComplete): OnEnterAsync/OnEscAsync not work (#5474)
* refactor: 代码重构 * refactor: support Enter/Esc key event * chore: bump version 9.4.3-beta01
1 parent 51f0063 commit 88ca87b

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.4.2</Version>
4+
<Version>9.4.3-beta01</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private async Task OnClickItem(string val)
126126
}
127127
}
128128

129-
private List<string> Rows => _filterItems ?? Items.ToList();
129+
private List<string> Rows => _filterItems ?? [.. Items];
130130

131131
/// <summary>
132132
/// TriggerFilter 方法
@@ -138,24 +138,24 @@ public override async Task TriggerFilter(string val)
138138
if (OnCustomFilter != null)
139139
{
140140
var items = await OnCustomFilter(val);
141-
_filterItems = items.ToList();
141+
_filterItems = [.. items];
142142
}
143143
else if (string.IsNullOrEmpty(val))
144144
{
145-
_filterItems = Items.ToList();
145+
_filterItems = [.. Items];
146146
}
147147
else
148148
{
149149
var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
150150
var items = IsLikeMatch
151151
? Items.Where(s => s.Contains(val, comparison))
152152
: Items.Where(s => s.StartsWith(val, comparison));
153-
_filterItems = items.ToList();
153+
_filterItems = [.. items];
154154
}
155155

156156
if (DisplayCount != null)
157157
{
158-
_filterItems = _filterItems.Take(DisplayCount.Value).ToList();
158+
_filterItems = [.. _filterItems.Take(DisplayCount.Value)];
159159
}
160160
StateHasChanged();
161161
}

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function init(id, invoke) {
107107

108108
const handlerKeyup = (ac, e) => {
109109
const key = e.key;
110-
const { el, input, menu } = ac;
110+
const { el, input, invoke, menu } = ac;
111111
if (key === 'Enter' || key === 'NumpadEnter') {
112112
const skipEnter = el.getAttribute('data-bb-skip-enter') === 'true';
113113
if (!skipEnter) {
@@ -116,12 +116,14 @@ const handlerKeyup = (ac, e) => {
116116
el.triggerEnter = true;
117117
current.click();
118118
}
119+
invoke.invokeMethodAsync('EnterCallback', input.value);
119120
}
120121
}
121122
else if (key === 'Escape') {
122123
const skipEsc = el.getAttribute('data-bb-skip-esc') === 'true';
123124
if (skipEsc === false) {
124125
EventHandler.trigger(menu, 'click');
126+
invoke.invokeMethodAsync('EscCallback');
125127
}
126128
}
127129
else if (key === 'ArrowUp' || key === 'ArrowDown') {

0 commit comments

Comments
 (0)