Autocomplete
Text input with intelligent suggestions and auto-completion functionality
Preview
Installation
Usage
Examples
Async Loading
Fetch suggestions asynchronously from an API.
Auto Highlight
Automatically highlight the first suggestion.
Clearable Input
Add a clear button to reset the input value.
Fuzzy Search
Enable fuzzy matching for more flexible searching.
Grouped Options
Organize suggestions into categories.
Inline Suggestions
Display suggestions inline within the input.
Limited Results
Limit the number of displayed suggestions.
Virtualized
Use virtualization for large lists (100+ items) to maintain smooth performance. Only renders items visible in the viewport, dramatically reducing DOM nodes.
Key concepts:
- Use
useListVirtualizerhook - Handles scroll positioning, keyboard navigation, and item measurement. See useListVirtualizer docs for full API reference. - Use
useAutocompleteFilteredItems()inside Root - CalluseAutocompleteFilteredItems()in a child component ofAutocompleteRootto get internally filtered items without manual filtering boilerplate. - Replace
AutocompleteListwithAutocompleteVirtualizedList- AcceptsscrollRefandtotalSizefrom the hook. - Pass
virtualizedanditemson Root - Enables virtualized mode with your full item list. - Use
useHighlightHandler- Pass avirtualizerRefto the child and useuseHighlightHandler(virtualizerRef)on Root so keyboard navigation scrolls to the highlighted item. - Override item margins - Pass
className="mt-0! mb-0!"toAutocompleteItemsince virtualized items are absolutely positioned and the virtualizer handles padding.
Manual filtering still works — If you need custom filter logic (fuzzy search, server-side filtering), you can still compute
filteredItemsexternally, passfilter={null}toAutocomplete.Root, and spreadrootPropsfromuseListVirtualizer. See useAutocompleteFilter.
API Reference
The Autocomplete component is built on top of Base UI's Autocomplete. All Base UI props are supported. The documentation below only covers custom props and modified defaults specific to our implementation.
For the complete Base UI API, see the Base UI Autocomplete documentation.
Props
AutocompletePositioner
Positions the suggestions dropdown relative to the input. Wraps Base UI's Autocomplete.Positioner.
AutocompleteList
Scrollable container for suggestion items. Wraps Base UI's Autocomplete.List.
AutocompleteVirtualizedList
Virtualized scrollable container for large lists. Use with useListVirtualizer hook for optimal performance with 100+ items.
Utilities
highlightText
Highlights matching portions of text by wrapping them in <mark> tags. Useful for showing which parts of a suggestion match the user's input.
See highlightText for full documentation and API reference.
Hooks
useAutocompleteFilter
Exposes Base UI's built-in filter matchers for external filtering. Required when using virtualization since you must compute filteredItems yourself.
Returns
| Property | Type | Description |
|---|---|---|
contains | (item, query, getItemLabel) => boolean | Returns true if item label contains query (case-insensitive) |
startsWith | (item, query, getItemLabel) => boolean | Returns true if item label starts with query |
endsWith | (item, query, getItemLabel) => boolean | Returns true if item label ends with query |
useAutocompleteFilteredItems
Returns the internally filtered items from the Autocomplete Root. Must be called inside AutocompleteRoot. Simplifies virtualized implementations by eliminating the need for manual query state, useDeferredValue, useFilter(), and useMemo filtering.
useFuzzyFilter
Provides fuzzy matching capabilities for flexible searching across multiple fields. Returns filter functions compatible with Base UI's Autocomplete.
See useFuzzyFilter for full documentation and API reference.
useListVirtualizer
Provides virtualization for large autocomplete lists using TanStack Virtual. Abstracts scroll handling, item positioning, and keyboard navigation.
See useListVirtualizer for full documentation and API reference.