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

Function useAutoFocus

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

Source from the content-addressed store, hash-verified

562}
563
564function useAutoFocus(scopeRef: RefObject<Element[] | null>, autoFocus?: boolean) {
565 const autoFocusRef = React.useRef(autoFocus);
566 useEffect(() => {
567 if (autoFocusRef.current) {
568 activeScope = scopeRef;
569 const ownerDocument = getOwnerDocument(scopeRef.current ? scopeRef.current[0] : undefined);
570 if (
571 !isElementInScope(getActiveElement(ownerDocument), activeScope.current) &&
572 scopeRef.current
573 ) {
574 focusFirstInScope(scopeRef.current);
575 }
576 }
577 autoFocusRef.current = false;
578 }, [scopeRef]);
579}
580
581function useActiveScopeTracker(
582 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