8
8
namespace BootstrapBlazor . Components ;
9
9
10
10
/// <summary>
11
- /// AutoComplete 组件
11
+ /// AutoComplete component
12
12
/// </summary>
13
13
public partial class AutoComplete
14
14
{
15
15
/// <summary>
16
- /// 获得 组件样式
16
+ /// Gets the component style
17
17
/// </summary>
18
18
private string ? ClassString => CssBuilder . Default ( "auto-complete" )
19
19
. AddClassFromAttributes ( AdditionalAttributes )
20
20
. Build ( ) ;
21
21
22
22
/// <summary>
23
- /// 获得/设置 通过输入字符串获得匹配数据集合
23
+ /// Gets or sets the collection of matching data obtained by inputting a string
24
24
/// </summary>
25
25
[ Parameter ]
26
26
[ NotNull ]
27
27
public IEnumerable < string > ? Items { get ; set ; }
28
28
29
29
/// <summary>
30
- /// 获得/设置 自定义集合过滤规则 默认 null
30
+ /// Gets or sets custom collection filtering rules, default is null
31
31
/// </summary>
32
32
[ Parameter ]
33
33
public Func < string , Task < IEnumerable < string > > > ? OnCustomFilter { get ; set ; }
34
34
35
35
/// <summary>
36
- /// 获得/设置 图标
36
+ /// Gets or sets the icon
37
37
/// </summary>
38
38
[ Parameter ]
39
39
public string ? Icon { get ; set ; }
40
40
41
41
/// <summary>
42
- /// 获得/设置 加载图标
42
+ /// Gets or sets the loading icon
43
43
/// </summary>
44
44
[ Parameter ]
45
45
public string ? LoadingIcon { get ; set ; }
46
46
47
47
/// <summary>
48
- /// 获得/设置 匹配数据时显示的数量
48
+ /// Gets or sets the number of items to display when matching data
49
49
/// </summary>
50
50
[ Parameter ]
51
51
[ NotNull ]
52
52
public int ? DisplayCount { get ; set ; }
53
53
54
54
/// <summary>
55
- /// 获得/设置 是否开启模糊查询,默认为 false
55
+ /// Gets or sets whether to enable fuzzy search, default is false
56
56
/// </summary>
57
57
[ Parameter ]
58
58
public bool IsLikeMatch { get ; set ; }
59
59
60
60
/// <summary>
61
- /// 获得/设置 匹配时是否忽略大小写,默认为 true
61
+ /// Gets or sets whether to ignore case when matching, default is true
62
62
/// </summary>
63
63
[ Parameter ]
64
64
public bool IgnoreCase { get ; set ; } = true ;
65
65
66
66
/// <summary>
67
- /// 获得/设置 获得焦点时是否展开下拉候选菜单 默认 true
67
+ /// Gets or sets whether to expand the dropdown candidate menu when focused, default is true
68
68
/// </summary>
69
69
[ Parameter ]
70
70
public bool ShowDropdownListOnFocus { get ; set ; } = true ;
71
71
72
72
/// <summary>
73
- /// 获得/设置 是否显示无匹配数据选项 默认 true 显示
73
+ /// Gets or sets whether to show the no matching data option, default is true
74
74
/// </summary>
75
75
[ Parameter ]
76
76
public bool ShowNoDataTip { get ; set ; } = true ;
77
77
78
78
/// <summary>
79
- /// IStringLocalizer 服务实例
79
+ /// IStringLocalizer service instance
80
80
/// </summary>
81
81
[ Inject ]
82
82
[ NotNull ]
83
83
private IStringLocalizer < AutoComplete > ? Localizer { get ; set ; }
84
84
85
85
/// <summary>
86
- /// 获得 获得焦点自动显示下拉框设置字符串
86
+ /// Gets the string setting for automatically displaying the dropdown when focused
87
87
/// </summary>
88
88
private string ? ShowDropdownListOnFocusString => ShowDropdownListOnFocus ? "true" : null ;
89
89
@@ -115,7 +115,7 @@ protected override void OnParametersSet()
115
115
}
116
116
117
117
/// <summary>
118
- /// 鼠标点击候选项时回调此方法
118
+ /// Callback method when a candidate item is clicked
119
119
/// </summary>
120
120
private async Task OnClickItem ( string val )
121
121
{
@@ -129,12 +129,15 @@ private async Task OnClickItem(string val)
129
129
private List < string > Rows => _filterItems ?? [ .. Items ] ;
130
130
131
131
/// <summary>
132
- /// TriggerFilter 方法
132
+ /// TriggerFilter method
133
133
/// </summary>
134
134
/// <param name="val"></param>
135
135
[ JSInvokable ]
136
136
public override async Task TriggerFilter ( string val )
137
137
{
138
+ // Store the current input value to prevent it from being overwritten
139
+ var currentInputValue = val ;
140
+
138
141
if ( OnCustomFilter != null )
139
142
{
140
143
var items = await OnCustomFilter ( val ) ;
@@ -157,20 +160,33 @@ public override async Task TriggerFilter(string val)
157
160
{
158
161
_filterItems = [ .. _filterItems . Take ( DisplayCount . Value ) ] ;
159
162
}
160
- await TriggerChange ( val ) ;
163
+
164
+ // Use currentInputValue here instead of potentially stale val
165
+ CurrentValue = currentInputValue ;
166
+
167
+ // Only trigger StateHasChanged if no binding is present
168
+ if ( ! ValueChanged . HasDelegate )
169
+ {
170
+ StateHasChanged ( ) ;
171
+ }
161
172
}
162
173
163
174
/// <summary>
164
- /// TriggerChange 方法
175
+ /// TriggerChange method
165
176
/// </summary>
166
177
/// <param name="val"></param>
167
178
[ JSInvokable ]
168
179
public override Task TriggerChange ( string val )
169
180
{
170
- CurrentValue = val ;
171
- if ( ! ValueChanged . HasDelegate )
181
+ // Only update CurrentValue if the value has actually changed
182
+ // This prevents overwriting the user's input
183
+ if ( CurrentValue != val )
172
184
{
173
- StateHasChanged ( ) ;
185
+ CurrentValue = val ;
186
+ if ( ! ValueChanged . HasDelegate )
187
+ {
188
+ StateHasChanged ( ) ;
189
+ }
174
190
}
175
191
return Task . CompletedTask ;
176
192
}
0 commit comments