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

Function useAutoFocus

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

Source from the content-addressed store, hash-verified

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