File tree Expand file tree Collapse file tree 3 files changed +42
-4
lines changed
src/BootstrapBlazor/Components/Cascader Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Original file line number Diff line number Diff line change 44
55@if (IsShowLabel )
66{
7- <BootstrapLabel required =" @Required" for =" @Id" ShowLabelTooltip =" ShowLabelTooltip" Value =" @DisplayText" / >
7+ <BootstrapLabel required =" @Required" for =" @Id" ShowLabelTooltip =" ShowLabelTooltip" Value =" @DisplayText" ></ BootstrapLabel >
88}
99<div @attributes =" AdditionalAttributes" id =" @Id" class =" @ClassString" tabindex =" -1" >
10- <input type =" text" id =" @InputId" readonly disabled =" @Disabled" class =" @InputClassName" data-bs-toggle =" dropdown" placeholder =" @PlaceHolder" value =" @DisplayTextString" />
10+ <input type =" text" id =" @InputId" readonly disabled =" @Disabled" class =" @InputClassName" data-bs-toggle =" dropdown" placeholder =" @PlaceHolder" value =" @DisplayTextString" @onblur = " OnBlur " />
1111 <span class =" @AppendClassName" ><i class =" @Icon" ></i ></span >
1212 <div class =" dropdown-menu shadow" >
1313 <CascadingValue Value =" SelectedItems" >
Original file line number Diff line number Diff line change @@ -45,9 +45,7 @@ public partial class Cascader<TValue>
4545 /// </summary>
4646 [ Parameter ]
4747 [ NotNull ]
48- #if NET6_0_OR_GREATER
4948 [ EditorRequired ]
50- #endif
5149 public IEnumerable < CascaderItem > ? Items { get ; set ; }
5250
5351 /// <summary>
@@ -80,6 +78,12 @@ public partial class Cascader<TValue>
8078 [ Parameter ]
8179 public string ? SubMenuIcon { get ; set ; }
8280
81+ /// <summary>
82+ /// 获得/设置 失去焦点回调方法 默认 null
83+ /// </summary>
84+ [ Parameter ]
85+ public Func < TValue , Task > ? OnBlurAsync { get ; set ; }
86+
8387 [ Inject ]
8488 [ NotNull ]
8589 private IStringLocalizer < Cascader < TValue > > ? Localizer { get ; set ; }
@@ -115,6 +119,17 @@ protected override void OnParametersSet()
115119 }
116120 }
117121
122+ /// <summary>
123+ /// 失去焦点时回调方法
124+ /// </summary>
125+ private async Task OnBlur ( )
126+ {
127+ if ( OnBlurAsync != null )
128+ {
129+ await OnBlurAsync ( Value ) ;
130+ }
131+ }
132+
118133 /// <summary>
119134 /// 设置默认选中
120135 /// </summary>
Original file line number Diff line number Diff line change @@ -218,6 +218,29 @@ public async Task ShowFullLevels_Ok()
218218 Assert . Equal ( "Test1/Test11" , cut . Instance . MockDisplayText ) ;
219219 }
220220
221+ [ Fact ]
222+ public async Task OnBlurAsync_Ok ( )
223+ {
224+ var value = "" ;
225+ var items = new List < CascaderItem > ( )
226+ {
227+ new ( ) { Text = "test1" , Value = "1" }
228+ } ;
229+ var cut = Context . RenderComponent < Cascader < string > > ( pb =>
230+ {
231+ pb . Add ( a => a . Items , items ) ;
232+ pb . Add ( a => a . Value , "1" ) ;
233+ pb . Add ( a => a . OnBlurAsync , v =>
234+ {
235+ value = v ;
236+ return Task . CompletedTask ;
237+ } ) ;
238+ } ) ;
239+ var input = cut . Find ( "input" ) ;
240+ await cut . InvokeAsync ( ( ) => input . Blur ( ) ) ;
241+ Assert . Equal ( "1" , value ) ;
242+ }
243+
221244 class MockCascader : Cascader < string >
222245 {
223246 public string ? MockDisplayText => DisplayTextString ;
You can’t perform that action at this time.
0 commit comments