UNPKG

goobs-frontend

Version:

A comprehensive React-based libary for building modern web applications

49 lines 2.17 kB
import { RefObject } from 'react'; /** * Closes a popover when Escape is pressed while the document has * focus inside it. Safer than blanket window-level Escape because it * only fires when the popover is open AND focus is somewhere within * its anchor / panel. * * @param isOpen - whether the popover is currently open * @param onClose - called when Escape is detected * @param scopeRef - optional ref to constrain to. When provided, * Escape only closes if focus is inside this element. When omitted, * any document-wide Escape closes (matches the legacy Popover * component's behavior). */ export declare function useEscape(isOpen: boolean, onClose: () => void, scopeRef?: RefObject<HTMLElement | null>): void; export interface ArrowKeyNavOptions { /** Number of options in the listbox. */ count: number; /** Currently active option index, or -1 when nothing is highlighted. */ activeIndex: number; /** Setter for the active index. */ onActiveIndexChange: (next: number) => void; /** * Called when Enter or Space activates the current option. Receives * the active index. Components decide what "activate" means * (selecting a value, expanding a sub-menu, etc.). */ onActivate?: (index: number) => void; /** * Optional roving tabindex orientation. `'vertical'` (default) * binds Up/Down, `'horizontal'` binds Left/Right, `'both'` binds all. */ orientation?: 'vertical' | 'horizontal' | 'both'; } /** * Roving-tabindex keyboard navigation for listboxes / menus / option * lists. Returns an `onKeyDown` handler the consumer attaches to the * trigger button (so the popover doesn't have to be focused for * navigation to work — this is the WAI-ARIA combobox 1.2 pattern). * * Bindings: * - ArrowDown / ArrowRight → next option, wraps to first * - ArrowUp / ArrowLeft → prev option, wraps to last * - Home → first option * - End → last option * - Enter / Space → onActivate(activeIndex) */ export declare function useArrowKeyNav(opts: ArrowKeyNavOptions): (event: React.KeyboardEvent<HTMLElement>) => void; //# sourceMappingURL=keyboard.d.ts.map