Skip to content
All components
Forms

Combobox

Search and choose one or several values from a known list, in a popup with a filter input.

A searchable select, composed from Popover and Command.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add combobox

Then import it from @/components/ui/combobox. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Single selection

Choose one framework from a short searchable list while the parent owns the value. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Combobox } from "@/components/ui/combobox"

const frameworks = [
  { value: "next", label: "Next.js" },
  { value: "remix", label: "Remix" },
  { value: "astro", label: "Astro" },
  { value: "nuxt", label: "Nuxt" },
  { value: "sveltekit", label: "SvelteKit" },
]

export function ComboboxSingleSelection() {
  
  const [value, setValue] = React.useState("next")
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <div className="flex">
        <Combobox
          aria-label="Framework"
          options={frameworks}
          value={value}
          onValueChange={setValue}
          placeholder="Pick a framework"
          searchPlaceholder="Search frameworks..."
          className="w-64"
        />
      </div>
    </div>
  )
}

Country field

Search a longer list inside a field with a visible label, hint and form name. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Combobox } from "@/components/ui/combobox"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

const countries = [
  { value: "AR", label: "Argentina" },
  { value: "AU", label: "Australia" },
  { value: "BR", label: "Brazil" },
  { value: "CA", label: "Canada" },
  { value: "CL", label: "Chile" },
  { value: "DE", label: "Germany" },
  { value: "ES", label: "Spain" },
  { value: "FR", label: "France" },
  { value: "IN", label: "India" },
  { value: "JP", label: "Japan" },
  { value: "MX", label: "Mexico" },
  { value: "GB", label: "United Kingdom" },
  { value: "US", label: "United States" },
]

export function ComboboxCountryField() {
  const id = React.useId()
  const [value, setValue] = React.useState("next")
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-country`}>Country</FieldLabel>
        <Combobox
          id={`${id}-country`}
          name="country"
          options={countries}
          placeholder="Select a country"
          searchPlaceholder="Search countries..."
          emptyMessage="No country matches that name."
          aria-describedby={`${id}-country-hint`}
        />
        <FieldDescription id={`${id}-country-hint`}>
          Type to filter the list, then press Enter to choose.
        </FieldDescription>
      </Field>
    </div>
  )
}

Multiple selection

multiple keeps the popup open while toggling values and reports an array. Disabled options are skipped and cannot be chosen.

"use client"

import * as React from "react"

import { Combobox } from "@/components/ui/combobox"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

const labels = [
  { value: "bug", label: "Bug" },
  { value: "docs", label: "Documentation" },
  { value: "design", label: "Design" },
  { value: "performance", label: "Performance" },
  { value: "security", label: "Security" },
]

export function ComboboxMultipleSelection() {
  const id = React.useId()
  const [value, setValue] = React.useState("next")
  const [issueLabels, setIssueLabels] = React.useState<string[]>(["bug"])

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-labels`}>Labels</FieldLabel>
        <Combobox
          id={`${id}-labels`}
          multiple
          name="labels"
          options={labels}
          value={issueLabels}
          onValueChange={setIssueLabels}
          placeholder="Add labels"
          searchPlaceholder="Search labels..."
          aria-describedby={`${id}-labels-hint`}
        />
        <FieldDescription id={`${id}-labels-hint`}>
          Choose all that apply. {issueLabels.length} selected.
        </FieldDescription>
      </Field>
    </div>
  )
}

Invalid

Associate combobox validation feedback with its trigger. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Combobox } from "@/components/ui/combobox"
import { Field, FieldError, FieldLabel } from "@/components/ui/field"

export function ComboboxInvalid() {
  const id = React.useId()
  const [value, setValue] = React.useState("next")
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-zone`}>Time zone</FieldLabel>
        <Combobox
          id={`${id}-zone`}
          options={[
            { value: "utc", label: "Coordinated Universal Time (UTC)" },
            { value: "cet", label: "Central European Time (CET)" },
            { value: "est", label: "Eastern Time (ET)" },
          ]}
          placeholder="Select a time zone"
          searchPlaceholder="Search time zones..."
          aria-invalid
          aria-describedby={`${id}-zone-error`}
        />
        <FieldError id={`${id}-zone-error`}>
          Choose a time zone so reminders arrive at the right hour.
        </FieldError>
      </Field>
    </div>
  )
}

Disabled option

Keep an unavailable option visible but unselectable and explain why in the hint. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Combobox } from "@/components/ui/combobox"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

const owners = [
  { value: "ana", label: "Ana Torres" },
  { value: "kai", label: "Kai Nakamura" },
  { value: "lee", label: "Lee Morgan" },
  { value: "sam", label: "Sam Okafor (on leave)", disabled: true },
]

export function ComboboxDisabledOption() {
  const id = React.useId()
  const [value, setValue] = React.useState("next")
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-owner`}>Owner</FieldLabel>
        <Combobox
          id={`${id}-owner`}
          options={owners}
          defaultValue="ana"
          placeholder="Select an owner"
          searchPlaceholder="Search people..."
          aria-describedby={`${id}-owner-hint`}
        />
        <FieldDescription id={`${id}-owner-hint`}>
          People on leave are listed but cannot be assigned.
        </FieldDescription>
      </Field>
    </div>
  )
}

