UNPKG

@base-ui/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

140 lines 5.17 kB
import * as React from 'react'; import { FloatingTreeStore } from "../components/FloatingTreeStore.js"; import type { ElementProps, FloatingContext, FloatingRootContext } from "../types.js"; export declare const ESCAPE = "Escape"; export interface UseListNavigationProps { /** * A ref that holds an array of list items. * @default empty list */ listRef: React.RefObject<Array<HTMLElement | null>>; /** * The index of the currently active (focused or highlighted) item, which may * or may not be selected. * @default null */ activeIndex: number | null; /** * A callback that is called when the user navigates to a new active item, * passed in a new `activeIndex`. */ onNavigate?: ((activeIndex: number | null, event: React.SyntheticEvent | undefined) => void) | undefined; /** * Whether the Hook is enabled, including all internal Effects and event * handlers. * @default true */ enabled?: boolean | undefined; /** * The currently selected item index, which may or may not be active. * @default null */ selectedIndex?: (number | null) | undefined; /** * Whether to focus the item upon opening the floating element. 'auto' infers * what to do based on the input type (keyboard vs. pointer), while a boolean * value will force the value. * @default 'auto' */ focusItemOnOpen?: (boolean | 'auto') | undefined; /** * Whether hovering an item synchronizes the focus. * @default true */ focusItemOnHover?: boolean | undefined; /** * Whether pressing an arrow key on the navigation’s main axis opens the * floating element. * @default true */ openOnArrowKeyDown?: boolean | undefined; /** * By default elements with either a `disabled` or `aria-disabled` attribute * are skipped in the list navigation — however, this requires the items to * be rendered. * This prop allows you to manually specify indices which should be disabled, * overriding the default logic. * For Windows-style select popups, where the menu does not open when * navigating via arrow keys, specify an empty array. * @default undefined */ disabledIndices?: (ReadonlyArray<number> | ((index: number) => boolean)) | undefined; /** * Determines whether focus can escape the list, such that nothing is selected * after navigating beyond the boundary of the list. In some * autocomplete/combobox components, this may be desired, as screen * readers will return to the input. * `loopFocus` must be `true`. * @default false */ allowEscape?: boolean | undefined; /** * Determines whether focus should loop around when navigating past the first * or last item. * @default false */ loopFocus?: boolean | undefined; /** * If the list is nested within another one (e.g. a nested submenu), the * navigation semantics change. * @default false */ nested?: boolean | undefined; /** * Allows to specify the orientation of the parent list, which is used to * determine the direction of the navigation. * This is useful when list navigation is used within a Composite, * as the hook can't determine the orientation of the parent list automatically. */ parentOrientation?: UseListNavigationProps['orientation'] | undefined; /** * Whether the direction of the floating element’s navigation is in RTL * layout. * @default false */ rtl?: boolean | undefined; /** * Whether the focus is virtual (using `aria-activedescendant`). * Use this if you need focus to remain on the reference element * (such as an input), but allow arrow keys to navigate list items. * This is common in autocomplete listbox components. * Your virtually-focused list items must have a unique `id` set on them. * If you’re using a component role with the `useRole()` Hook, then an `id` is * generated automatically. * @default false */ virtual?: boolean | undefined; /** * The orientation in which navigation occurs. * @default 'vertical' */ orientation?: ('vertical' | 'horizontal' | 'both') | undefined; /** * Specifies how many columns the list has (i.e., it’s a grid). Use an * orientation of 'horizontal' (e.g. for an emoji picker/date picker, where * pressing ArrowRight or ArrowLeft can change rows), or 'both' (where the * current row cannot be escaped with ArrowRight or ArrowLeft, only ArrowUp * and ArrowDown). * @default 1 */ cols?: number | undefined; /** * The id of the root component. */ id?: string | undefined; /** * Whether to clear the active index when the pointer leaves an item. * @default true */ resetOnPointerLeave?: boolean | undefined; /** * External FlatingTree to use when the one provided by context can't be used. */ externalTree?: FloatingTreeStore | undefined; } /** * Adds arrow key-based navigation of a list of items, either using real DOM * focus or virtual focus. * @see https://floating-ui.com/docs/useListNavigation */ export declare function useListNavigation(context: FloatingRootContext | FloatingContext, props: UseListNavigationProps): ElementProps;