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" role="dialog"
aria-modal="true" aria-modal="true"
@onkeydown="OnKeyDown"> @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-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title">@state.Title</h5> <h5 class="modal-title">@state.Title</h5>
@@ -124,6 +124,11 @@
} }
} }
else else
{
// 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; _focusedForState = null;
try { await JS.InvokeVoidAsync("document.body.classList.remove", "modal-open"); } try { await JS.InvokeVoidAsync("document.body.classList.remove", "modal-open"); }
@@ -135,6 +140,7 @@
catch { /* prerender: no JS — ignore */ } catch { /* prerender: no JS — ignore */ }
} }
} }
}
private async Task OnKeyDown(KeyboardEventArgs e) private async Task OnKeyDown(KeyboardEventArgs e)
{ {