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

Function focusNext

packages/react-aria/src/focus/FocusScope.tsx:223–240  ·  view source on GitHub ↗
(opts: FocusManagerOptions = {})

Source from the content-addressed store, hash-verified

221function createFocusManagerForScope(scopeRef: React.RefObject<Element[] | null>): FocusManager {
222 return {
223 focusNext(opts: FocusManagerOptions = {}) {
224 let scope = scopeRef.current!;
225 let {from, tabbable, wrap, accept} = opts;
226 let node = from || getActiveElement(getOwnerDocument(scope[0] ?? undefined))!;
227 let sentinel = scope[0].previousElementSibling!;
228 let scopeRoot = getScopeRoot(scope);
229 let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);
230 walker.currentNode = isElementInScope(node, scope) ? node : sentinel;
231 let nextNode = walker.nextNode() as FocusableElement;
232 if (!nextNode && wrap) {
233 walker.currentNode = sentinel;
234 nextNode = walker.nextNode() as FocusableElement;
235 }
236 if (nextNode) {
237 focusElement(nextNode, true);
238 }
239 return nextNode;
240 },
241 focusPrevious(opts: FocusManagerOptions = {}) {
242 let scope = scopeRef.current!;
243 let {from, tabbable, wrap, accept} = opts;

Callers

nothing calls this directly

Calls 8

getActiveElementFunction · 0.90
getOwnerDocumentFunction · 0.90
nodeContainsFunction · 0.90
getScopeRootFunction · 0.85
getFocusableTreeWalkerFunction · 0.85
isElementInScopeFunction · 0.85
focusElementFunction · 0.85
nextNodeMethod · 0.80

Tested by

no test coverage detected