Skip to content
Klarhimmel UI

Combobox

npx shadcn add @klarhimmel/combobox @klarhimmel/input

Examples

  • Basic

  • States

  • Long

DetailsAbout, usage, props and more

A text field that filters a list as you type and picks one option.

When to use

  • Use for

    Long lists people can name: countries, staff, products. They type, the list narrows.

  • Not for

    Fewer than seven options. Use Select. Free text with suggestions. Use Input.

  • Pairs with

    Field, forms.

Preview

Start typing to narrow the list.

Nothing chosen yet.

combobox.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Combobox } from '@/components/klarhimmel/ui/combobox';
import { Field } from '@/components/klarhimmel/ui/input';

export default function Example() {
  return (
    <Theme theme="brand">
      <Field label="Country">
        {(p) => (
          <Combobox
            {...p}
            options={[
              { value: 'dk', label: 'Denmark' },
              { value: 'fi', label: 'Finland' },
              { value: 'no', label: 'Norway' },
              { value: 'se', label: 'Sweden' },
            ]}
            placeholder="Search countries"
          />
        )}
      </Field>
    </Theme>
  );
}

Import

Import

import { Combobox } from '@/components/klarhimmel/ui/combobox';
Files
combobox.tsx, input.tsx, in components/klarhimmel/ui/. With it: button, editing, select, theme, utils. npm: lucide-react.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
optionsSelectOption[]requiredRequired. Matching is case-insensitive and anywhere in the label.
valuestring-Controlled or uncontrolled state. An empty string means nothing chosen.
defaultValuestring-Controlled or uncontrolled state. An empty string means nothing chosen.
onValueChange(value: string) => void-Controlled or uncontrolled state. An empty string means nothing chosen.
placeholderstring-Placeholder; the message when nothing matches.
emptyTextstring'No matches'Shown when the typed text matches nothing.
namestring-Submits the chosen value with a form (a hidden input).
idstring-
disabledboolean-Error styling; switches it off.
invalidboolean-Error styling; switches it off.
aria-labelstring-
aria-labelledbystring-
aria-describedbystring-
classNamestring-Extra classes, merged after the component's own.

Accessibility

KeyDoes
TypeOpens the list and filters it; the first match is highlighted
Down / UpOpens the list, or moves the highlight
EnterChooses the highlighted option
EscapeCloses and restores the chosen text; again, clears the field
Home / End / Left / RightMove the caret in the text, as in any field
TabLeaves the field; unmatched text is replaced by the chosen label

The WAI-ARIA combobox with list autocomplete. The number of matches is announced as you type.

Accessibility