MCPcopy Create free account
hub / github.com/adobe/react-spectrum / isElementInChildScope

Function isElementInChildScope

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

Source from the content-addressed store, hash-verified

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