ComboBox

A combo box combines a text input with a listbox, allowing users to filter a list of options to items matching a query.

Theme 
 
selectionMode 
isDisabled 
Example
ComboBox.tsx
ComboBox.css
import {ComboBox, ComboBoxItem} from './ComboBox';

<ComboBox
  label="Favorite Animal"
  placeholder="Select an animal">
  <ComboBoxItem>Aardvark</ComboBoxItem>
  <ComboBoxItem>Cat</ComboBoxItem>
  <ComboBoxItem>Dog</ComboBoxItem>
  <ComboBoxItem>Kangaroo</ComboBoxItem>
  <ComboBoxItem>Panda</ComboBoxItem>
  <ComboBoxItem>Snake</ComboBoxItem>
</ComboBox>

Content

ComboBox reuses the ListBox component, following the Collection Components API. It supports ListBox features such as static and dynamic collections, sections, disabled items, links, text slots, asynchronous loading, etc. See the ListBox docs for more details.

The following example shows a dynamic collection of items, grouped into sections.

import {ComboBox, ComboBoxItem} from './ComboBox';
import {ListBoxSection, Header} from './ListBox';
import {Collection} from 'react-aria-components/Collection';

function Example() {
return ( <ComboBox label="Preferred fruit or vegetable" placeholder="Select an option" defaultItems={options}> {section => ( <ListBoxSection id={section.name}> <Header>{section.name}</Header> <Collection items={section.children}> {item => <ComboBoxItem id={item.name}>{item.name}</ComboBoxItem>} </Collection> </ListBoxSection> )} </ComboBox> ); }

TagGroup

Use the ComboBoxValue render prop function to display the selected items as a TagGroup.

No selected items
import {ComboBox, ComboBoxValue, Input} from 'react-aria-components/ComboBox';
import {ComboBoxListBox, ComboBoxItem} from './ComboBox';
import {Label, FieldButton} from './Form';
import {Popover} from './Popover';
import {Tag, TagGroup} from './TagGroup';
import {ChevronDown} from 'lucide-react';

<ComboBox selectionMode="multiple"> <Label>States</Label> <div className="combobox-field"> <Input className="react-aria-Input inset" placeholder="Select a state" />
<FieldButton><ChevronDown /></FieldButton> </div> <ComboBoxValue<typeof states[0]>> {({selectedItems, state}) => ( <TagGroup aria-label="Selected states" style={{marginTop: 8}} items={selectedItems.filter(item => item != null)} renderEmptyState={() => 'No selected items'} onRemove={(keys) => { // Remove keys from ComboBox state. if (Array.isArray(state.value)) { state.setValue(