CraftUI

Combobox

A select you can type into, for lists too long to scroll.

Starting biome

Installation

npx shadcn@latest add @runqora/craft-combobox

Usage

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxLabel,
  ComboboxList,
} from "@/components/craft/combobox";

const biomes = ["Badlands", "Desert", "Jungle"];

<Combobox items={biomes}>
  <ComboboxLabel>Biome</ComboboxLabel>
  <ComboboxInput placeholder="Search biomes" />
  <ComboboxContent>
    <ComboboxEmpty>No biomes match.</ComboboxEmpty>
    <ComboboxList>
      {(biome: string) => (
        <ComboboxItem key={biome} value={biome}>
          {biome}
        </ComboboxItem>
      )}
    </ComboboxList>
  </ComboboxContent>
</Combobox>;

Props

ComboboxInput

Prop

Type

Accessibility

  • The input is a combobox that controls a listbox, so screen readers announce the highlighted option as you move.
  • Down Arrow opens the list. The arrow keys move through the matches, Enter chooses and Escape closes.
  • The button beside the input shows every option. It's left out of the tab order, as the input does the same from the keyboard.

Customization

ComboboxList takes a function as its child, so a combobox goes in a client component.

Combobox filters items as you type. Pass filter to match differently, or filteredItems to filter yourself, for instance on a server.

Dependencies

Source

On this page