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

Function isElementInChildScope

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

Source from the content-addressed store, hash-verified

506}
507
508function isElementInChildScope(element: Element, scope: ScopeRef = null) {
509 // If the element is within a top layer element (e.g. toasts), always allow moving focus there.
510 if (element instanceof Element && element.closest('[data-react-aria-top-layer]')) {
511 return true;
512 }
513
514 // node.contains in isElementInScope covers child scopes that are also DOM children,
515 // but does not cover child scopes in portals.
516 for (let {scopeRef: s} of focusScopeTree.traverse(focusScopeTree.getTreeNode(scope))) {
517 if (s && isElementInScope(element, s.current)) {
518 return true;
519 }
520 }
521
522 return false;
523}
524
525/** @private */
526export 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