diff --git a/src/renderer/src/assets/main.css b/src/renderer/src/assets/main.css index 59c6fd15fb5..47b8935c749 100644 --- a/src/renderer/src/assets/main.css +++ b/src/renderer/src/assets/main.css @@ -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); } diff --git a/src/renderer/src/lib/body-overlay-attributes.ts b/src/renderer/src/lib/body-overlay-attributes.ts index 39c85bc90b8..a34733b8be4 100644 --- a/src/renderer/src/lib/body-overlay-attributes.ts +++ b/src/renderer/src/lib/body-overlay-attributes.ts @@ -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()