diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 22826c6e14a..613c2b28200 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.0.0-beta01 + 9.0.0-beta02 diff --git a/src/BootstrapBlazor/Components/Modal/Modal.razor.js b/src/BootstrapBlazor/Components/Modal/Modal.razor.js index cfca54155de..9a2da09f40c 100644 --- a/src/BootstrapBlazor/Components/Modal/Modal.razor.js +++ b/src/BootstrapBlazor/Components/Modal/Modal.razor.js @@ -17,16 +17,6 @@ export function init(id, invoke, shownCallback, closeCallback) { Data.set(id, modal) EventHandler.on(el, 'shown.bs.modal', () => { - const dialog = el.querySelector('.modal-dialog'); - if (dialog.classList.contains('is-draggable-center')) { - const width = dialog.offsetWidth / 2; - const height = dialog.offsetHeight / 2; - - dialog.style.setProperty("margin-left", `calc(50vw - ${width}px)`); - dialog.style.setProperty("margin-top", `calc(50vh - ${height}px)`); - dialog.classList.remove('is-draggable-center'); - } - invoke.invokeMethodAsync(shownCallback) }) EventHandler.on(el, 'hidden.bs.modal', e => { diff --git a/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs b/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs index 776759bbb2e..c2fa72789fc 100644 --- a/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs +++ b/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs @@ -24,7 +24,7 @@ public partial class ModalDialog : IHandlerException .AddClass("modal-dialog-scrollable", IsScrolling) .AddClass("modal-fullscreen", MaximizeStatus) .AddClass("is-draggable", IsDraggable) - .AddClass("is-draggable-center", IsCentered && IsDraggable) + .AddClass("is-draggable-center", IsCentered && IsDraggable && _firstRender) .AddClass("d-none", !IsShown) .AddClass(Class, !string.IsNullOrEmpty(Class)) .Build(); @@ -291,6 +291,8 @@ public partial class ModalDialog : IHandlerException private DialogResult _result = DialogResult.Close; + private bool _firstRender = true; + /// /// OnInitialized 方法 /// @@ -329,6 +331,20 @@ protected override void OnParametersSet() MaximizeIconString = MaximizeWindowIcon; } + /// + /// + /// + /// + protected override void OnAfterRender(bool firstRender) + { + base.OnAfterRender(firstRender); + + if (firstRender) + { + _firstRender = false; + } + } + /// /// 设置 Header 文字方法 /// diff --git a/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.js b/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.js index 0789c889894..6a779c85e6b 100644 --- a/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.js +++ b/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.js @@ -119,6 +119,15 @@ export function init(id) { } ) } + + if (el.classList.contains('is-draggable-center')) { + const width = el.offsetWidth / 2; + const height = el.offsetHeight / 2; + + el.style.setProperty("margin-left", `calc(50vw - ${width}px)`); + el.style.setProperty("margin-top", `calc(50vh - ${height}px)`); + el.classList.remove('is-draggable-center'); + } } export function dispose(id) {