File tree Expand file tree Collapse file tree 2 files changed +33
-10
lines changed
src/BootstrapBlazor/Components/Checkbox Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -215,21 +215,23 @@ private async Task<bool> InternalStateChanged(CheckboxState state)
215215 if ( IsBoolean )
216216 {
217217 CurrentValue = ( TValue ) ( object ) ( state == CheckboxState . Checked ) ;
218- }
219218
220- if ( State != state )
221- {
222- State = state ;
223- if ( StateChanged . HasDelegate )
219+ if ( ValueChanged . HasDelegate )
224220 {
225- await StateChanged . InvokeAsync ( State ) ;
226221 ret = false ;
227222 }
223+ }
228224
229- if ( OnStateChanged != null )
230- {
231- await OnStateChanged ( State , Value ) ;
232- }
225+ State = state ;
226+ if ( StateChanged . HasDelegate )
227+ {
228+ await StateChanged . InvokeAsync ( State ) ;
229+ ret = false ;
230+ }
231+
232+ if ( OnStateChanged != null )
233+ {
234+ await OnStateChanged ( State , Value ) ;
233235 }
234236 return ret ;
235237 }
Original file line number Diff line number Diff line change @@ -94,6 +94,27 @@ public async Task Checkbox_OnTriggerClickAsync()
9494 Assert . Equal ( CheckboxState . Checked , cut . Instance . State ) ;
9595 }
9696
97+ [ Fact ]
98+ public async Task Bool_TriggerStateChanged_Ok ( )
99+ {
100+ bool value = false ;
101+ // 测试 bool 值改变值时触发 StateChanged 回调方法
102+ var cut = Context . RenderComponent < Checkbox < bool > > ( pb =>
103+ {
104+ pb . Add ( a => a . Value , false ) ;
105+ pb . Add ( a => a . OnStateChanged , ( state , v ) =>
106+ {
107+ value = v ;
108+ return Task . CompletedTask ;
109+ } ) ;
110+ } ) ;
111+
112+ // JavaScript 调用 OnTriggerClickAsync 方法
113+ await cut . InvokeAsync ( ( ) => cut . Instance . OnTriggerClickAsync ( ) ) ;
114+ Assert . Equal ( CheckboxState . Checked , cut . Instance . State ) ;
115+ Assert . True ( value ) ;
116+ }
117+
97118 [ Fact ]
98119 public void Checkbox_Dispose ( )
99120 {
You can’t perform that action at this time.
0 commit comments