Skip to content

Commit a408e98

Browse files
authored
fix(Dialog): not trigger OnCloseAsync multiple dialog (#6339)
* fix: 修复未触发 OnCloseAsync 回调问题 * chore: bump version 9.8.0
1 parent f8d6acc commit a408e98

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.8.0-beta07</Version>
4+
<Version>9.8.0</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Dialog/Dialog.razor.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public partial class Dialog : IDisposable
2323
[NotNull]
2424
private Func<Task>? _onCloseAsync = null;
2525

26-
private readonly Dictionary<Dictionary<string, object>, (bool IsKeyboard, bool IsBackdrop)> DialogParameters = [];
26+
private readonly Dictionary<Dictionary<string, object>, (bool IsKeyboard, bool IsBackdrop, Func<Task>? OnCloseCallback)> DialogParameters = [];
2727
private Dictionary<string, object>? _currentParameter;
2828
private bool _isKeyboard = false;
2929
private bool _isBackdrop = false;
@@ -72,16 +72,14 @@ private async Task Show(DialogOption option)
7272

7373
_onCloseAsync = async () =>
7474
{
75-
// Callback OnCloseAsync
76-
if (option.OnCloseAsync != null)
77-
{
78-
await option.OnCloseAsync();
79-
}
80-
8175
// Remove current DialogParameter
8276
if (_currentParameter != null)
8377
{
84-
DialogParameters.Remove(_currentParameter);
78+
DialogParameters.Remove(_currentParameter, out var v);
79+
if (v.OnCloseCallback != null)
80+
{
81+
await v.OnCloseCallback();
82+
}
8583

8684
// Support for multiple dialogs
8785
var p = DialogParameters.LastOrDefault();
@@ -162,7 +160,7 @@ private async Task Show(DialogOption option)
162160
_currentParameter = parameters;
163161

164162
// Add ModalDialog to the container
165-
DialogParameters.Add(parameters, (_isKeyboard, _isBackdrop));
163+
DialogParameters.Add(parameters, (_isKeyboard, _isBackdrop, option.OnCloseAsync));
166164
await InvokeAsync(StateHasChanged);
167165
}
168166

0 commit comments

Comments
 (0)