Disabled

Inspect the unavailable control using its real disabled semantics. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Combobox } from "@/components/ui/combobox"
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

export function ComboboxDisabled() {
  const id = React.useId()
  const [value, setValue] = React.useState("next")
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-repo`}>Repository</FieldLabel>
        <Combobox
          id={`${id}-repo`}
          options={[{ value: "web", label: "web-app" }]}
          defaultValue="web"
          disabled
          aria-describedby={`${id}-repo-hint`}
        />
        <FieldDescription id={`${id}-repo-hint`}>
          The repository cannot change after the first deploy.
        </FieldDescription>
      </Field>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Combobox

Not a primitive: a composition of Popover and Command. It lives in the registry anyway because every project rebuilds this pairing, and rebuilding it is where the keyboard handling usually goes wrong. The trigger takes its accessible name from an associated label (Label htmlFor, FieldLabel or aria-labelledby) or an explicit aria-label; it never invents one from the selection or placeholder.

Combobox props
PropTypeDefaultDescription
intent"primary" | "neutral" | "error" | null | undefined—Semantic purpose: primary action, neutral action, or destructive/error action. Independent of visual emphasis. Defaults to primary.
emphasis"link" | "filled" | "stroke" | "lighter" | "ghost" | null | undefined—Visual weight: filled, stroke, lighter, ghost, or link (text only, underlined on hover). Does not change the action's semantics; use asChild with an anchor when it navigates. Defaults to filled.
size"xs" | "sm" | "md" | "lg" | null | undefined—Control size: xs, sm, md, or lg. Keep labels and icons readable when choosing a size. Defaults to md.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
namestring | undefined—Form field name. Renders hidden inputs with the selected value(s) so native form submission includes them.
options(required)ComboboxOption[]—Available choices, each with a unique value and a readable label. Labels are used for search and visible selection.
placeholderstring | undefined—Text shown when nothing is selected. It is not a replacement for an accessible label.
searchPlaceholderstring | undefined—Prompt and accessible name for the search input inside the popup.
emptyMessagestring | undefined—Message displayed when filtering finds no matching options.
multipleboolean | undefined—Select one value (default). Select several values. The popup stays open while toggling options.
valuestring | string[] | undefined—Controlled option value. Selecting the current option clears it and reports an empty string. Controlled selected values.
defaultValuestring | string[] | undefined—Initial uncontrolled value. Initial uncontrolled values.
onValueChange((value: string) => void) | ((value: string[]) => void) | undefined—Called with the next option value, or an empty string when the current choice is cleared. Called with the next selected values after an option is toggled.
Inherited props (12)
Combobox inherited props
PropTypeDefaultDescription
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.

Accessibility & usage

From registry/ui/combobox.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Lists too long to scan, such as countries, time zones, people or repositories.
  • Choosing several values from a known list with multiple.
  • Cases where people know part of the name and want to type it.

When not to use

  • Short lists (under about 10 options); a select or radio group is faster.
  • Free text that is not limited to the options; this combobox only selects from the list.
  • Commands and actions; use a command palette.

Anatomy

Combobox
One component that renders the trigger, popup, search input and options from the options prop. Takes value or defaultValue (string, or string[] with multiple), onValueChange, placeholder, searchPlaceholder, emptyMessage and name.
Trigger
A Button with role=combobox and aria-expanded showing the selected labels or the placeholder. Accepts id, disabled, aria-describedby and aria-invalid.
Popup
A Popover as wide as the trigger, named after the associated label, containing a Command list.
Search input
Filters options by their visible label, never by the raw value; its placeholder is also its accessible name.
Option
Each option shows a check when selected and exposes it as aria-checked; disabled options stay visible and are skipped.
Hidden inputs
With name, one hidden input per selected value for native form submission.

Keyboard & interaction

  • Enter, Space or a click on the trigger opens the popup with focus in the search input.
  • Typing filters the list; Arrow Up and Down move the highlight; Enter selects the highlighted option.
  • Single mode closes the popup after a choice and returns focus to the trigger; multiple mode stays open while toggling options.
  • Escape or a click outside closes the popup and returns focus to the trigger.
  • When nothing matches, the empty message is shown; disabled options cannot be chosen.

Responsive behavior

  • The trigger is full width; the popup matches its width, so give the trigger enough room on narrow screens.
  • The selected labels are joined with commas on one truncated line; for several values, show a count or the selected items near the field.
  • On phones the popup and the on-screen keyboard share the screen; keep the list short enough to show a few options above the keyboard.

Content guidelines

  • Label names the value ('Country'); placeholder prompts ('Select a country'); searchPlaceholder names what is searched ('Search countries...').
  • emptyMessage tells people what to try next ('No country matches that name').
  • Hint explains multiple selection or limits ('Choose all that apply').
  • Option labels are unique and recognizable without context; add a qualifier for duplicates ('Springfield, IL').

Alternatives

  • Select — A short fixed list without search.
  • Native select — Long familiar lists on phones with the platform picker.
  • Command — Choosing an action rather than a field value.
  • Radio group — A few options shown at once.

Resources