Skip to content

Forms

Combobox

tsx
"use client";
import { Combobox, Field } from "@cherry-design-system/react";

export function Framework() {
  return (
    <Field label="Framework">
      <Combobox options={["Next.js", "Remix", "Astro"]} placeholder="Select a framework" />
    </Field>
  );
}

A text input with a filterable listbox, following the ARIA combobox pattern. The list is a native popover placed with CSS anchor positioning. Use it for long lists such as countries or frameworks. Use Select for a short, fixed list.

Examples

Value and label objects

Plain strings are both value and label. Pass { value, label, disabled } objects to separate them or disable an option.

tsx
"use client";
import { useState } from "react";
import { Combobox, Field, type ComboboxOption } from "@cherry-design-system/react";

const countries: ComboboxOption[] = [
  { value: "al", label: "Albania" },
  { value: "de", label: "Germany" },
  { value: "it", label: "Italy", disabled: true },
];

export function Country() {
  const [country, setCountry] = useState<string | null>(null);
  return (
    <Field label="Country">
      <Combobox
        options={countries}
        value={country}
        onValueChange={setCountry}
        placeholder="Search countries"
      />
    </Field>
  );
}

Empty state

tsx
"use client";
import { Combobox, Field } from "@cherry-design-system/react";

export function Language() {
  return (
    <Field label="Language">
      <Combobox
        options={["English", "German", "Albanian"]}
        emptyMessage="No languages found"
        emptyHint="Try another spelling."
      />
    </Field>
  );
}

Custom filter

The default matcher is a case-insensitive "contains". Pass filter to change it.

tsx
"use client";
import { Combobox, Field } from "@cherry-design-system/react";

export function StartsWith() {
  return (
    <Field label="City">
      <Combobox
        options={["Berlin", "Bern", "Tirana"]}
        filter={(option, query) => option.label.toLowerCase().startsWith(query.toLowerCase())}
      />
    </Field>
  );
}

Translated labels

tsx
"use client";
import { Combobox, Field } from "@cherry-design-system/react";

export function Marco() {
  return (
    <Field label="Marco">
      <Combobox
        options={["Next.js", "Remix", "Astro"]}
        emptyMessage="Sin resultados"
        toggleLabel="Mostrar opciones"
        resultsLabel={(count) => (count === 1 ? "1 resultado" : `${count} resultados`)}
      />
    </Field>
  );
}

Properties

optionsReadonlyArray<ComboboxOption | string>required

The choices; plain strings are both value and label. ComboboxOption is { value: string; label: string; disabled?: boolean }.

valuestring | null

Controlled selected value (null means none).

defaultValuestring | null

Initial value when uncontrolled.

onValueChange(value: string | null) => void

Called when the selected value changes.

onInputChange(text: string) => void

Called with the typed text on every keystroke.

filter(option: ComboboxOption, query: string) => boolean

Custom matcher. Defaults to a case-insensitive "contains".

size"sm" | "md" | "lg"

Control size. Defaults to "md".

invalidboolean

Error state; set automatically inside a <Field error>.

emptyMessageReactNode

Shown when nothing matches. Defaults to "No results found".

emptyHintReactNode

Second line under emptyMessage.

resultsLabel(count: number) => string

Live-region text for the match count (translate here). Defaults to "1 result" / "{count} results".

toggleLabelstring

Name of the chevron button. Defaults to "Show options".

wrapperClassNamestring

Class for the outer wrapper (className goes to the <input>).

The ref and native <input> attributes (except value, defaultValue, onChange, type and list) go to the <input>.

Styling

Root class cherry-combobox with data-size (sm, md, lg) and states data-open, data-invalid, data-disabled. Options use data-active, aria-selected and aria-disabled. Parts: cherry-combobox__input, __trigger, __popover, __listbox, __option, __option-label, __check, __empty, __empty-title, __empty-hint.

Reads the field tokens plus --cherry-bg-elevated, --cherry-elevation-lg and --cherry-ghost-hover for the list.

Accessibility

Combobox and listbox pattern: Up and Down highlight options through aria-activedescendant, Enter selects, Escape closes. The match count is announced through a live region (resultsLabel). Label it with Field.