Skip to content

An open-source, self-hosted system for apps built with web technologies.

Focus a closing dialog returns never brings a Window forward

zohayrslilehbbb8149b73e0
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index 2f06b3f..1afb15b 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -189,6 +189,20 @@ export default function ({ title, header = true, surface, layer, icon, children,
}
}, [layer, onPresentationMoveGesture])
+ // A closing dialog, menu, or popover returns focus to what held it before it opened. Into a Window
+ // no longer in front, that would bring it forward again, though no person chose it; the Desktop
+ // keeps focus instead. React Aria announces each return with this cancelable event.
+ useEffect(function () {
+ const element = frameElement.current
+ if (!element || active) return
+ const decline = (event: Event) => {
+ event.preventDefault()
+ element.closest<HTMLElement>("[data-desktop]")?.focus({ preventScroll: true })
+ }
+ element.addEventListener("react-aria-focus-scope-restore", decline)
+ return () => element.removeEventListener("react-aria-focus-scope-restore", decline)
+ }, [frameElement, active])
+
useEffect(function () {
if (!externalMoveActive) return
const cancel = () => finishExternalMove(null)