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

Function getFirstInScope

packages/react-aria/src/focus/FocusScope.tsx:541–557  ·  view source on GitHub ↗
(scope: Element[], tabbable = true)

Source from the content-addressed store, hash-verified

539}
540
541function getFirstInScope(scope: Element[], tabbable = true) {
542 let sentinel = scope[0].previousElementSibling!;
543 let scopeRoot = getScopeRoot(scope);
544 let walker = getFocusableTreeWalker(scopeRoot, {tabbable}, scope);
545 walker.currentNode = sentinel;
546 let nextNode = walker.nextNode();
547
548 // If the scope does not contain a tabbable element, use the first focusable element.
549 if (tabbable && !nextNode) {
550 scopeRoot = getScopeRoot(scope);
551 walker = getFocusableTreeWalker(scopeRoot, {tabbable: false}, scope);
552 walker.currentNode = sentinel;
553 nextNode = walker.nextNode();
554 }
555
556 return nextNode as FocusableElement;
557}
558
559function focusFirstInScope(scope: Element[], tabbable: boolean = true) {
560 focusElement(getFirstInScope(scope, tabbable));

Callers 2

focusFirstInScopeFunction · 0.85
useRestoreFocusFunction · 0.85

Calls 3

getScopeRootFunction · 0.85
getFocusableTreeWalkerFunction · 0.85
nextNodeMethod · 0.80

Tested by

no test coverage detected