Skip to content

Commit 51d04b2

Browse files
authored
Restore original getFocusableTreeWalker signature (#4502)
1 parent b677593 commit 51d04b2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/@react-aria/focus/src/FocusScope.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ function useFocusContainment(scopeRef: RefObject<Element[]>, contain: boolean) {
320320
}
321321
let focusNextInChildScope = (childScopeRef: ScopeRef): FocusableElement | null => {
322322
if (childScopeRef !== scopeRef) {
323-
let walker = getFocusableTreeWalker(getScopeRoot(childScopeRef.current), {tabbable: true}, scope, scopeRef);
323+
let walker = getFocusableTreeWalker(getScopeRoot(childScopeRef.current), {tabbable: true}, scope);
324324
walker.currentNode = focusedElement;
325325
let nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement;
326326
if (nextElement) {
@@ -568,7 +568,7 @@ function useRestoreFocus(scopeRef: RefObject<Element[]>, restoreFocus: boolean,
568568
let onFocus = () => {
569569
// If focusing an element in a child scope of the currently active scope, the child becomes active.
570570
// Moving out of the active scope to an ancestor is not allowed.
571-
if ((!activeScope || isAncestorScope(activeScope, scopeRef)) &&
571+
if ((!activeScope || isAncestorScope(activeScope, scopeRef)) &&
572572
isElementInScope(document.activeElement, scopeRef.current)
573573
) {
574574
activeScope = scopeRef;
@@ -709,7 +709,7 @@ function useRestoreFocus(scopeRef: RefObject<Element[]>, restoreFocus: boolean,
709709
* Create a [TreeWalker]{@link https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker}
710710
* that matches all focusable/tabbable elements.
711711
*/
712-
export function getFocusableTreeWalker(root: Element, opts?: FocusManagerOptions, scope?: Element[], scopeRef?: ScopeRef) {
712+
export function getFocusableTreeWalker(root: Element, opts?: FocusManagerOptions, scope?: Element[]) {
713713
let selector = opts?.tabbable ? TABBABLE_ELEMENT_SELECTOR : FOCUSABLE_ELEMENT_SELECTOR;
714714
let walker = document.createTreeWalker(
715715
root,
@@ -721,6 +721,16 @@ export function getFocusableTreeWalker(root: Element, opts?: FocusManagerOptions
721721
return NodeFilter.FILTER_REJECT;
722722
}
723723

724+
let scopeRef = null;
725+
if (scope) {
726+
for (let node of focusScopeTree.traverse()) {
727+
if (node.scopeRef.current === scope) {
728+
scopeRef = node.scopeRef;
729+
break;
730+
}
731+
}
732+
}
733+
724734
if ((node as Element).matches(selector)
725735
&& isElementVisible(node as Element)
726736
&& ((!scope || isElementInScope(node as Element, scope)) || (scopeRef && isElementInChildScope(node as Element, scopeRef)))

0 commit comments

Comments
 (0)