Autocomplete
An input that suggests options as you type.
View as MarkdownUsage guidelines
- No selection state: 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.
- Filterable command picker: The input can be used as a filter for command items that perform an action when clicked when rendered inside the popup.
Anatomy
Import the components and place them together:
import { Autocomplete } from '@base-ui-components/react/autocomplete';
<Autocomplete.Root>
<Autocomplete.Input />
<Autocomplete.Trigger />
<Autocomplete.Icon />
<Autocomplete.Clear />
<Autocomplete.Value />
<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>API reference
Root
Groups all parts of the autocomplete. Doesn't render its own HTML element.
namestring
—
namestring
—- Name
- Description
Identifies the field when a form is submitted.
- Type
string | undefined
defaultValueUnion
—
defaultValueUnion
—- Name
- Description
The uncontrolled input value of the autocomplete when it's initially rendered.
To render a controlled autocomplete, use the
valueprop instead.- Type
string | number | string[] | undefined
valueUnion
—
valueUnion
—- Name
- Description
The input value of the autocomplete. Use when controlled.
- Type
string | number | string[] | undefined
onValueChangefunction
—
onValueChangefunction
—- Name
- Description
Event handler called when the input value of the autocomplete changes.
- Type
| (( value: string, eventDetails: Autocomplete.Root.ChangeEventDetails, ) => void) | undefined
defaultOpenboolean
false
defaultOpenboolean
false
- Name
- Description
Whether the popup is initially open.
To render a controlled popup, use the
openprop instead.- Type
boolean | undefined- Default
false
openboolean
—
openboolean
—- Name
- Description
Whether the popup is currently open. Use when controlled.
- Type
boolean | undefined
onOpenChangefunction
—
onOpenChangefunction
—- Name
- Description
Event handler called when the popup is opened or closed.
- Type
| (( open: boolean, eventDetails: Autocomplete.Root.ChangeEventDetails, ) => void) | undefined
actionsRefRefObject<Autocomplete.Root.Actions>
—
actionsRefRefObject<Autocomplete.Root.Actions>
—- Name
- Description
A ref to imperative actions.
unmount: When specified, the autocomplete will not be unmounted when closed. Instead, theunmountfunction must be called to unmount the autocomplete manually. Useful when the autocomplete's animation is controlled by an external library.
- Type
| React.RefObject<Autocomplete.Root.Actions> | undefined
alwaysSubmitOnEnterboolean
false
alwaysSubmitOnEnterboolean
false
- Description
Whether pressing Enter in the input should always allow forms to submit. By default, pressing Enter in the input will stop form submission if an item is highlighted.
- Type
boolean | undefined- Default
false
autoHighlightboolean
false
autoHighlightboolean
false
- Name
- Description
Whether to automatically highlight the first item while filtering.
- Type
boolean | undefined- Default
false
filterUnion
—
filterUnion
—- Name
- Description
Filter function used to match items vs input query.
- Type
| (( itemValue: any, query: string, itemToString: | ((itemValue: any) => string) | undefined, ) => boolean) | (( itemValue: ItemValue, query: string, itemToString: | ((itemValue: ItemValue) => string) | null | undefined
gridboolean
false
gridboolean
false
- Name
- Description
Whether list items are presented in a grid layout. When enabled, arrow keys navigate across rows and columns inferred from DOM rows.
- Type
boolean | undefined- Default
false
itemToStringValueUnion
—
itemToStringValueUnion
—- Description
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.- Type
| ((itemValue: any) => string) | ((itemValue: ItemValue) => string) | undefined
itemsUnion
—
itemsUnion
—- Name
- Description
The items to be displayed in the list. Can be either a flat array of items or an array of groups with items.
- Type
{ items: any[] }[] | ItemValue[] | undefined
limitnumber
-1
limitnumber
-1
- Name
- Description
The maximum number of items to display in the list.
- Type
number | undefined- Default
-1
localeIntl.LocalesArgument
—
localeIntl.LocalesArgument
—- Name
- Description
The locale to use for string comparison. Defaults to the user's runtime locale.
- Type
Intl.LocalesArgument | undefined
modalboolean
false
modalboolean
false
- Name
- Description
Determines 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.
- Type
boolean | undefined- Default
false
modeUnion
'list'
modeUnion
'list'
- Name
- Description
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.
- Type
'none' | 'list' | 'inline' | 'both' | undefined- Default
'list'
onInputValueChangefunction
—
onInputValueChangefunction
—- Description
Event handler called when the input value changes.
- Type
| (( inputValue: string, eventDetails: Autocomplete.Root.ChangeEventDetails, ) => void) | undefined
onItemHighlightedfunction
—
onItemHighlightedfunction
—- Description
Callback fired when an item is highlighted or unhighlighted. Receives the highlighted item value (or
undefinedif no item is highlighted) and event details with areasonproperty describing why the highlight changed. Thereasoncan be:'keyboard': the highlight changed due to keyboard navigation.'pointer': the highlight changed due to pointer hovering.'none': the highlight changed programmatically.
- Type
| (( highlightedValue: any | undefined, eventDetails: Autocomplete.Root.HighlightEventDetails, ) => void) | (( highlightedValue: ItemValue | undefined, eventDetails: Autocomplete.Root.HighlightEventDetails, ) => void) | undefined
onOpenChangeCompletefunction
—
onOpenChangeCompletefunction
—- Description
Event handler called after any animations complete when the popup is opened or closed.
- Type
((open: boolean) => void) | undefined
openOnInputClickboolean
true
openOnInputClickboolean
true
- Name
- Description
Whether the popup opens when clicking the input.
- Type
boolean | undefined- Default
true
virtualizedboolean
false
virtualizedboolean
false
- Name
- Description
Whether the items are being externally virtualized.
- Type
boolean | undefined- Default
false
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
readOnlyboolean
false
readOnlyboolean
false
- Name
- Description
Whether the user should be unable to choose a different option from the popup.
- Type
boolean | undefined- Default
false
requiredboolean
false
requiredboolean
false
- Name
- Description
Whether the user must choose a value before submitting a form.
- Type
boolean | undefined- Default
false
inputRefRef<HTMLInputElement>
—
inputRefRef<HTMLInputElement>
—- Name
- Description
A ref to the hidden input element.
- Type
React.Ref<HTMLInputElement> | undefined
idstring
—
idstring
—- Name
- Description
The id of the component.
- Type
string | undefined
childrenReactNode
—
childrenReactNode
—- Name
- Type
React.ReactNode | undefined
Value
The current value of the autocomplete. Doesn't render its own HTML element.
childrenReactNode | ((value: string) => ReactNode)
—
childrenReactNode | ((value: string) => ReactNode)
—- Name
- Type
React.ReactNode | ((value: string) => ReactNode)
Input
A text input to search for items in the list.
Renders an <input> element.
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Input.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Input.State, ) => ReactElement)
data-popup-open
Present when the corresponding popup is open.
data-pressed
Present when the input is pressed.
data-disabled
Present when the component is disabled.
data-readonly
Present when the component is readonly.
data-required
Present when the component is required.
data-valid
Present when the component is in valid state (when wrapped in Field.Root).
data-invalid
Present when the component is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the component's value has changed (when wrapped in Field.Root).
data-touched
Present when the component has been touched (when wrapped in Field.Root).
data-filled
Present when the component has a value (when wrapped in Field.Root).
data-focused
Present when the input is focused (when wrapped in Field.Root).
Trigger
A button that opens the popup.
Renders a <button> element.
nativeButtonboolean
true
nativeButtonboolean
true
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (e.g.<div>).- Type
boolean | undefined- Default
true
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Trigger.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Trigger.State, ) => ReactElement)
data-popup-open
Present when the corresponding popup is open.
data-pressed
Present when the trigger is pressed.
data-disabled
Present when the component is disabled.
data-readonly
Present when the component is readonly.
data-required
Present when the component is required.
data-valid
Present when the component is in valid state (when wrapped in Field.Root).
data-invalid
Present when the component is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the component's value has changed (when wrapped in Field.Root).
data-touched
Present when the component has been touched (when wrapped in Field.Root).
data-filled
Present when the component has a value (when wrapped in Field.Root).
data-focused
Present when the trigger is focused (when wrapped in Field.Root).
Icon
An icon that indicates that the trigger button opens the popup.
Renders a <span> element.
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Icon.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Icon.State, ) => ReactElement)
Clear
Clears the value when clicked.
Renders a <button> element.
nativeButtonboolean
true
nativeButtonboolean
true
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (e.g.<div>).- Type
boolean | undefined- Default
true
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Clear.State) => string)
keepMountedboolean
false
keepMountedboolean
false
- Name
- Description
Whether the component should remain mounted in the DOM when not visible.
- Type
boolean | undefined- Default
false
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Clear.State, ) => ReactElement)
data-popup-open
Present when the corresponding popup is open.
data-disabled
Present when the button is disabled.
data-starting-style
Present when the button is animating in.
data-ending-style
Present when the button is animating out.
List
A list container for the items.
Renders a <div> element.
childrenReactNode | ((item: any, index: number) => ReactNode)
—
childrenReactNode | ((item: any, index: number) => ReactNode)
—- Name
- Type
| React.ReactNode | ((item: any, index: number) => ReactNode)
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.List.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.List.State, ) => ReactElement)
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.
containerUnion
—
containerUnion
—- Name
- Description
A parent element to render the portal element into.
- Type
| HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Portal.State) => string)
keepMountedboolean
false
keepMountedboolean
false
- Name
- Description
Whether to keep the portal mounted in the DOM while the popup is hidden.
- Type
boolean | undefined- Default
false
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Portal.State, ) => ReactElement)
Backdrop
An overlay displayed beneath the popup.
Renders a <div> element.
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Backdrop.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Backdrop.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-starting-style
Present when the popup is animating in.
data-ending-style
Present when the popup is animating out.
Positioner
Positions the popup against the trigger.
Renders a <div> element.
collisionAvoidanceCollisionAvoidance
—
collisionAvoidanceCollisionAvoidance
—- Description
Determines how to handle collisions when positioning the popup.
- Type
| { side?: 'none' | 'flip' align?: 'none' | 'shift' | 'flip' fallbackAxisSide?: 'none' | 'start' | 'end' } | { side?: 'none' | 'shift' align?: 'none' | 'shift' fallbackAxisSide?: 'none' | 'start' | 'end' } | undefined- Example
<Positioner collisionAvoidance={{ side: 'shift', align: 'shift', fallbackAxisSide: 'none', }} />
alignAlign
'center'
alignAlign
'center'
- Name
- Description
How to align the popup relative to the specified side.
- Type
'center' | 'start' | 'end' | undefined- Default
'center'
alignOffsetnumber | OffsetFunction
0
alignOffsetnumber | OffsetFunction
0
- Name
- Description
Additional 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
dataobject parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.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.
- Type
| number | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined- Default
0- Example
<Positioner alignOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.width : anchor.height; }} />
sideSide
'bottom'
sideSide
'bottom'
- Name
- Description
Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
- Type
| 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | undefined- Default
'bottom'
sideOffsetnumber | OffsetFunction
0
sideOffsetnumber | OffsetFunction
0
- Name
- Description
Distance 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
dataobject parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.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.
- Type
| number | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined- Default
0- Example
<Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} />
arrowPaddingnumber
5
arrowPaddingnumber
5
- Name
- Description
Minimum 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.
- Type
number | undefined- Default
5
anchorUnion
—
anchorUnion
—- Name
- Description
An element to position the popup against. By default, the popup will be positioned against the trigger.
- Type
| Element | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null | undefined
collisionBoundaryBoundary
'clipping-ancestors'
collisionBoundaryBoundary
'clipping-ancestors'
- Description
An element or a rectangle that delimits the area that the popup is confined to.
- Type
| Element | 'clipping-ancestors' | Element[] | Rect | undefined- Default
'clipping-ancestors'
collisionPaddingPadding
5
collisionPaddingPadding
5
- Name
- Description
Additional space to maintain from the edge of the collision boundary.
- Type
| { top?: number right?: number bottom?: number left?: number } | number | undefined- Default
5
stickyboolean
false
stickyboolean
false
- Name
- Description
Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.
- Type
boolean | undefined- Default
false
positionMethod'fixed' | 'absolute'
'absolute'
positionMethod'fixed' | 'absolute'
'absolute'
- Name
- Description
Determines which CSS
positionproperty to use.- Type
'fixed' | 'absolute' | undefined- Default
'absolute'
trackAnchorboolean
true
trackAnchorboolean
true
- Name
- Description
Whether the popup tracks any layout shift of its positioning anchor.
- Type
boolean | undefined- Default
true
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Autocomplete.Positioner.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Positioner.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to specified side.
data-empty
Present when the items list is empty.
data-side
Indicates which side the popup is positioned relative to the trigger.
--anchor-height
The anchor's height.
--anchor-width
The anchor's width.
--available-height
The available height between the trigger and the edge of the viewport.
--available-width
The available width between the trigger and the edge of the viewport.
--transform-origin
The coordinates that this element is anchored to. Used for animations and transitions.
Popup
A container for the list.
Renders a <div> element.
initialFocusUnion
—
initialFocusUnion
—- Name
- Description
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).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse,touch,pen, orkeyboard). Return an element to focus,trueto use the default behavior, orfalse/undefinedto do nothing.
- Type
| boolean | React.RefObject<HTMLElement | null> | (( openType: InteractionType, ) => boolean | void | HTMLElement | null) | undefined
finalFocusUnion
—
finalFocusUnion
—- Name
- Description
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).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse,touch,pen, orkeyboard). Return an element to focus,trueto use the default behavior, orfalse/undefinedto do nothing.
- Type
| boolean | React.RefObject<HTMLElement | null> | (( closeType: InteractionType, ) => boolean | void | HTMLElement | null) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Popup.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Popup.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-align
Indicates how the popup is aligned relative to specified side.
data-empty
Present when the items list is empty.
data-instant
Present if animations should be instant.
data-side
Indicates which side the popup is positioned relative to the trigger.
data-starting-style
Present when the popup is animating in.
data-ending-style
Present when the popup is animating out.
Arrow
Displays an element positioned against the anchor.
Renders a <div> element.
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Arrow.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Arrow.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-uncentered
Present when the arrow is uncentered.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
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.
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Status.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Status.State, ) => ReactElement)
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.
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Empty.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Empty.State, ) => ReactElement)
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.
children*((item: any, index: number) => ReactNode)
—
children*((item: any, index: number) => ReactNode)
—- Name
- Type
(item: any, index: number) => ReactNode
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.
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Row.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Row.State, ) => ReactElement)
Item
An individual item in the list.
Renders a <div> element.
valueany
null
valueany
null
- Name
- Description
A unique value that identifies this item.
- Type
any- Default
null
onClickfunction
—
onClickfunction
—- Name
- Description
An optional click handler for the item when selected. It fires when clicking the item with the pointer, as well as when pressing
Enterwith the keyboard if the item is highlighted when theInputorListelement has focus.- Type
React.MouseEventHandler<HTMLElement> | undefined
indexnumber
—
indexnumber
—- Name
- Description
The index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM.
- Type
number | undefined
nativeButtonboolean
false
nativeButtonboolean
false
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set totrueif the rendered element is a native button.- Type
boolean | undefined- Default
false
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
childrenReactNode
—
childrenReactNode
—- Name
- Type
React.ReactNode
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Item.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Item.State, ) => ReactElement)
data-selected
Present when the item is selected.
data-highlighted
Present when the item is highlighted.
data-disabled
Present when the item is disabled.
Group
Groups related items with the corresponding label.
Renders a <div> element.
itemsany[]
—
itemsany[]
—- Name
- Description
Items to be rendered within this group. When provided, child
Collectioncomponents will use these items.- Type
any[] | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Autocomplete.Group.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.Group.State, ) => ReactElement)
GroupLabel
An accessible label that is automatically associated with its parent group.
Renders a <div> element.
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Autocomplete.GroupLabel.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Autocomplete.GroupLabel.State, ) => ReactElement)
Separator
A separator element accessible to screen readers.
Renders a <div> element.
orientationOrientation
'horizontal'
orientationOrientation
'horizontal'
- Name
- Description
The orientation of the separator.
- Type
'horizontal' | 'vertical' | undefined- Default
'horizontal'
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Separator.State) => string)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Separator.State, ) => ReactElement)
useFilter
Matches items against a query using Intl.Collator for robust string matching.
This hook is used when externally filtering items.
Input parameters
Accepts all Intl.CollatorOptions, plus the following option:
localeIntl.LocalesArgument
—
localeIntl.LocalesArgument
—- Name
- Description
The locale to use for string comparison.
- Type
Intl.LocalesArgument
Return value
contains(itemValue: any, query: string) => boolean
—
contains(itemValue: any, query: string) => boolean
—- Name
- Description
Returns whether the item matches the query anywhere.
- Type
(itemValue: any, query: string) => boolean
startsWith(itemValue: any, query: string) => boolean
—
startsWith(itemValue: any, query: string) => boolean
—- Name
- Description
Returns whether the item starts with the query.
- Type
(itemValue: any, query: string) => boolean
endsWith(itemValue: any, query: string) => boolean
—
endsWith(itemValue: any, query: string) => boolean
—- Name
- Description
Returns whether the item ends with the query.
- Type
(itemValue: any, query: string) => boolean
TypeScript inference
Autocomplete infers the item type from the items prop passed to <Autocomplete.Root>.
If using itemToStringValue, the value prop on the <Autocomplete.Item> must match the type of an item in the items array.
Examples
Async search
Load items asynchronously while typing and render custom status content.
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
Group related options together by passing an array of group objects to the items prop.
Fuzzy matching
Use fuzzy matching to find relevant results even when the query doesn’t exactly match the item text.
Limit results
Limit the number of visible items using the limit prop and guide users to refine their query using <Autocomplete.Status>.
Auto highlight
Automatically highlight the first matching option as the user types using the autoHighlight prop.
Grid layout
Display items in a grid layout, wrapping each row in <Autocomplete.Row> components.
Virtualized
Efficiently handle large datasets using a virtualization library like @tanstack/react-virtual.