Combobox
The React Combobox component combines an input field with a dropdown list, allowing users to search and select an option. It lets users type to filter results and quickly find what they need.
It is useful when you have a large list of options. For example, users can search for a country, user, or category instead of scrolling through a long list. It also supports selecting multiple options with MultiCombobox, with selected items displayed as tags.
Built with React Aria Components ComboBox and styled using Tailwind CSS. It supports filtering, keyboard navigation, and accessible selection patterns.
Installation
Install the component using the Tailgrids CLI.
npx @tailgrids/cli@latest add comboboxAnatomy
Import the component and pass the required props.
import {
Combobox,
ComboboxInput,
ComboboxItem,
ComboboxList,
ComboboxContent,
ComboboxEmpty,
ComboboxTrigger
} from "@/components/tailgrids/combobox";
export default function ComboboxExample() {
return (
<Combobox aria-label="Fruit">
<ComboboxInput placeholder="Select fruit">
<ComboboxTrigger />
</ComboboxInput>
<ComboboxContent>
<ComboboxList>
<ComboboxItem id="apple">Apple</ComboboxItem>
<ComboboxItem id="banana">Banana</ComboboxItem>
</ComboboxList>
<ComboboxEmpty>No results found</ComboboxEmpty>
</ComboboxContent>
</Combobox>
);
}Examples
With Label and Description
Add a label and description with FieldLabel and FieldDescription from the field component.
Sections
Group related items together using ComboboxGroup and ComboboxLabel.
Multi Selection
The MultiCombobox component allows users to select multiple options, which are displayed as tags.
Controlled
Manage the selection state externally using the value and onChange props.
Selected: 2 items
Validation
Mark the combobox as required and display error messages using FieldError from the field component.
Disabled
Disable the entire component or individual items to prevent user interaction.
With Avatars
Display items with avatars and secondary text for a more informative selection experience.
With Icons
Use icons to visually represent categories or types within the combobox.
Custom Tag Rendering
The MultiCombobox component can be customized to render selection tags with different styles.
Command Palette
A minimalist, search-focused design that can be used as a command palette with keyboard shortcut hints.
API Reference
Combobox
The root component that manages the selection state and coordinates between the input and the listbox.
| Prop | Type | Default | Description |
|---|---|---|---|
value | Key | - | The currently selected key (controlled). |
defaultValue | Key | - | The initial selected key (uncontrolled). |
onChange | (key: Key) => void | - | Handler that is called when the selection changes. |
allowsEmptyCollection | boolean | true | Whether the combobox allows an empty collection. |
items | Iterable<T> | - | The items to display in the combobox. |
isDisabled | boolean | - | Whether the combobox is disabled. |
isInvalid | boolean | - | Whether the combobox is in an invalid state. |
isRequired | boolean | - | Whether the combobox is required. |
className | string | - | Additional CSS classes to apply to the combobox container. |
ComboboxInput
Renders the input group: the text field where users type to filter options. Render ComboboxTrigger as its child to add the toggle button.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Elements shown at the end of the group, such as ComboboxTrigger. |
className | string | - | Additional CSS classes to apply to the input field. |
ComboboxTrigger
The button that toggles the visibility of the listbox.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes to apply to the trigger button. |
ComboboxContent
The popover container that holds the listbox of options.
| Prop | Type | Default | Description |
|---|---|---|---|
isNonModal | boolean | false | Whether the popover should be non-modal (doesn't block interaction). |
placement | Placement | - | The placement of the popover relative to the trigger. |
offset | number | - | The distance between the trigger and the popover. |
crossOffset | number | - | The distance along the trigger's edge. |
children | ReactNode | - | The content to be rendered within the popover. |
className | string | - | Additional CSS classes to apply to the popover content. |
ComboboxList
The listbox component that renders the collection of items.
| Prop | Type | Default | Description |
|---|---|---|---|
renderEmptyState | () => Node | - | A function that returns the content to display when the collection is empty. |
className | string | - | Additional CSS classes to apply to the list content. |
ComboboxEmpty
A convenience component to display a message when no results are found. Should be placed inside ComboboxContent.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes to apply to the empty message. |
ComboboxItem
An individual option within the listbox.
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | number | - | The unique identifier for the item. |
textValue | string | - | A text representation of the item's content, used for keyboard navigation and accessibility. |
isDisabled | boolean | - | Whether the item is disabled. |
className | string | - | Additional CSS classes to apply to the item. |
ComboboxGroup
A container for grouping related items within the listbox.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes to apply to the section container. |
ComboboxLabel
The heading for a group of items.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes to apply to the header. |
ComboboxValue
Renders the currently selected value(s) from React Aria ComboBoxValue.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((props: ComboBoxValueRenderProps<T>) => ReactNode) | - | Custom render function or fallback content. |
ComboboxSeparator
Visual divider between groups or items. Extends React Aria Separator props.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes to apply to the separator. |
ComboboxCollection
Re-export of React Aria Collection for rendering dynamic item lists inside ComboboxList or ComboboxGroup.
ComboboxChips
Multi-select input container that wraps selected chips and ComboboxChipsInput. Extends React Aria Group props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | ComboboxChipList and ComboboxChipsInput. |
className | string | - | Additional CSS classes to apply to the container. |
ComboboxChipList
Renders the list of selected items inside ComboboxChips. Extends React Aria ComboBoxValue props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | ((props: ComboBoxValueRenderProps<T>) => ReactNode) | - | Render function or elements for each selected chip. |
ComboboxChip
An individual removable chip/tag representing a selected item. Extends React Aria Tag props.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Label content rendered inside the chip. |
className | string | - | Additional CSS classes to apply to the chip. |
ComboboxChipsInput
Text input placed inside ComboboxChips for filtering options in multi-select mode. Extends React Aria Input props.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes to apply to the input. |
MultiCombobox
A specialized combobox for selecting multiple values. Accepts all Combobox props except selectionMode (fixed to 'multiple'), with array-based value, defaultValue, and onChange.
| Prop | Type | Default | Description |
|---|---|---|---|
value | Key[] | - | The currently selected keys (controlled). |
defaultValue | Key[] | - | The initial selected keys (uncontrolled). |
onChange | (keys: Key[]) => void | - | Handler that is called when the selection changes. |
onSelectionChange | (key: Key | null) => void | - | Handler called when an individual item is selected. |
items | Iterable<T> | - | The items to display in the combobox. |
allowsEmptyCollection | boolean | true | Whether the combobox allows an empty collection. |
isDisabled | boolean | - | Whether the combobox is disabled. |
isInvalid | boolean | - | Whether the combobox is in an invalid state. |
isRequired | boolean | - | Whether the combobox is required. |
className | string | - | Additional CSS classes to apply to the container. |
MultiComboboxDisplay
Renders the selected items as removable tags above or below MultiCombobox. Extends HTMLAttributes<HTMLDivElement>.
| Prop | Type | Default | Description |
|---|---|---|---|
renderTag | (key: Key) => Node | - | Custom tag renderer. |
className | string | - | Additional CSS classes to apply to the tags container. |
The Key type supports string and number. See React Aria's Combobox for more details.
Accessibility
- Keyboard support: Users can navigate options using
Arrowkeys, select an option withEnter, and close the list withEscape. - Search and filtering: As users type in the input, the list updates to show matching results.
- Focus management: Focus stays on the input while users navigate the list.
- Selection behavior: Supports single and multiple selection depending on configuration.
- Label and description: Provide a label and optional description so users understand the purpose of the input.
