Skip to content

Commit 4c51a04

Browse files
committed
refactor: 重构 OnTriggerClickAsync
1 parent 86d286f commit 4c51a04

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,13 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
170170
/// </summary>
171171
/// <returns></returns>
172172
[JSInvokable]
173-
public async ValueTask<bool> OnTriggerClickAsync(string? state = null)
173+
public async ValueTask<bool> OnTriggerClickAsync(CheckboxState? state = null)
174174
{
175175
// 本组件由于支持 OnBeforeStateChanged 回调方法,所以设计上移除了 onclick 事件,改为通过 JS 调用 TriggerClick 方法
176-
// state 值 1 表示 Checked 状态,0 表示 UnChecked 状态
177-
178176
// state 有值时表示同步状态功能
179-
if (!string.IsNullOrEmpty(state))
177+
if (state.HasValue)
180178
{
181-
State = state == "1" ? CheckboxState.UnChecked : CheckboxState.Checked;
179+
State = state.Value;
182180
return true;
183181
}
184182

src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function init(id, invoke, method) {
2424
el.parentElement.classList.add('is-checked');
2525
}
2626
}
27-
var result = await invoke.invokeMethodAsync(method, state);
27+
var result = await invoke.invokeMethodAsync(method, state == "1" ? 0 : 1);
2828
if (result === false) {
2929
e.preventDefault();
3030
}

0 commit comments

Comments
 (0)