MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useAutoFocus

Function useAutoFocus

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

Source from the content-addressed store, hash-verified

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