File tree Expand file tree Collapse file tree 3 files changed +42
-6
lines changed
BootstrapBlazor.Server/Components/Components
BootstrapBlazor/Components/AutoComplete Expand file tree Collapse file tree 3 files changed +42
-6
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ private string FindCodeSnippetByName(string code)
148148 {
149149 var regex = new Regex ( $ "<DemoBlock [\\ s\\ S]*? Name=\" { BlockName } \" >([\\ s\\ S]*?)</DemoBlock>") ;
150150 var match = regex . Match ( content ) ;
151- if ( match . Success && match . Groups . Count == 2 )
151+ if ( match is { Success : true , Groups . Count : 2 } )
152152 {
153153 content = match . Groups [ 1 ] . Value . Replace ( "\r \n " , "\n " ) . Replace ( "\n " , "\n " ) . TrimStart ( '\n ' ) ;
154154 }
Original file line number Diff line number Diff line change @@ -59,6 +59,12 @@ public partial class AutoComplete
5959 [ Parameter ]
6060 public bool OnFocusFilter { get ; set ; }
6161
62+ /// <summary>
63+ /// 获得/设置 失去焦点回调方法 默认 null
64+ /// </summary>
65+ [ Parameter ]
66+ public Func < string ? , Task > ? OnBlurAsync { get ; set ; }
67+
6268 /// <summary>
6369 /// 获得/设置 匹配时是否忽略大小写,默认为 true
6470 /// </summary>
@@ -145,10 +151,15 @@ protected override void OnParametersSet()
145151 /// <summary>
146152 /// OnBlur 方法
147153 /// </summary>
148- protected void OnBlur ( )
154+ protected virtual async Task OnBlur ( )
149155 {
150156 CurrentSelectedItem = "" ;
151157 IsShown = false ;
158+
159+ if ( OnBlurAsync != null )
160+ {
161+ await OnBlurAsync ( Value ) ;
162+ }
152163 }
153164
154165 /// <summary>
@@ -239,7 +250,7 @@ public virtual async Task OnKeyUp(string key)
239250 }
240251 else if ( key == "Escape" )
241252 {
242- OnBlur ( ) ;
253+ await OnBlur ( ) ;
243254 if ( ! SkipEsc && OnEscAsync != null )
244255 {
245256 await OnEscAsync ( Value ) ;
@@ -256,7 +267,7 @@ public virtual async Task OnKeyUp(string key)
256267 }
257268 }
258269
259- OnBlur ( ) ;
270+ await OnBlur ( ) ;
260271 if ( ! SkipEnter && OnEnterAsync != null )
261272 {
262273 await OnEnterAsync ( Value ) ;
@@ -268,7 +279,7 @@ public virtual async Task OnKeyUp(string key)
268279 }
269280
270281 /// <summary>
271- ///
282+ /// 自定义按键处理方法
272283 /// </summary>
273284 /// <param name="key"></param>
274285 /// <returns></returns>
Original file line number Diff line number Diff line change @@ -294,7 +294,7 @@ public void ValidateForm_Ok()
294294 [ Fact ]
295295 public void IsPopover_Ok ( )
296296 {
297- IEnumerable < string > items = new List < string > ( ) { "test1" , "test2" } ;
297+ var items = new List < string > ( ) { "test1" , "test2" } ;
298298 var cut = Context . RenderComponent < AutoComplete > ( pb =>
299299 {
300300 pb . Add ( a => a . Items , items ) ;
@@ -309,4 +309,29 @@ public void IsPopover_Ok()
309309 cut . DoesNotContain ( "data-bs-placement" ) ;
310310 cut . Contains ( "data-bs-custom-class=\" ac-pop-test shadow\" " ) ;
311311 }
312+
313+ [ Fact ]
314+ public async Task OnBlurAsync_Ok ( )
315+ {
316+ string ? val = "" ;
317+ var items = new List < string > ( ) { "test1" , "test2" } ;
318+ var cut = Context . RenderComponent < AutoComplete > ( pb =>
319+ {
320+ pb . Add ( a => a . Items , items ) ;
321+ pb . Add ( a => a . OnBlurAsync , v =>
322+ {
323+ val = v ;
324+ return Task . CompletedTask ;
325+ } ) ;
326+ } ) ;
327+
328+ // trigger blur
329+ var input = cut . Find ( "input" ) ;
330+ await cut . InvokeAsync ( ( ) =>
331+ {
332+ input . Input ( "123" ) ;
333+ input . Blur ( ) ;
334+ } ) ;
335+ Assert . Equal ( "123" , val ) ;
336+ }
312337}
You can’t perform that action at this time.
0 commit comments