mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-11-29 18:49:08 +08:00
fix(Checkbox): not trigger OnStateChanged callback when set TValue to bool (#4667)
* refactor: 修复布尔值时不触发 OnStateChanged 回调问题 * test: 增加单元测试
This commit is contained in:
parent
ccd3bdb0ec
commit
dc1a76c835
@ -215,21 +215,23 @@ public partial class Checkbox<TValue> : ValidateBase<TValue>
|
||||
if (IsBoolean)
|
||||
{
|
||||
CurrentValue = (TValue)(object)(state == CheckboxState.Checked);
|
||||
}
|
||||
|
||||
if (State != state)
|
||||
{
|
||||
State = state;
|
||||
if (StateChanged.HasDelegate)
|
||||
if (ValueChanged.HasDelegate)
|
||||
{
|
||||
await StateChanged.InvokeAsync(State);
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (OnStateChanged != null)
|
||||
{
|
||||
await OnStateChanged(State, Value);
|
||||
}
|
||||
State = state;
|
||||
if (StateChanged.HasDelegate)
|
||||
{
|
||||
await StateChanged.InvokeAsync(State);
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (OnStateChanged != null)
|
||||
{
|
||||
await OnStateChanged(State, Value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -94,6 +94,27 @@ public class CheckboxListTest : BootstrapBlazorTestBase
|
||||
Assert.Equal(CheckboxState.Checked, cut.Instance.State);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Bool_TriggerStateChanged_Ok()
|
||||
{
|
||||
bool value = false;
|
||||
// 测试 bool 值改变值时触发 StateChanged 回调方法
|
||||
var cut = Context.RenderComponent<Checkbox<bool>>(pb =>
|
||||
{
|
||||
pb.Add(a => a.Value, false);
|
||||
pb.Add(a => a.OnStateChanged, (state, v) =>
|
||||
{
|
||||
value = v;
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
});
|
||||
|
||||
// JavaScript 调用 OnTriggerClickAsync 方法
|
||||
await cut.InvokeAsync(() => cut.Instance.OnTriggerClickAsync());
|
||||
Assert.Equal(CheckboxState.Checked, cut.Instance.State);
|
||||
Assert.True(value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Checkbox_Dispose()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user