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

Function useAutoFocus

packages/react-aria/src/focus/FocusScope.tsx:580–595  ·  view source on GitHub ↗
(scopeRef: RefObject<Element[] | null>, autoFocus?: boolean)

Source from the content-addressed store, hash-verified

578}
579
580function useAutoFocus(scopeRef: RefObject<Element[] | null>, autoFocus?: boolean) {
581 const autoFocusRef = React.useRef(autoFocus);
582 useEffect(() => {
583 if (autoFocusRef.current) {
584 activeScope = scopeRef;
585 const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);
586 if (
587 !isElementInScope(getActiveElement(ownerDocument), activeScope.current) &&
588 scopeRef.current
589 ) {
590 focusFirstInScope(scopeRef.current);
591 }
592 }
593 autoFocusRef.current = false;
594 }, [scopeRef]);
595}
596
597function useActiveScopeTracker(
598 scopeRef: RefObject<Element[] | null>,

Callers 1

FocusScopeFunction · 0.85

Calls 4

getOwnerDocumentFunction · 0.90
getActiveElementFunction · 0.90
isElementInScopeFunction · 0.85
focusFirstInScopeFunction · 0.85

Tested by

no test coverage detected