Combobox

React Combobox components combine a text input with a listbox, allowing users to filter options and select a value from a list. They are often used for search-driven selection, large sets of options, and other layouts where users need to filter through data to find their choice.

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli add combobox

Anatomy

Import the component and pass the required props.

import {
  Combobox,
  ComboboxInput,
  ComboboxInputWrapper,
  ComboboxItem,
  ComboboxList,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxTrigger
} from "@/registry/core/combobox/combobox";

export default function ComboboxExample() {
  return (
    <Combobox>
      <ComboboxInputWrapper>
        <ComboboxInput placeholder="Select fruit" />
        <ComboboxTrigger />
      </ComboboxInputWrapper>
      <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 to providing additional context for the selection.

Choose the language you use most often.

Sections

Group related items together using ComboboxSection and ComboboxHeader.

Multi Selection

The MultiCombobox component allows users to select multiple options, which are displayed as tags.

apple

Controlled

Manage the selection state externally using the value and onChange props.

Selected: 2 items

applebanana

Validation

Mark the combobox as required and display error messages using ComboboxErrorMessage.

Please select a framework to continue.

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.

esc

API Reference

Combobox

The root component that manages the selection state and coordinates between the input and the listbox.

PropTypeDefaultDescription
valueKey-The currently selected key (controlled).
defaultValueKey-The initial selected key (uncontrolled).
onChange(key: Key) => void-Handler that is called when the selection changes.
allowsEmptyCollectionbooleantrueWhether the combobox allows an empty collection.
labelstring-The label for the combobox (convenience prop).
descriptionstring-The description for the combobox (convenience prop).
errorMessagestring | ((validation: any) => string)-The error message for the combobox (convenience prop).
itemsIterable<T>-The items to display in the combobox.
isDisabledboolean-Whether the combobox is disabled.
isInvalidboolean-Whether the combobox is in an invalid state.
isRequiredboolean-Whether the combobox is required.
classNamestring-Additional CSS classes to apply to the combobox container.

ComboboxInputWrapper

The wrapper for the input field and trigger button, providing consistent styling.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the input wrapper element.

ComboboxInput

The text input field where users type to filter options.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the input field.

ComboboxTrigger

The button that toggles the visibility of the listbox.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the trigger button.

ComboboxContent

The popover container that holds the listbox of options.

PropTypeDefaultDescription
isNonModalbooleanfalseWhether the popover should be non-modal (doesn't block interaction).
placementPlacement-The placement of the popover relative to the trigger.
offsetnumber-The distance between the trigger and the popover.
crossOffsetnumber-The distance along the trigger's edge.
childrenReactNode-The content to be rendered within the popover.
classNamestring-Additional CSS classes to apply to the popover content.

ComboboxList

The listbox component that renders the collection of items.

PropTypeDefaultDescription
renderEmptyState() => Node-A function that returns the content to display when the collection is empty.
classNamestring-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.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the empty message.

ComboboxItem

An individual option within the listbox.

PropTypeDefaultDescription
idstring | number-The unique identifier for the item.
textValuestring-A text representation of the item's content, used for keyboard navigation and accessibility.
isDisabledboolean-Whether the item is disabled.
classNamestring-Additional CSS classes to apply to the item.

ComboboxSection

A container for grouping related items within the listbox.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the section container.

ComboboxHeader

The header for a group of items within a section.

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the header.

MultiCombobox

A specialized combobox for selecting multiple values.

PropTypeDefaultDescription
valueKey[]-The currently selected keys (controlled).
defaultValueKey[]-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.

MultiComboboxDisplay

Renders the selected items as tags above or below the combobox.

PropTypeDefaultDescription
renderTag(key: Key) => Node-Custom tag renderer.
classNamestring-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 Navigation: Supports arrow keys to navigate options, Enter/Space to select, and Escape to close.
  • Filtering: Type to filter the list of options dynamically.
  • Screen Readers: Follows W3C ARIA ComboBox design pattern with proper descriptions and state announcements.
  • Focus Management: Maintains focus within the input while navigating the listbox.