fix(ui): drop modal blur when the overlay starts closing

The workspace blur was keyed on the overlay node existing, so it held through
Radix's exit fade and snapped off after the dim was already gone.
This commit is contained in:
Brennan Benson
2026-11-09 15:29:09 -08:00
parent 5c5cd9344a
commit 3a9b79b04f
2 changed files with 13 additions and 5 deletions
+3 -1
View File
@@ -1059,7 +1059,9 @@ body[data-modal-overlay-open]
[data-slot='command-dialog-content'],
[data-slot='sheet-content'],
[data-onboarding-overlay]
):has(~ [data-slot='dialog-overlay'], ~ [data-slot='sheet-overlay']) {
):has(
~ :is([data-slot='dialog-overlay'], [data-slot='sheet-overlay']):not([data-state='closed'])
) {
filter: blur(2px);
}
@@ -1,5 +1,7 @@
export const MODAL_OVERLAY_CHILD_SELECTOR =
":scope > [data-slot='dialog-overlay'], :scope > [data-slot='sheet-overlay']"
const MOUNTED_MODAL_OVERLAY_CHILD_SELECTOR =
":scope > :is([data-slot='dialog-overlay'], [data-slot='sheet-overlay'])"
// Radix keeps a closing overlay mounted through its fade; it must not hold the blur past the dim.
export const MODAL_OVERLAY_CHILD_SELECTOR = `${MOUNTED_MODAL_OVERLAY_CHILD_SELECTOR}:not([data-state='closed'])`
const ONBOARDING_OVERLAY_CHILD_SELECTOR = ':scope > [data-onboarding-overlay]'
let disposeInstalledObserver: (() => void) | null = null
@@ -11,7 +13,11 @@ export function installBodyOverlayAttributes(): () => void {
return disposeInstalledObserver
}
const body = document.body
const observer = new MutationObserver(() => sync())
const sync = (): void => {
for (const overlay of body.querySelectorAll(MOUNTED_MODAL_OVERLAY_CHILD_SELECTOR)) {
observer.observe(overlay, { attributes: true, attributeFilter: ['data-state'] })
}
// toggleAttribute is a no-op when the state is unchanged, so unrelated portals cost no restyle.
body.toggleAttribute(
'data-modal-overlay-open',
@@ -23,8 +29,8 @@ export function installBodyOverlayAttributes(): () => void {
)
}
sync()
// Overlays portal as direct body children; childList-only keeps the callback off app mutations.
const observer = new MutationObserver(sync)
// Overlays portal as direct body children; watching only body children and overlay state keeps
// the callback off app mutations.
observer.observe(body, { childList: true })
disposeInstalledObserver = () => {
observer.disconnect()