MCPcopy Index your code
hub / github.com/primer/react / useFocusZone

Function useFocusZone

packages/react/src/hooks/useFocusZone.ts:28–67  ·  view source on GitHub ↗
(
  settings: FocusZoneHookSettings = {},
  dependencies: React.DependencyList = [],
)

Source from the content-addressed store, hash-verified

26}
27
28export function useFocusZone(
29 settings: FocusZoneHookSettings = {},
30 dependencies: React.DependencyList = [],
31): {containerRef: React.RefObject<HTMLElement>; activeDescendantControlRef: React.RefObject<HTMLElement>} {
32 const containerRef = useProvidedRefOrCreate(settings.containerRef)
33 const useActiveDescendant = !!settings.activeDescendantFocus
34 const passedActiveDescendantRef =
35 typeof settings.activeDescendantFocus === 'boolean' || !settings.activeDescendantFocus
36 ? undefined
37 : settings.activeDescendantFocus
38 const activeDescendantControlRef = useProvidedRefOrCreate(passedActiveDescendantRef)
39 const disabled = settings.disabled
40 const abortController = React.useRef<AbortController>()
41
42 useEffect(
43 () => {
44 if (
45 containerRef.current instanceof HTMLElement &&
46 (!useActiveDescendant || activeDescendantControlRef.current instanceof HTMLElement)
47 ) {
48 if (!disabled) {
49 const vanillaSettings: FocusZoneSettings = {
50 ...settings,
51 activeDescendantControl: activeDescendantControlRef.current ?? undefined,
52 }
53 abortController.current = focusZone(containerRef.current, vanillaSettings)
54 return () => {
55 abortController.current?.abort()
56 }
57 } else {
58 abortController.current?.abort()
59 }
60 }
61 },
62 // eslint-disable-next-line react-hooks/exhaustive-deps
63 [disabled, ...dependencies],
64 )
65
66 return {containerRef, activeDescendantControlRef}
67}

Callers 15

ConfirmationFooterFunction · 0.90
CoreToolbarFunction · 0.90
ActionBarFunction · 0.90
AutocompleteMenuFunction · 0.90
DefaultFooterFunction · 0.90
TabNavFunction · 0.90
List.tsxFile · 0.90
FilteredActionListFunction · 0.90
useRovingTabIndexFunction · 0.90
AnchoredOverlayFunction · 0.90
BasicFocusZoneFunction · 0.90

Calls 1

useProvidedRefOrCreateFunction · 0.90

Tested by

no test coverage detected