Skip to content

Commit 4459cbb

Browse files
committed
refactor: 支持 OnCloseAsync 回调方法
1 parent be7873d commit 4459cbb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/BootstrapBlazor/Components/SweetAlert/SweetAlert.razor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
9393
}
9494
await Task.Delay(Delay, DelayToken.Token);
9595
await ModalContainer.Close();
96+
97+
if (OnCloseCallbackAsync != null)
98+
{
99+
await OnCloseCallbackAsync();
100+
}
96101
}
97102
catch (TaskCanceledException) { }
98103
}
@@ -101,6 +106,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
101106

102107
private bool AutoHideCheck() => IsAutoHide && Delay > 0;
103108

109+
private Func<Task>? OnCloseCallbackAsync = null;
110+
104111
private async Task Show(SwalOption option)
105112
{
106113
if (!IsShowDialog)
@@ -122,6 +129,8 @@ private async Task Show(SwalOption option)
122129

123130
DialogParameter = parameters;
124131

132+
OnCloseCallbackAsync = AutoHideCheck() ? option.OnCloseAsync : null;
133+
125134
// 渲染 UI 准备弹窗 Dialog
126135
await InvokeAsync(StateHasChanged);
127136
}

0 commit comments

Comments
 (0)