Skip to content

Commit b0e1125

Browse files
ArgoZhangdensen2014
andcommitted
fix: close all window when Modal inside of Dialog #337
Co-authored-by: alex chow <zhouchuanglin@gmail.com>
1 parent 2c4fc54 commit b0e1125

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ protected override void OnInitialized()
4848

4949
// 注册 Dialog 弹窗事件
5050
DialogService.Register(this, Show);
51+
52+
// 增加参数
53+
AdditionalAttributes ??= new Dictionary<string, object>();
54+
AdditionalAttributes["data-bb-dialog"] = "true";
5155
}
5256

5357
/// <summary>

src/BootstrapBlazor/wwwroot/modules/modal.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@ export class Modal extends BlazorComponent {
77
this._invoker = this._config.arguments[0]
88
this._invokerShownMethod = this._config.arguments[1]
99
this._invokerCloseMethod = this._config.arguments[2]
10+
this._isDialog = this._config.dialog === true
1011
this._setEventListeners()
1112
}
1213

1314
_setEventListeners() {
1415
EventHandler.on(this._element, 'shown.bs.modal', () => {
1516
this._invoker.invokeMethodAsync(this._invokerShownMethod)
1617
})
17-
EventHandler.on(this._element, 'hide.bs.modal', () => {
18+
EventHandler.on(this._element, 'hide.bs.modal', e => {
19+
e.stopPropagation();
1820
if (this._draggable) {
1921
this._dialog.style.width = ''
2022
this._dialog.style.margin = ''
2123

2224
EventHandler.off(this._dialog, 'mousedown')
2325
EventHandler.off(this._dialog, 'touchstart')
2426
}
25-
this._invoker.invokeMethodAsync(this._invokerCloseMethod)
27+
if (this._isDialog) {
28+
this._invoker.invokeMethodAsync(this._invokerCloseMethod)
29+
}
2630
})
2731

2832
this._pop = () => {

0 commit comments

Comments
 (0)