@@ -18,12 +18,6 @@ public partial class AutoComplete
1818 protected virtual string ? ClassString => CssBuilder . Default ( "auto-complete" )
1919 . Build ( ) ;
2020
21- /// <summary>
22- /// 获得 最终候选数据源
23- /// </summary>
24- [ NotNull ]
25- protected List < string > ? FilterItems { get ; private set ; }
26-
2721 /// <summary>
2822 /// 获得/设置 通过输入字符串获得匹配数据集合
2923 /// </summary>
@@ -80,6 +74,12 @@ public partial class AutoComplete
8074 [ Parameter ]
8175 public bool SkipEsc { get ; set ; }
8276
77+ /// <summary>
78+ /// 获得/设置 滚动行为 默认 <see cref="ScrollIntoViewBehavior.Smooth"/>
79+ /// </summary>
80+ [ Parameter ]
81+ public ScrollIntoViewBehavior ScrollIntoViewBehavior { get ; set ; } = ScrollIntoViewBehavior . Smooth ;
82+
8383 /// <summary>
8484 /// 获得/设置 候选项模板 默认 null
8585 /// </summary>
@@ -107,18 +107,21 @@ public partial class AutoComplete
107107
108108 private string CurrentSelectedItem { get ; set ; } = "" ;
109109
110+ private List < string > ? _items ;
111+
112+ private string ? SkipEscString => SkipEsc ? "true" : null ;
113+
114+ private string ? SkipEnterString => SkipEnter ? "true" : null ;
115+
116+ private string ? ScrollIntoViewBehaviorString => ScrollIntoViewBehavior == ScrollIntoViewBehavior . Smooth ? null : ScrollIntoViewBehavior . ToDescriptionString ( ) ;
117+
110118 /// <summary>
111119 /// <inheritdoc/>
112120 /// </summary>
113121 protected override void OnInitialized ( )
114122 {
115123 base . OnInitialized ( ) ;
116124
117- NoDataTip ??= Localizer [ nameof ( NoDataTip ) ] ;
118- PlaceHolder ??= Localizer [ nameof ( PlaceHolder ) ] ;
119- Items ??= [ ] ;
120- FilterItems ??= [ ] ;
121-
122125 SkipRegisterEnterEscJSInvoke = true ;
123126 }
124127
@@ -129,8 +132,12 @@ protected override void OnParametersSet()
129132 {
130133 base . OnParametersSet ( ) ;
131134
135+ NoDataTip ??= Localizer [ nameof ( NoDataTip ) ] ;
136+ PlaceHolder ??= Localizer [ nameof ( PlaceHolder ) ] ;
132137 Icon ??= IconTheme . GetIconByKey ( ComponentIcons . AutoCompleteIcon ) ;
133138 LoadingIcon ??= IconTheme . GetIconByKey ( ComponentIcons . LoadingIcon ) ;
139+
140+ _items = Items ? . ToList ( ) ;
134141 }
135142
136143 /// <summary>
@@ -153,58 +160,60 @@ protected virtual async Task OnClickItem(string val)
153160 [ JSInvokable ]
154161 public virtual async Task OnKeyUp ( string key )
155162 {
156- var source = FilterItems ;
157- if ( source . Count > 0 )
158- {
159- // 键盘向上选择
160- if ( key == "ArrowUp" )
161- {
162- var index = source . IndexOf ( CurrentSelectedItem ) - 1 ;
163- if ( index < 0 )
164- {
165- index = source . Count - 1 ;
166- }
167- CurrentSelectedItem = source [ index ] ;
168- CurrentItemIndex = index ;
169- }
170- else if ( key == "ArrowDown" )
171- {
172- var index = source . IndexOf ( CurrentSelectedItem ) + 1 ;
173- if ( index > source . Count - 1 )
174- {
175- index = 0 ;
176- }
177- CurrentSelectedItem = source [ index ] ;
178- CurrentItemIndex = index ;
179- }
180- else if ( key == "Escape" )
181- {
182- await OnBlur ( ) ;
183- if ( ! SkipEsc && OnEscAsync != null )
184- {
185- await OnEscAsync ( Value ) ;
186- }
187- }
188- else if ( IsEnterKey ( key ) )
189- {
190- if ( ! string . IsNullOrEmpty ( CurrentSelectedItem ) )
191- {
192- CurrentValueAsString = CurrentSelectedItem ;
193- if ( OnSelectedItemChanged != null )
194- {
195- await OnSelectedItemChanged ( CurrentSelectedItem ) ;
196- }
197- }
198-
199- await OnBlur ( ) ;
200- if ( ! SkipEnter && OnEnterAsync != null )
201- {
202- await OnEnterAsync ( Value ) ;
203- }
204- }
205- }
206- await CustomKeyUp ( key ) ;
207- StateHasChanged ( ) ;
163+ await Task . Delay ( 0 ) ;
164+
165+ //var source = FilterItems;
166+ //if (source.Count > 0)
167+ //{
168+ // // 键盘向上选择
169+ // if (key == "ArrowUp")
170+ // {
171+ // var index = source.IndexOf(CurrentSelectedItem) - 1;
172+ // if (index < 0)
173+ // {
174+ // index = source.Count - 1;
175+ // }
176+ // CurrentSelectedItem = source[index];
177+ // CurrentItemIndex = index;
178+ // }
179+ // else if (key == "ArrowDown")
180+ // {
181+ // var index = source.IndexOf(CurrentSelectedItem) + 1;
182+ // if (index > source.Count - 1)
183+ // {
184+ // index = 0;
185+ // }
186+ // CurrentSelectedItem = source[index];
187+ // CurrentItemIndex = index;
188+ // }
189+ // else if (key == "Escape")
190+ // {
191+ // await OnBlur();
192+ // if (!SkipEsc && OnEscAsync != null)
193+ // {
194+ // await OnEscAsync(Value);
195+ // }
196+ // }
197+ // else if (IsEnterKey(key))
198+ // {
199+ // if (!string.IsNullOrEmpty(CurrentSelectedItem))
200+ // {
201+ // CurrentValueAsString = CurrentSelectedItem;
202+ // if (OnSelectedItemChanged != null)
203+ // {
204+ // await OnSelectedItemChanged(CurrentSelectedItem);
205+ // }
206+ // }
207+
208+ // await OnBlur();
209+ // if (!SkipEnter && OnEnterAsync != null)
210+ // {
211+ // await OnEnterAsync(Value);
212+ // }
213+ // }
214+ //}
215+ //await CustomKeyUp(key);
216+ //StateHasChanged();
208217 }
209218
210219 /// <summary>
@@ -224,20 +233,20 @@ public async Task TriggerOnChange(string val)
224233 if ( OnCustomFilter != null )
225234 {
226235 var items = await OnCustomFilter ( val ) ;
227- FilterItems = items . ToList ( ) ;
236+ _items = items . ToList ( ) ;
228237 }
229238 else
230239 {
231240 var comparison = IgnoreCase ? StringComparison . OrdinalIgnoreCase : StringComparison . Ordinal ;
232241 var items = IsLikeMatch
233242 ? Items . Where ( s => s . Contains ( val , comparison ) )
234243 : Items . Where ( s => s . StartsWith ( val , comparison ) ) ;
235- FilterItems = items . ToList ( ) ;
244+ _items = items . ToList ( ) ;
236245 }
237246
238247 if ( DisplayCount != null )
239248 {
240- FilterItems = FilterItems . Take ( DisplayCount . Value ) . ToList ( ) ;
249+ _items = _items . Take ( DisplayCount . Value ) . ToList ( ) ;
241250 }
242251
243252 CurrentValue = val ;
0 commit comments