Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/SweetAlert/SwalOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class SwalOption : PopupOptionBase
public Func<Task>? OnConfirmAsync { get; set; }

/// <summary>
///
/// 构造函数
/// </summary>
public SwalOption()
{
Expand Down
10 changes: 10 additions & 0 deletions src/BootstrapBlazor/Components/SweetAlert/SweetAlert.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,16 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (DelayToken.IsCancellationRequested)
{
DelayToken.Dispose();
DelayToken = new();
}
await Task.Delay(Delay, DelayToken.Token);
await ModalContainer.Close();

if (OnCloseCallbackAsync != null)
{
await OnCloseCallbackAsync();
}
}
catch (TaskCanceledException) { }
}
Expand All @@ -100,6 +106,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

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

private Func<Task>? OnCloseCallbackAsync = null;

private async Task Show(SwalOption option)
{
if (!IsShowDialog)
Expand All @@ -121,6 +129,8 @@ private async Task Show(SwalOption option)

DialogParameter = parameters;

OnCloseCallbackAsync = AutoHideCheck() ? option.OnCloseAsync : null;

// 渲染 UI 准备弹窗 Dialog
await InvokeAsync(StateHasChanged);
}
Expand Down
6 changes: 1 addition & 5 deletions src/BootstrapBlazor/Components/SweetAlert/SweetContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@ internal class SweetContext
/// 获得/设置 弹窗任务上下文
/// </summary>
[NotNull]
#if NET7_0_OR_GREATER
public required TaskCompletionSource<bool>? ConfirmTask { get; init; }
#else
public TaskCompletionSource<bool>? ConfirmTask { get; set; }
#endif
public TaskCompletionSource<bool>? ConfirmTask { get; init; }
}
6 changes: 5 additions & 1 deletion test/UnitTest/Components/SwalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ public void Show_Ok()
Content = "I am auto hide",
IsAutoHide = true,
ForceDelay = true,
Delay = 500
Delay = 500,
OnCloseAsync = () =>
{
return Task.CompletedTask;
}
}));
Thread.Sleep(150);
// 弹窗显示
Expand Down
Loading