Skip to content

Commit

Permalink
Add generic type parameter for useFocusZone container ref
Browse files Browse the repository at this point in the history
  • Loading branch information
kyooosukedn committed Dec 19, 2024
1 parent 5cba52a commit 86052ea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/react/src/hooks/useFocusZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {useProvidedRefOrCreate} from './useProvidedRefOrCreate'
export {FocusKeys} from '@primer/behaviors'
export type {Direction} from '@primer/behaviors'

export interface FocusZoneHookSettings extends Omit<FocusZoneSettings, 'activeDescendantControl'> {
export interface FocusZoneHookSettings<T extends HTMLElement>
extends Omit<FocusZoneSettings, 'activeDescendantControl'> {
/**
* Optional ref for the container that holds all elements participating in arrow key focus.
* If one is not passed, we will create one for you and return it from the hook.
*/
containerRef?: React.RefObject<HTMLElement>
containerRef?: React.RefObject<T>

/**
* If using the "active descendant" focus pattern, pass `true` or a ref to the controlling
Expand All @@ -25,11 +26,11 @@ export interface FocusZoneHookSettings extends Omit<FocusZoneSettings, 'activeDe
disabled?: boolean
}

export function useFocusZone(
settings: FocusZoneHookSettings = {},
export function useFocusZone<T extends HTMLElement>(
settings: FocusZoneHookSettings<T> = {},
dependencies: React.DependencyList = [],
): {containerRef: React.RefObject<HTMLElement>; activeDescendantControlRef: React.RefObject<HTMLElement>} {
const containerRef = useProvidedRefOrCreate(settings.containerRef)
): {containerRef: React.RefObject<T>; activeDescendantControlRef: React.RefObject<HTMLElement>} {
const containerRef = useProvidedRefOrCreate<T>(settings.containerRef)
const useActiveDescendant = !!settings.activeDescendantFocus
const passedActiveDescendantRef =
typeof settings.activeDescendantFocus === 'boolean' || !settings.activeDescendantFocus
Expand Down

0 comments on commit 86052ea

Please sign in to comment.