Autocomplete
A searchable dropdown component that allows users to filter and select from a list of options.
Import
Usage
Examples
With custom input handling
Typing: waiting for input...
Allow custom values
Menu styling
With below list content
Controlled with selected option
Selected: apple
Inheritance
Autocomplete extends the <Input /> component and inherits all of its props and functionality. This means you can use any Input prop with Autocomplete, including:
size,radius,variant,colorlabel,labelAlign,description,messagestatus,required,isLoading,disabledstartContent,className, and all native input attributes
Reference: For a complete list of inherited props with detailed descriptions, see the Input documentation.
What Autocomplete adds
Autocomplete extends Input with the following additional features:
| Feature | Description |
|---|---|
| Options List | A dropdown menu showing filtered suggestions based on user input |
| Value Selection | Selection handling with onValueChange callback |
| Custom Values | Support for free-form values not in the options list |
| Below List Content | Ability to render custom content below the options list |
| Menu Configuration | Full control over dropdown menu appearance and behavior |
What Autocomplete modifies
| Modification | Description |
|---|---|
value | Controlled selected value, shown as its option label |
onChange | Not available - use onValueChange for selection and onInputChange for text changes |
children | Not available - options are provided via the options prop |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | SelectMenuOption[] | [] | Array of options to display in dropdown |
value | string | number | None | Controlled selected value |
onValueChange | (value: string | number, option?: SelectMenuOption) => void | None | Callback when a value is selected |
onInputChange | (inputValue: string) => void | None | Callback when input text changes |
allowCustomValue | boolean | false | Allows entering values not in options list |
belowList | ReactNode | None | Content to display below the option list |
menu | MenuProps | None | Menu configuration overrides (see below) |
placeholder | string | "Type to search..." | Input placeholder text |
Excluded Props
The following Input props are not available on Autocomplete:
| Prop | Reason |
|---|---|
onChange | Replaced by onValueChange and onInputChange |
children | Not applicable - options are provided via options prop |
All other Input props are fully supported. See the Input documentation for the complete list.
SelectMenuOption
| Prop | Type | Description |
|---|---|---|
label | string | Display text for the option |
value | string | number | Value of the option |
disabled | boolean | Prevents selection of this option |
[key: string] | unknown | Additional custom properties |
Menu Configuration
The dropdown menu appearance is controlled through the menu prop, which accepts all MenuConfig options:
| Prop | Type | Default | Description |
|---|---|---|---|
menu.radius | Radius | "md"* | Corner rounding of the dropdown menu |
menu.size | Size | "md"* | Size of menu items |
menu.itemVariant | Variant | "ghost"* | Visual style of inactive options |
menu.itemColor | Color | "primary"* | Color of inactive options |
menu.activeItemVariant | Variant | "faded"* | Visual style of selected option |
menu.activeItemColor | Color | "primary"* | Color of selected option |
menu.lockScroll | boolean | false* | Whether to lock body scroll when open |
menu.portal | boolean | true* | Whether to render menu in a portal |
menu.portalTarget | HTMLElement | null | null* | Custom portal target element |
menu.className | string | None | Extra classes for the dropdown menu |
* Falls back through Global Configuration if not set. See below.
Global Configuration
Autocomplete reads defaults from four places, in this order of precedence:
- Instance prop: set directly on
<Autocomplete /> - Component config:
components.autocompletein yourashee.config - Theme default:
defaultVariant/defaultRadius/defaultColorin yourashee.config - Built-in fallback: component's internal default values
Component config
Built-in fallbacks
Accessibility
- Renders with proper ARIA roles (
combobox,listbox) - Uses
aria-expandedandaria-autocompletefor state indication - Supports keyboard navigation and selection
disableditems are not focusable or selectable- Implements
focus-visibleindicators - Uses Floating UI for robust positioning
Portal Behavior
The Autocomplete dropdown menu is rendered in a React portal by default. This means the menu is attached to document.body rather than staying in the component's DOM hierarchy.
Why use a portal?
- Escapes CSS containment: The menu appears above other content even when inside containers with
overflow: hiddenorcontain: layout - Avoids stacking context issues: The menu maintains proper z-index regardless of parent stacking contexts
- Works with any parent: The menu functions correctly regardless of where the Autocomplete is placed in the component tree
- Prevents clipping: The menu is never clipped by parent containers
When to disable the portal
You may want to disable the portal (by setting menu.portal={false}) when:
- You need the menu to stay within a specific container for testing purposes
- You are rendering inside a shadow DOM or iframe where
document.bodyis not appropriate - You have specific layout requirements that depend on the menu remaining in the DOM hierarchy
You can also provide a custom menu.portalTarget to render the menu into a specific container instead of document.body.
Notes
- Controlled Usage: Use
value/onValueChangefor controlled behavior. - Custom Values: When
allowCustomValueis enabled, ensure your application handles string values appropriately. - Filtering: Options are filtered in real-time, case-insensitive, matching against option labels.
- Performance: For large option lists (1000+ items), consider implementing virtual scrolling or server-side filtering.
- Keyboard Navigation: Up/Down arrows navigate options, Enter selects, Escape closes.
- Portal: The dropdown menu is portaled to
document.bodyby default. This can be disabled via themenu.portalprop or component config. - Menu Configuration: All menu appearance options are consolidated into the
menuprop for cleaner API surface. - Inheritance: Autocomplete inherits all Input props except
onChangeandchildren.