File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed
src/BootstrapBlazor/Components/Textarea Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 66{
77 <BootstrapLabel required =" @Required" for =" @Id" ShowLabelTooltip =" ShowLabelTooltip" Value =" @DisplayText" />
88}
9- <textarea @attributes =" AdditionalAttributes" placeholder =" @PlaceHolder" id =" @Id" class =" @ClassName" disabled =" @Disabled" @bind-value =" @CurrentValueAsString" @bind-value:event =" @EventString" data-bb-scroll =" @AutoScrollString" @ref =" FocusElement" ></textarea >
9+ <textarea @attributes =" AdditionalAttributes" placeholder =" @PlaceHolder" id =" @Id" class =" @ClassName" disabled =" @Disabled" @bind-value =" @CurrentValueAsString" @bind-value:event =" @EventString" @onblur = " OnBlur " data-bb-scroll =" @AutoScrollString" @ref =" FocusElement" ></textarea >
Original file line number Diff line number Diff line change @@ -34,6 +34,12 @@ public partial class Textarea
3434 [ Parameter ]
3535 public bool IsAutoScroll { get ; set ; }
3636
37+ /// <summary>
38+ /// 获得/设置 失去焦点回调方法 默认 null
39+ /// </summary>
40+ [ Parameter ]
41+ public Func < string ? , Task > ? OnBlurAsync { get ; set ; }
42+
3743 /// <summary>
3844 /// 获得 客户端是否自动滚屏标识
3945 /// </summary>
@@ -53,4 +59,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
5359 await InvokeVoidAsync ( "execute" , Id , "update" ) ;
5460 }
5561 }
62+
63+ /// <summary>
64+ /// OnBlur 方法
65+ /// </summary>
66+ protected virtual async Task OnBlur ( )
67+ {
68+ if ( OnBlurAsync != null )
69+ {
70+ await OnBlurAsync ( Value ) ;
71+ }
72+ }
5673}
Original file line number Diff line number Diff line change @@ -53,4 +53,21 @@ public void AutoScrollString_OK()
5353 cut . Instance . ScrollToTop ( ) ;
5454 cut . Instance . ScrollToBottom ( ) ;
5555 }
56+
57+ [ Fact ]
58+ public async Task OnBlurAsync_Ok ( )
59+ {
60+ var blur = false ;
61+ var cut = Context . RenderComponent < Textarea > ( builder =>
62+ {
63+ builder . Add ( a => a . OnBlurAsync , v =>
64+ {
65+ blur = true ;
66+ return Task . CompletedTask ;
67+ } ) ;
68+ } ) ;
69+ var input = cut . Find ( "textarea" ) ;
70+ await cut . InvokeAsync ( ( ) => { input . Blur ( ) ; } ) ;
71+ Assert . True ( blur ) ;
72+ }
5673}
You can’t perform that action at this time.
0 commit comments