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.

103 lines 5.8 kB
import * as React from 'react'; import { AriaCombobox } from "./AriaCombobox.js"; /** * Groups all parts of the combobox. * Doesn't render its own HTML element. * * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox) */ export declare function ComboboxRoot<Value, Multiple extends boolean | undefined = false>(props: ComboboxRoot.Props<Value, Multiple>): React.JSX.Element; type ModeFromMultiple<Multiple extends boolean | undefined> = Multiple extends true ? 'multiple' : 'single'; type ComboboxValueType<Value, Multiple extends boolean | undefined> = Multiple extends true ? Value[] : Value; export type ComboboxRootProps<Value, Multiple extends boolean | undefined = false> = Omit<AriaCombobox.Props<Value, ModeFromMultiple<Multiple>>, 'fillInputOnItemPress' | 'autoComplete' | 'formAutoComplete' | 'submitOnItemClick' | 'autoHighlight' | 'keepHighlight' | 'highlightItemOnHover' | 'itemToStringLabel' | 'itemToStringValue' | 'isItemEqualToValue' | 'selectionMode' | 'defaultSelectedValue' | 'selectedValue' | 'onSelectedValueChange' | 'actionsRef' | 'onOpenChange' | 'onInputValueChange' | 'onItemHighlighted'> & { /** * Whether multiple items can be selected. * @default false */ multiple?: Multiple | undefined; /** * Provides a hint to the browser for autofill. * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/autocomplete */ autoComplete?: string | undefined; /** * Whether the first matching item is highlighted automatically while filtering. * @default false */ autoHighlight?: boolean | undefined; /** * Whether moving the pointer over items should highlight them. * Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. * @default true */ highlightItemOnHover?: boolean | undefined; /** * When the item values are objects (`<Combobox.Item value={object}>`), this function converts the object value to a string representation for display in the input. * If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop. */ itemToStringLabel?: ((itemValue: Value) => string) | undefined; /** * When the item values are objects (`<Combobox.Item value={object}>`), this function converts the object value to a string representation for form submission. * If the shape of the object is `{ value, label }`, the value will be used automatically without needing to specify this prop. */ itemToStringValue?: ((itemValue: Value) => string) | undefined; /** * Custom comparison logic used to determine if a combobox item value matches the current selected value. Useful when item values are objects without matching referentially. * Defaults to `Object.is` comparison. */ isItemEqualToValue?: ((itemValue: Value, value: Value) => boolean) | undefined; /** * The uncontrolled selected value of the combobox when it's initially rendered. * * To render a controlled combobox, use the `value` prop instead. */ defaultValue?: (ComboboxValueType<Value, Multiple> | null) | undefined; /** * A ref to imperative actions. * - `unmount`: When specified, the combobox will not be unmounted when closed. * Instead, the `unmount` function must be called to unmount the combobox manually. * Useful when the combobox's animation is controlled by an external library. */ actionsRef?: React.RefObject<ComboboxRoot.Actions | null> | undefined; /** * Event handler called when the popup is opened or closed. */ onOpenChange?: ((open: boolean, eventDetails: ComboboxRoot.ChangeEventDetails) => void) | undefined; /** * Event handler called when the input value changes. */ onInputValueChange?: ((inputValue: string, eventDetails: ComboboxRoot.ChangeEventDetails) => void) | undefined; /** * Callback fired when an item is highlighted or unhighlighted. * Receives the highlighted item value (or `undefined` if no item is highlighted) and event details with a `reason` property describing why the highlight changed. * The `reason` can be: * - `'keyboard'`: the highlight changed due to keyboard navigation. * - `'pointer'`: the highlight changed due to pointer hovering. * - `'none'`: the highlight changed programmatically. */ onItemHighlighted?: ((highlightedValue: Value | undefined, eventDetails: ComboboxRoot.HighlightEventDetails) => void) | undefined; /** * The selected value of the combobox. Use when controlled. */ value?: (ComboboxValueType<Value, Multiple> | null) | undefined; /** * Event handler called when the selected value of the combobox changes. */ onValueChange?: ((value: ComboboxValueType<Value, Multiple> | (Multiple extends true ? never : null), eventDetails: ComboboxRoot.ChangeEventDetails) => void) | undefined; }; export type ComboboxRootState = AriaCombobox.State; export type ComboboxRootActions = AriaCombobox.Actions; export type ComboboxRootChangeEventReason = AriaCombobox.ChangeEventReason; export type ComboboxRootChangeEventDetails = AriaCombobox.ChangeEventDetails; export type ComboboxRootHighlightEventReason = AriaCombobox.HighlightEventReason; export type ComboboxRootHighlightEventDetails = AriaCombobox.HighlightEventDetails; export declare namespace ComboboxRoot { type Props<Value, Multiple extends boolean | undefined = false> = ComboboxRootProps<Value, Multiple>; type State = ComboboxRootState; type Actions = ComboboxRootActions; type ChangeEventReason = ComboboxRootChangeEventReason; type ChangeEventDetails = ComboboxRootChangeEventDetails; type HighlightEventReason = ComboboxRootHighlightEventReason; type HighlightEventDetails = ComboboxRootHighlightEventDetails; } export {};