fix(centralui): DialogHost cleanup only on open->closed transition + drop trailing class space (T33a review)

This commit is contained in:
Joseph Doherty
2026-06-18 19:42:10 -04:00
parent 9ee21205d6
commit acbb52b459
@@ -17,7 +17,7 @@
role="dialog"
aria-modal="true"
@onkeydown="OnKeyDown">
<div class="modal-dialog modal-dialog-centered @state.Size" role="document">
<div class="modal-dialog modal-dialog-centered@(state.Size is null ? "" : $" {state.Size}")" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@state.Title</h5>
@@ -125,14 +125,20 @@
}
else
{
_focusedForState = null;
try { await JS.InvokeVoidAsync("document.body.classList.remove", "modal-open"); }
catch { /* prerender: no JS — ignore */ }
// Only clean up on the actual open→closed transition. Skipping when
// _focusedForState is already null avoids spurious JS interop on
// the initial render and every steady-state no-dialog render.
if (_focusedForState is not null)
{
_focusedForState = null;
try { await JS.InvokeVoidAsync("document.body.classList.remove", "modal-open"); }
catch { /* prerender: no JS — ignore */ }
// Return focus to whatever element triggered the dialog so keyboard
// users are not dumped at the top of the document on close.
try { await JS.InvokeVoidAsync("sbDialog.restoreActiveElement"); }
catch { /* prerender: no JS — ignore */ }
// Return focus to whatever element triggered the dialog so keyboard
// users are not dumped at the top of the document on close.
try { await JS.InvokeVoidAsync("sbDialog.restoreActiveElement"); }
catch { /* prerender: no JS — ignore */ }
}
}
}