From 7f38a162515435977889edba94c0b0d36751970e Mon Sep 17 00:00:00 2001 From: Daniel Lu Date: Wed, 4 Dec 2024 17:25:17 -0800 Subject: [PATCH 1/4] Fix Android talkback focus cusor movement when inside contain FocusScopes (e.g. Dialogs) --- packages/@react-aria/focus/src/FocusScope.tsx | 5 ++--- packages/@react-spectrum/dialog/stories/Dialog.stories.tsx | 2 +- packages/@react-spectrum/menu/test/MenuTrigger.test.js | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/@react-aria/focus/src/FocusScope.tsx b/packages/@react-aria/focus/src/FocusScope.tsx index f48af3ff981..e0480fe1943 100644 --- a/packages/@react-aria/focus/src/FocusScope.tsx +++ b/packages/@react-aria/focus/src/FocusScope.tsx @@ -376,13 +376,12 @@ function useFocusContainment(scopeRef: RefObject, contain?: bo }; let onBlur = (e) => { - // Firefox doesn't shift focus back to the Dialog properly without this + // Use raf to delay long enough that subdialogs will fully unmount and not move focus away from parent menu's hovered item that triggered the close if (raf.current) { cancelAnimationFrame(raf.current); } raf.current = requestAnimationFrame(() => { - // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe - if (ownerDocument.activeElement && shouldContainFocus(scopeRef) && !isElementInChildScope(ownerDocument.activeElement, scopeRef)) { + if (e.relatedTarget && shouldContainFocus(scopeRef) && !isElementInChildScope(e.relatedTarget, scopeRef)) { activeScope = scopeRef; if (ownerDocument.body.contains(e.target)) { focusedNode.current = e.target; diff --git a/packages/@react-spectrum/dialog/stories/Dialog.stories.tsx b/packages/@react-spectrum/dialog/stories/Dialog.stories.tsx index 05fac03bfc5..c7e68815419 100644 --- a/packages/@react-spectrum/dialog/stories/Dialog.stories.tsx +++ b/packages/@react-spectrum/dialog/stories/Dialog.stories.tsx @@ -171,7 +171,7 @@ function renderIframe({width = 'auto', isDismissable = undefined, ...props}) {
The Header
-