MCPcopy Index your code
hub / github.com/adobe/react-spectrum / isElementInChildScope

Function isElementInChildScope

packages/react-aria/src/focus/FocusScope.tsx:491–506  ·  view source on GitHub ↗
(element: Element, scope: ScopeRef = null)

Source from the content-addressed store, hash-verified

489}
490
491function isElementInChildScope(element: Element, scope: ScopeRef = null) {
492 // If the element is within a top layer element (e.g. toasts), always allow moving focus there.
493 if (element instanceof Element && element.closest('[data-react-aria-top-layer]')) {
494 return true;
495 }
496
497 // node.contains in isElementInScope covers child scopes that are also DOM children,
498 // but does not cover child scopes in portals.
499 for (let {scopeRef: s} of focusScopeTree.traverse(focusScopeTree.getTreeNode(scope))) {
500 if (s && isElementInScope(element, s.current)) {
501 return true;
502 }
503 }
504
505 return false;
506}
507
508/** @private */
509export function isElementInChildOfActiveScope(element: Element): boolean {

Callers 6

onFocusFunction · 0.85
onBlurFunction · 0.85
isElementInAnyScopeFunction · 0.85
onKeyDownFunction · 0.85
useRestoreFocusFunction · 0.85

Calls 3

isElementInScopeFunction · 0.85
traverseMethod · 0.80
getTreeNodeMethod · 0.80

Tested by

no test coverage detected