MCPcopy
hub / github.com/adobe/react-spectrum / focusPrevious

Function focusPrevious

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

Source from the content-addressed store, hash-verified

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