import type { ReactElement, ReactNode } from "react"; import { useMemo } from "react"; import type { ActiveDescendantContext } from "./activeDescendantContext"; import { ActiveDescendantContextProvider } from "./activeDescendantContext"; /** * @internal * @remarks \@since 5.0.0 */ export interface ActiveDescendantMovementProviderProps extends ActiveDescendantContext { children: ReactNode; } /** * This component should be used with the {@link KeyboardMovementProvider} * component to implement custom keyboard focusable behavior using * `aria-activedescendant`. * * @example * Base Example * ```tsx * function Descendant({ id, children, ...props }: HTMLAttributes): ReactElement { * const { ref, active } = useActiveDescendant({ id }); * return ( *
* {children} *
* ); * } * * function CustomFocus(): ReactElement { * const { providerProps, focusIndex, ...containerProps } = * useActiveDescendantFocus() * * return ( * *
* * Some Option * *
*
* ); * } * * function Example() { * return ( * * * * ); * } * ``` * * @see https://www.w3.org/TR/wai-aria-practices/#kbd_focus_activedescendant * @internal * @remarks \@since 5.0.0 */ export function ActiveDescendantMovementProvider({ children, activeId, setActiveId, }: ActiveDescendantMovementProviderProps): ReactElement { return ( ({ activeId, setActiveId, }), [activeId, setActiveId] )} > {children} ); }