File tree Expand file tree Collapse file tree 4 files changed +17
-7
lines changed
src/BootstrapBlazor/Components/SweetAlert Expand file tree Collapse file tree 4 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ public class SwalOption : PopupOptionBase
102102 public Func < Task > ? OnConfirmAsync { get ; set ; }
103103
104104 /// <summary>
105- ///
105+ /// 构造函数
106106 /// </summary>
107107 public SwalOption ( )
108108 {
Original file line number Diff line number Diff line change @@ -88,10 +88,16 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
8888 {
8989 if ( DelayToken . IsCancellationRequested )
9090 {
91+ DelayToken . Dispose ( ) ;
9192 DelayToken = new ( ) ;
9293 }
9394 await Task . Delay ( Delay , DelayToken . Token ) ;
9495 await ModalContainer . Close ( ) ;
96+
97+ if ( OnCloseCallbackAsync != null )
98+ {
99+ await OnCloseCallbackAsync ( ) ;
100+ }
95101 }
96102 catch ( TaskCanceledException ) { }
97103 }
@@ -100,6 +106,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
100106
101107 private bool AutoHideCheck ( ) => IsAutoHide && Delay > 0 ;
102108
109+ private Func < Task > ? OnCloseCallbackAsync = null ;
110+
103111 private async Task Show ( SwalOption option )
104112 {
105113 if ( ! IsShowDialog )
@@ -121,6 +129,8 @@ private async Task Show(SwalOption option)
121129
122130 DialogParameter = parameters ;
123131
132+ OnCloseCallbackAsync = AutoHideCheck ( ) ? option . OnCloseAsync : null ;
133+
124134 // 渲染 UI 准备弹窗 Dialog
125135 await InvokeAsync ( StateHasChanged ) ;
126136 }
Original file line number Diff line number Diff line change @@ -16,9 +16,5 @@ internal class SweetContext
1616 /// 获得/设置 弹窗任务上下文
1717 /// </summary>
1818 [ NotNull ]
19- #if NET7_0_OR_GREATER
20- public required TaskCompletionSource < bool > ? ConfirmTask { get ; init ; }
21- #else
22- public TaskCompletionSource < bool > ? ConfirmTask { get ; set ; }
23- #endif
19+ public TaskCompletionSource < bool > ? ConfirmTask { get ; init ; }
2420}
Original file line number Diff line number Diff line change @@ -271,7 +271,11 @@ public void Show_Ok()
271271 Content = "I am auto hide" ,
272272 IsAutoHide = true ,
273273 ForceDelay = true ,
274- Delay = 500
274+ Delay = 500 ,
275+ OnCloseAsync = ( ) =>
276+ {
277+ return Task . CompletedTask ;
278+ }
275279 } ) ) ;
276280 Thread . Sleep ( 150 ) ;
277281 // 弹窗显示
You can’t perform that action at this time.
0 commit comments