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

Function getFirstInScope

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

Source from the content-addressed store, hash-verified

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