Components
Autocomplete
An input that suggests options as you type.
Usage guidelines#
- Avoid when selection state is needed: Use Combobox instead of Autocomplete if the selection should be remembered and the input value cannot be custom. Unlike Combobox, Autocomplete's input can contain free-form text, as its suggestions only optionally autocomplete the text.
- Form controls must have an accessible name: It can be created using a
<label>element or the Field component. See the forms guide. - Closing animations: The popup stays rendered until its closing animation finishes. See JavaScript animations for manual control.
Anatomy#
Import the components and place them together:
import { Autocomplete } from '@egoist/solid-base/autocomplete';
<Autocomplete.Root>
<Autocomplete.InputGroup>
<Autocomplete.Input />
<Autocomplete.Trigger />
<Autocomplete.Icon />
<Autocomplete.Clear />
<Autocomplete.Value />
</Autocomplete.InputGroup>
<Autocomplete.Portal>
<Autocomplete.Backdrop />
<Autocomplete.Positioner>
<Autocomplete.Popup>
<Autocomplete.Arrow />
<Autocomplete.Status />
<Autocomplete.Empty />
<Autocomplete.List>
<Autocomplete.Row>
<Autocomplete.Item />
</Autocomplete.Row>
<Autocomplete.Separator />
<Autocomplete.Group>
<Autocomplete.GroupLabel />
</Autocomplete.Group>
<Autocomplete.Collection />
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>;Item values#
Each <Autocomplete.Item> takes a value prop identifying it. Pass the item being rendered, so
that props like itemToStringValue receive it.
A function child of <Autocomplete.List> renders each item of the filtered list:
<Autocomplete.Root items={tags}>
{/* ... */}
<Autocomplete.List>
{(tag: Tag) => <Autocomplete.Item value={tag}>{tag.value}</Autocomplete.Item>}
</Autocomplete.List>
</Autocomplete.Root>Examples#
Async search#
Load items asynchronously while typing and render custom status content.
Pass filter={null} when the results are already filtered by the server, and keep the query in a
signal with value and onValueChange. An AbortController discards responses that arrive after
a newer query was typed.
Inline autocomplete#
Autofill the input with the highlighted item while navigating with arrow keys using the mode
prop. Accepts aria-autocomplete values list, both, inline, or none.
Grouped#
Organize related options with <Autocomplete.Group> and <Autocomplete.GroupLabel> to add
section headings inside the popup.
Groups are represented by an array of objects with an items property, which itself is an array
of individual items for each group. An extra property, such as value, can be provided for the
heading text when rendering the group label.
interface ProduceGroupItem {
value: string;
items: string[];
}
const groups: ProduceGroupItem[] = [
{
value: 'Fruits',
items: ['Apple', 'Banana', 'Orange'],
},
{
value: 'Vegetables',
items: ['Carrot', 'Lettuce', 'Spinach'],
},
];Pass each group's items to <Autocomplete.Group items> and render them with
<Autocomplete.Collection>:
Fuzzy matching#
Use fuzzy matching to find relevant results even when the query doesn't exactly match the item
text. Pass a custom filter to <Autocomplete.Root>: it receives each item and the query, and
keeps the item when it returns true.
A function child of <Autocomplete.Value> receives the current input value, and re-runs when it
changes. The demo uses it to highlight the matched text in each item.
Limit results#
Limit the number of visible items using the limit prop and guide users to refine their query
using <Autocomplete.Status>.
Auto highlight#
The first matching item can be automatically highlighted as the user types by specifying the
autoHighlight prop on <Autocomplete.Root>. Set the prop's value to "always" if the highlight
should always be present, such as when the list is rendered inline within a dialog.
The prop can be combined with the keepHighlight and highlightItemOnHover props to configure how
the highlight behaves during mouse interactions.
Virtualized#
Efficiently handle large datasets by rendering only the items in view. Add the virtualized prop
to <Autocomplete.Root>, read the filtered items with Autocomplete.useFilteredItems(), and pass
each rendered item its index in the filtered list.
The demo windows a fixed-height list by hand. A virtualization library such as
@tanstack/solid-virtual works the same way: render its virtual items as <Autocomplete.Item>
parts with their index, and scroll to the highlighted index from onItemHighlighted.
API reference#
<Autocomplete.Root>
Groups all parts of the autocomplete. Doesn't render its own HTML element.
idstring—The id of the component.
disabledbooleanfalseWhether the component should ignore user interaction.
formstring—Identifies the form that owns the internal input. Useful when the autocomplete is rendered outside the form.
namestring—Identifies the field when a form is submitted.
valueAriaCombobox.Props<string, 'none'>['inputValue']—The input value of the autocomplete. Use when controlled.
defaultValueAriaCombobox.Props<string, 'none'>['defaultInputValue']—The uncontrolled input value of the autocomplete when it's initially rendered.
To render a controlled autocomplete, use the value prop instead.
readOnlybooleanfalseWhether the user should be unable to choose a different option from the popup.
requiredbooleanfalseWhether the user must choose a value before submitting a form.
filterAriaCombobox.Props<ItemValue, 'none'>['filter']—Filter function used to match items against the input query.
itemToStringValue((itemValue: ItemValue) => string)—When the item values are objects (<Autocomplete.Item value={object}>), this function converts the object value to a string representation for both display in the input and form submission. If the shape of the object is { value, label }, the label will be used automatically without needing to specify this prop.
inlinebooleanfalseWhether the list is rendered inline without using the component's own popup.
Specify open unconditionally in conjunction with this prop so the list is considered visible: <Autocomplete.Root inline open>
autoHighlightboolean | 'always'falseWhether the first matching item is highlighted automatically. - true: highlight after the user types and keep the highlight while the query changes. - 'always': always highlight the first item.
keepHighlightbooleanfalseWhether the highlighted item should be preserved when the pointer leaves the list.
highlightItemOnHoverbooleantrueWhether moving the pointer over items should highlight them. Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state.
actionsRefActionsRef<AutocompleteRootActions>—A ref to imperative actions: a ref object ({ current: null }) or a callback receiving them. - unmount: Ends the closing phase of the autocomplete after an externally controlled closing animation finishes. Call preventUnmountOnClose() in onOpenChange first, otherwise the autocomplete completes closing on its own. Whether it leaves the DOM is decided by keepMounted on the portal. - close: Closes the autocomplete imperatively when called.
onOpenChange((open: boolean, eventDetails: AutocompleteRootOpenChangeEventDetails) => void)—Event handler called when the popup is opened or closed.
openOnInputClickbooleanfalseWhether the popup opens when clicking the input.
filteredItemsreadonly ItemValue[] | readonly Group<ItemValue>[]—Filtered items to display in the list. When provided, the list uses these items instead of filtering the items prop internally. When items is also provided, this array must preserve its flat or grouped structure. Nullish entries are not supported, as in items. Use when you want to control filtering logic externally with the useFilter() hook.
defaultOpenbooleanfalseWhether the popup is initially open.
To render a controlled popup, use the open prop instead.
openboolean—Whether the popup is currently open. Use when controlled.
onOpenChangeComplete((open: boolean) => void)—Event handler called after any animations complete when the popup is opened or closed.
loopFocusbooleantrueWhether to loop keyboard focus back to the input when the end of the list is reached while using the arrow keys. The first item can then be reached by pressing <kbd>ArrowDown</kbd> again from the input, or the last item can be reached by pressing <kbd>ArrowUp</kbd> from the input. The input is always included in the focus loop per ARIA Authoring Practices. When disabled, focus does not move when on the last element and the user presses <kbd>ArrowDown</kbd>, or when on the first element and the user presses <kbd>ArrowUp</kbd>.
onItemHighlighted| (( highlightedValue: ItemValue, eventDetails: AutocompleteRootHighlightEventDetails, ) => void)—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. The event may be a MouseEvent rather than a PointerEvent. - 'none': the highlight changed for another reason, such as typing, autoHighlight, the item list changing, or the popup opening or closing.
inputRefRefProp<HTMLInputElement>—A ref to the hidden input element.
gridbooleanfalseWhether list items are presented in a grid layout. When enabled, arrow keys navigate across rows and columns inferred from DOM rows.
virtualizedbooleanfalseWhether the items are being externally virtualized.
modalbooleanfalseDetermines if the popup enters a modal state when open. - true: user interaction is limited to the popup: document page scroll is locked and pointer interactions on outside elements are disabled. - false: user interaction with the rest of the document is allowed.
limitnumber-1The maximum number of items to display in the list.
localeIntl.LocalesArgument—The locale to use for string comparison. Defaults to the user's runtime locale.
submitOnItemClickAriaCombobox.Props<ItemValue, 'none'>['submitOnItemClick']falseWhether clicking an item should submit the autocomplete's owning form. By default, clicking an item via a pointer or <kbd>Enter</kbd> key does not submit the owning form. Useful when the autocomplete is used as a single-field form search input.
mode'list' | 'both' | 'inline' | 'none''list'Controls how the autocomplete behaves with respect to list filtering and inline autocompletion. - list (default): items are dynamically filtered based on the input value. The input value does not change based on the active item. - both: items are dynamically filtered based on the input value, which will temporarily change based on the active item (inline autocompletion). - inline: items are static (not filtered), and the input value will temporarily change based on the active item (inline autocompletion). - none: items are static (not filtered), and the input value will not change based on the active item.
onValueChange((value: string, eventDetails: AutocompleteRootChangeEventDetails) => void)—Event handler called when the input value of the autocomplete changes.
items*Items—<Autocomplete.Trigger>
A button that opens the popup. Renders a <button> element.
disabledbooleanfalseWhether the component should ignore user interaction.
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-disabledPresent when the component is disabled.
data-readonlyPresent when the component is readonly.
data-popup-sideIndicates which side the corresponding popup is positioned relative to its anchor.
data-requiredPresent when the component is required.
data-validPresent when the component is in a valid state (when wrapped in Field.Root).
data-invalidPresent when the component is in an invalid state (when wrapped in Field.Root).
data-touchedPresent when the component has been touched (when wrapped in Field.Root).
data-dirtyPresent when the component's value has changed (when wrapped in Field.Root).
data-filledPresent when the component has a value (when wrapped in Field.Root).
data-focusedPresent when the trigger is focused (when wrapped in Field.Root).
data-list-emptyPresent when the corresponding items list is empty.
<Autocomplete.Value>
The current value of the autocomplete. Doesn't render its own HTML element.
<Autocomplete.Input>
A text input to search for items in the list. Renders an <input> element.
disabledbooleanfalseWhether the component should ignore user interaction.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.InputGroup>
A wrapper for the input and its associated controls. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-popup-openPresent when the corresponding popup is open.
data-pressedPresent when the input group is pressed.
data-disabledPresent when the component is disabled.
data-readonlyPresent when the component is readonly.
data-popup-sideIndicates which side the corresponding popup is positioned relative to its anchor.
data-validPresent when the component is in a valid state (when wrapped in Field.Root).
data-invalidPresent when the component is in an invalid state (when wrapped in Field.Root).
data-touchedPresent when the component has been touched (when wrapped in Field.Root).
data-dirtyPresent when the component's value has changed (when wrapped in Field.Root).
data-filledPresent when the component has a value (when wrapped in Field.Root).
data-focusedPresent when the component is focused (when wrapped in Field.Root).
data-list-emptyPresent when the corresponding items list is empty.
<Autocomplete.Icon>
An icon that indicates that the trigger button opens the popup. Renders a <span> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Clear>
Clears the value when clicked. Renders a <button> element.
disabledbooleanfalseWhether the component should ignore user interaction.
keepMountedbooleanfalseWhether the component should remain mounted in the DOM when not visible.
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.List>
A list container for the items. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Status>
Displays a status message whose content changes are announced politely to screen readers. Useful for conveying the status of an asynchronously loaded list. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Portal>
A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.
keepMountedbooleanfalseWhether to keep the portal mounted in the DOM while the popup is hidden.
containerPortalContainer—A parent element to render the portal element into.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Backdrop>
An overlay displayed beneath the popup. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Positioner>
Positions the popup against the input or trigger. Renders a <div> element.
anchor| Element | null | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null)—An element to position the popup against. By default, the popup will be positioned against the trigger.
Accepts an element, a virtual element, a ref object, or a function (such as a signal accessor) that returns an element or a virtual element.
positionMethod'absolute' | 'fixed''absolute'Determines which CSS position property to use.
sideSide'bottom'Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
sideOffsetnumber | OffsetFunction0Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.
The function takes a data object parameter with the following properties: - data.anchor: the dimensions of the anchor element with properties width and height. - data.positioner: the dimensions of the positioner element with properties width and height. - data.side: which side of the anchor element the positioner is aligned against. - data.align: how the positioner is aligned relative to the specified side.
alignAlign'center'How to align the popup relative to the specified side.
alignOffsetnumber | OffsetFunction0Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.
The function takes a data object parameter with the following properties: - data.anchor: the dimensions of the anchor element with properties width and height. - data.positioner: the dimensions of the positioner element with properties width and height. - data.side: which side of the anchor element the positioner is aligned against. - data.align: how the positioner is aligned relative to the specified side.
collisionBoundaryBoundary'clipping-ancestors'An element or a rectangle that delimits the area that the popup is confined to.
collisionPaddingPadding5Additional space to maintain from the edge of the collision boundary.
stickybooleanfalseWhether to maintain the popup in the viewport after the anchor element was scrolled out of view.
arrowPaddingnumber5Minimum distance to maintain between the arrow and the edges of the popup.
Use it to prevent the arrow element from hanging out of the rounded corners of a popup.
disableAnchorTrackingbooleanfalseWhether to disable the popup from tracking any layout shift of its positioning anchor.
collisionAvoidanceCollisionAvoidance—Determines how to handle collisions when positioning the popup.
side controls overflow on the preferred placement axis (top/bottom or left/right): - 'flip': keep the requested side when it fits; otherwise try the opposite side (top and bottom, or left and right). - 'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible. - 'none': do not correct side-axis overflow.
align controls overflow on the alignment axis (start/center/end): - 'flip': keep side, but swap start and end when the requested alignment overflows. - 'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit. - 'none': do not correct alignment-axis overflow.
fallbackAxisSide controls fallback behavior on the perpendicular axis when the preferred axis cannot fit: - 'start': allow perpendicular fallback and try the logical start side first (top before bottom, or left before right in LTR). - 'end': allow perpendicular fallback and try the logical end side first (bottom before top, or right before left in LTR). - 'none': do not fallback to the perpendicular axis.
When side is 'shift', explicitly setting align only supports 'shift' or 'none'. If align is omitted, it defaults to 'flip'.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Popup>
A container for the list. Renders a <div> element.
initialFocusFocusTargetProp—Determines the element to focus when the popup is opened.
- false: Do not move focus. - true: Move focus based on the default behavior (first tabbable element or popup). - An element or a ref object ({ current }): Move focus to that element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.
finalFocusFocusTargetProp—Determines the element to focus when the popup is closed.
- false: Do not move focus. - true: Move focus based on the default behavior (trigger or previously focused element). - An element or a ref object ({ current }): Move focus to that element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Arrow>
Displays an element positioned against the anchor. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Group>
Groups related items with the corresponding label. Renders a <div> element.
itemsreadonly any[]—Items to be rendered within this group. When provided, child Collection components will use these items.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.GroupLabel>
An accessible label that is automatically associated with its parent group. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Item>
An individual item in the list. Renders a <div> element.
onClickBaseUIComponentProps<'div', AutocompleteItemState>['onClick']—An optional click handler for the item when selected. It fires when clicking the item with the pointer, as well as when pressing Enter with the keyboard if the item is highlighted when the Input or List element has focus.
indexnumber—The index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM.
valueanynullA unique value that identifies this item.
disabledbooleanfalseWhether the component should ignore user interaction.
nativeButtonbooleanfalseWhether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Row>
Displays a single row of items in a grid list. Enable grid on the root component to turn the listbox into a grid. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Collection>
Renders filtered list items. Doesn't render its own HTML element.
If rendering a flat list, pass a function child to the List component instead, which implicitly wraps it.
<Autocomplete.Empty>
Renders its children only when the list is empty. Requires the items prop on the root component. Announces changes politely to screen readers. Renders a <div> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
<Autocomplete.Separator>
A separator element accessible to screen readers. Renders a <div> element.
orientationOrientation'horizontal'The orientation of the separator.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
useFilter#
Matches items against a query using Intl.Collator for robust string matching. Use it when
filtering items externally.
const { contains, startsWith, endsWith } = Autocomplete.useFilter({ sensitivity: 'base' });
contains('Crème brûlée', 'creme'); // trueIt accepts Intl.CollatorOptions plus a locale (defaults to the user's runtime locale), and
returns contains, startsWith and endsWith functions with the signature
(item, query, itemToString?) => boolean.
useFilteredItems#
Returns the internally filtered items when called inside <Autocomplete.Root>.
const filteredItems = Autocomplete.useFilteredItems<Tag>();
filteredItems().length;