Autocomplete

A text input with type-ahead suggestions. Supports keyboard navigation, custom values, and validation states.

Basic Example

Controlled Value

Type to filter suggestions

Pre-selected Value

React is pre-selected

With Helper Text

Start typing to see suggestions

States

Error State

Disabled State

Allow Custom Values

When allowCustomValue is true (default), users can enter values not in the suggestions list and press Enter to confirm.

Type a custom tag and press Enter

Restrict to Suggestions

Set allowCustomValue=false to only allow selecting from suggestions.

Only values from the list are allowed

Limit Suggestions

Shows max 5 suggestions

Non-Clearable

Clear button is hidden

Props

NameTypeDefaultDescription
label*string-Label text for the input
suggestions*string[]-Array of suggestion strings to display
placeholderstring'Type to search...'Placeholder text when input is empty
valuestring-Controlled value of the input
maxSuggestionsnumber10Maximum number of suggestions to display
allowCustomValuebooleantrueAllow entering values not in suggestions list
clearablebooleantrueShow clear button when input has value
disabledbooleanfalseWhether the input is disabled
errorstring-Error message to display
helperTextstring-Helper text below input
onChange(value: string) => void-Callback when input value changes
onSelect(value: string) => void-Callback when a suggestion is selected
onClear() => void-Callback when input is cleared

Keyboard Navigation

KeyAction
Arrow DownOpen suggestions / Move to next suggestion
Arrow UpMove to previous suggestion
EnterSelect highlighted suggestion / Confirm custom value
EscapeClose suggestions dropdown
TabClose dropdown and move to next element

Usage Guidelines

When to use

  • When users need to select from a long list with type-ahead filtering
  • When the list of options is dynamic or loaded from an API
  • When users might need to enter custom values not in the list
  • For tagging or labeling interfaces

Best practices

  • Provide meaningful placeholder text that hints at expected input
  • Use helper text to explain how the autocomplete works
  • Set appropriate maxSuggestions to avoid overwhelming the user
  • Consider disabling custom values when input must match specific options

Accessibility

  • Full keyboard navigation (Arrow keys, Enter, Escape)
  • ARIA combobox pattern with listbox for suggestions
  • aria-expanded indicates dropdown state
  • aria-invalid for error states
  • Error messages announced with aria-live
  • Clear button has accessible label

Do's and Don'ts

Do

  • Use for searchable lists with many options
  • Allow custom values when appropriate
  • Provide clear feedback when no results match
  • Use descriptive labels and placeholders

Don't

  • Don't use for short lists (use Select instead)
  • Don't use vague placeholder text
  • Don't show too many suggestions at once
  • Don't require exact matching without clear indication

Related Components

Resources