Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ModalDialog): not shown after close previous window when set IsDraggable and IsCenter to true #4663

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 0 additions & 10 deletions src/BootstrapBlazor/Components/Modal/Modal.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
18 changes: 17 additions & 1 deletion src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -291,6 +291,8 @@ public partial class ModalDialog : IHandlerException

private DialogResult _result = DialogResult.Close;

private bool _firstRender = true;

/// <summary>
/// OnInitialized 方法
/// </summary>
Expand Down Expand Up @@ -329,6 +331,20 @@ protected override void OnParametersSet()
MaximizeIconString = MaximizeWindowIcon;
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="firstRender"></param>
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);

if (firstRender)
{
_firstRender = false;
}
}

/// <summary>
/// 设置 Header 文字方法
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/BootstrapBlazor/Components/Modal/ModalDialog.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading