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

Function focusNext

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

Source from the content-addressed store, hash-verified

237function createFocusManagerForScope(scopeRef: React.RefObject<Element[] | null>): FocusManager {
238 return {
239 focusNext(opts: FocusManagerOptions = {}) {
240 let scope = scopeRef.current!;
241 let {from, tabbable, wrap, accept} = opts;
242 let node = from || getActiveElement(getOwnerDocument(scope[0] ?? undefined))!;
243 let sentinel = scope[0].previousElementSibling!;
244 let scopeRoot = getScopeRoot(scope);
245 let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);
246 walker.currentNode = isElementInScope(node, scope) ? node : sentinel;
247 let nextNode = walker.nextNode() as FocusableElement;
248 if (!nextNode && wrap) {
249 walker.currentNode = sentinel;
250 nextNode = walker.nextNode() as FocusableElement;
251 }
252 if (nextNode) {
253 focusElement(nextNode, true);
254 }
255 return nextNode;
256 },
257 focusPrevious(opts: FocusManagerOptions = {}) {
258 let scope = scopeRef.current!;
259 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