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

Function focusPrevious

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

Source from the content-addressed store, hash-verified

239 return nextNode;
240 },
241 focusPrevious(opts: FocusManagerOptions = {}) {
242 let scope = scopeRef.current!;
243 let {from, tabbable, wrap, accept} = opts;
244 let node = from || getActiveElement(getOwnerDocument(scope[0] ?? undefined))!;
245 let sentinel = scope[scope.length - 1].nextElementSibling!;
246 let scopeRoot = getScopeRoot(scope);
247 let walker = getFocusableTreeWalker(scopeRoot, {tabbable, accept}, scope);
248 walker.currentNode = isElementInScope(node, scope) ? node : sentinel;
249 let previousNode = walker.previousNode() as FocusableElement;
250 if (!previousNode && wrap) {
251 walker.currentNode = sentinel;
252 previousNode = walker.previousNode() as FocusableElement;
253 }
254 if (previousNode) {
255 focusElement(previousNode, true);
256 }
257 return previousNode;
258 },
259 focusFirst(opts = {}) {
260 let scope = scopeRef.current!;
261 let {tabbable, accept} = opts;

Callers

nothing calls this directly

Calls 9

getActiveElementFunction · 0.90
getOwnerDocumentFunction · 0.90
nodeContainsFunction · 0.90
getScopeRootFunction · 0.85
getFocusableTreeWalkerFunction · 0.85
isElementInScopeFunction · 0.85
focusElementFunction · 0.85
previousNodeMethod · 0.80
lastFunction · 0.70

Tested by

no test coverage detected