Combobox

Select an option from a dropdown list and search for options by typing.

A combobox allows a user to select an option from a dropdown list and search for options by typing.

Fruit
<Combobox name="fruit" label="Fruit">
  <ComboboxSearchField placeholder="Search fruit..." />
  <ComboboxListBox>
    <ComboboxItem id="apple">Apple</ComboboxItem>
    <ComboboxItem id="banana">Banana</ComboboxItem>
    <ComboboxItem id="orange">Orange</ComboboxItem>
    ...
  </ComboboxListBox>
</Combobox>

Validation

Combobox supports the same validation functions as the other form elements. See the validation documentation for more details.

<Combobox
  className="w-full"
  name="country"
  label="Country"
  validate={(value) => {
    if (!value) {
      return 'Please select a country';
    }
  }}
  isRequired
>
  <ComboboxSearchField placeholder="Search country..." />
  <ComboboxListBox>
    <ComboboxItem id="us">United States</ComboboxItem>
    <ComboboxItem id="gb">United Kingdom</ComboboxItem>
    <ComboboxItem id="ca">Canada</ComboboxItem>
    <ComboboxItem id="au">Australia</ComboboxItem>
  </ComboboxListBox>
</Combobox>
Country (Required)

Grouping options

To group options, you can use the ComboboxSection component.

Country (Required)
<Combobox>
  <ComboboxSearchField placeholder="Search country..." />
  <ComboboxListBox>
    <ComboboxSection title="Europe">
      <ComboboxItem id="at">Austria</ComboboxItem>
      <ComboboxItem id="de">Germany</ComboboxItem>
      <ComboboxItem id="fr">France</ComboboxItem>
    </ComboboxSection>
    <ComboboxSection title="Asia">
      <ComboboxItem id="cn">China</ComboboxItem>
      <ComboboxItem id="jp">Japan</ComboboxItem>
      <ComboboxItem id="in">India</ComboboxItem>
    </ComboboxSection>
  </ComboboxListBox>
</Combobox>

Other props

description

A description can be added to the combobox to provide additional information to the user.

FruitSelect the fruit for your account
<Combobox
  name="fruit"
  label="Fruit"
  description="Select the fruit for your account"
>
  <ComboboxItem id="apple">Apple</ComboboxItem>
  <ComboboxItem id="banana">Banana</ComboboxItem>
  <ComboboxItem id="orange">Orange</ComboboxItem>
</Combobox>

icon

You can set an icon

Fruit
<Combobox name="fruit" label="Fruit" icon={<RiAppleLine size={18} />}>
  <ComboboxItem id="apple">Apple</ComboboxItem>
  <ComboboxItem id="banana">Banana</ComboboxItem>
  <ComboboxItem id="orange">Orange</ComboboxItem>
</Combobox>

isRequired

A combobox can be marked as required by setting the isRequired prop to true.

Fruit (Required)
<Combobox name="fruit" label="Fruit" isRequired>
  <ComboboxSearchField placeholder="Search fruit..." />
  <ComboboxListBox>
    <ComboboxItem id="apple">Apple</ComboboxItem>
    <ComboboxItem id="banana">Banana</ComboboxItem>
    <ComboboxItem id="orange">Orange</ComboboxItem>
  </ComboboxListBox>
</Combobox>

isInvalid

When rendered inside a form, the combobox will automatically enter an invalid state and display the field error message defined by the validation function. However, it is also possible to manually set the invalid state by setting the isInvalid prop to true and passing an errorMessage prop.

Fruit
<Combobox name="fruit" label="Fruit" isInvalid>
  <ComboboxSearchField placeholder="Search fruit..." />
  <ComboboxListBox>
    <ComboboxItem id="apple">Apple</ComboboxItem>
    <ComboboxItem id="banana">Banana</ComboboxItem>
    <ComboboxItem id="orange">Orange</ComboboxItem>
  </ComboboxListBox>
</Combobox>

Props

<Combobox />

Here are the props for the Combobox component that are also used on the Select. For more details check the documentation.

PropTypeDescription
labelReactNodeThe label of the combobox.
descriptionReactNodeThe description of the combobox.
errorMessagestringThe error message to display when the combobox is invalid.
placeholderstringThe text to display when no option is selected.
isRequiredbooleanWhether the combobox is required.
isInvalidbooleanWhether the combobox is invalid.
isDisabledbooleanWhether the combobox is disabled.
validate(value: Key) => string | undefinedThe validation function to use for the combobox.
defaultSelectedKeystringThe id of the item selected by default.
selectedKeystringThe id of the currently selected item (controlled).
onSelectionChange(key: Key) => voidHandler called when the selected item changes.
namestringThe name of the combobox submitted with form data.
itemsIterable<T>Item objects to render dynamically using a render function.
childrenReactNode | ((item: T) => ReactNode)The combobox items, or a render function for dynamic items.

Additional props on the Comobobox that target the Aria-Autocomplete can be passed as comboboxProps to further customize the behaviour of the Combobox.

PropTypeDescription
filterfunctionThe filtering behaviour. Default: contains from react-aria-components that returns whether a string contains a given substring.
disableVirtualFocusbooleanDisable virtual focus.
disableAutoFocusFirstbooleanDisable auto focusing the first item in the collection after a filter is performed.
inputValue (controlled)stringThe value of the input field (controlled). When this prop is set, the input value will not be updated automatically when an item is selected.
defaultInputValue(uncontrolled)stringThe default value of the input field.
onInputChange(value: string) => voidThe handler that is called when the input value changes.

<ComboboxItem />

PropTypeDescription
idstringThe value submitted with the form for this option.
childrenReactNodeThe display label for this option.
textValuestringA plain text label used for typeahead search.

<ComboboxSection />

PropTypeDescription
titlestringThe heading label for the section.
itemsIterable<T>Items to render dynamically.
childrenReactNodeThe ComboboxItem elements to group.

<ComboboxSearchField />

PropTypeDescription
placeholderstringThe text to display when the input is empty.
autoFocusbooleanWhether the input should be automatically focused. (Default: true)
descriptionReactNodeThe description of the searchfield.

<ComboboxListBox />

The ListBox is a react-aria-component and supports all props from react-aria.