Combobox

A text field with a list of suggestions that narrows as you type, to pick one or several from.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items: string[] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-2">
    <Label htmlFor="combobox-preview">Label</Label>
    <Combobox defaultValue="Item 1" items={items}>
      <ComboboxInput id="combobox-preview" placeholder="Placeholder" />
      <ComboboxContent>
        <ComboboxEmpty />
        <ComboboxList>
          {(item: string) => (
            <ComboboxItem key={item} value={item}>
              {item}
            </ComboboxItem>
          )}
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  </div>
);

export default Example;

Usage

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
const items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"];

export const ExampleCombobox = () => (
  <Combobox items={items}>
    <ComboboxInput placeholder="Placeholder" />
    <ComboboxContent>
      <ComboboxEmpty />
      <ComboboxList>
        {(item) => (
          <ComboboxItem key={item} value={item}>
            {item}
          </ComboboxItem>
        )}
      </ComboboxList>
    </ComboboxContent>
  </Combobox>
);

Examples

Appearances

appearance paints the field on the kit's one scale: solid, the default, soft on the grey wash, outline with only its line, and transparent with neither until it is hovered.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
  type ComboboxAppearance,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3"];

const variants: { appearance: ComboboxAppearance; label: string }[] = [
  { appearance: "solid", label: "Solid" },
  { appearance: "soft", label: "Soft" },
  { appearance: "outline", label: "Outline" },
  { appearance: "transparent", label: "Transparent" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col gap-2" key={variant.appearance}>
        <Label htmlFor={`combobox-appearance-${variant.appearance}`}>
          {variant.label}
        </Label>
        <Combobox items={items}>
          <ComboboxInput
            id={`combobox-appearance-${variant.appearance}`}
            placeholder="Placeholder"
            appearance={variant.appearance}
          />
          <ComboboxContent>
            <ComboboxEmpty />
            <ComboboxList>
              {(item: string) => (
                <ComboboxItem key={item} value={item}>
                  {item}
                </ComboboxItem>
              )}
            </ComboboxList>
          </ComboboxContent>
        </Combobox>
      </div>
    ))}
  </div>
);

export default Example;

Sizes

size sets its height, on ComboboxInput and on ComboboxChips alike: sm 32px, base 40px (the default) or lg 48px, a Button's height at the same size, the large one written at 16px on a phone.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import type { InputSize } from "@produkto/ui/Input";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3"];

const variants: { size: InputSize; label: string }[] = [
  { size: "sm", label: "Small" },
  { size: "base", label: "Base" },
  { size: "lg", label: "Large" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col gap-2" key={variant.size}>
        <Label htmlFor={`combobox-size-${variant.size}`}>{variant.label}</Label>
        <Combobox items={items}>
          <ComboboxInput
            id={`combobox-size-${variant.size}`}
            placeholder="Placeholder"
            size={variant.size}
          />
          <ComboboxContent>
            <ComboboxEmpty />
            <ComboboxList>
              {(item: string) => (
                <ComboboxItem key={item} value={item}>
                  {item}
                </ComboboxItem>
              )}
            </ComboboxList>
          </ComboboxContent>
        </Combobox>
      </div>
    ))}
  </div>
);

export default Example;

Border radius

borderRadius sets its corners on the kit's one scale: none, xs 4px, sm 6px, base 8px (the default), lg 12px, xl 16px, or full to round it.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import type { InputBorderRadius } from "@produkto/ui/Input";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3"];

const variants: { borderRadius: InputBorderRadius; label: string }[] = [
  { borderRadius: "none", label: "None" },
  { borderRadius: "xs", label: "xs" },
  { borderRadius: "sm", label: "sm" },
  { borderRadius: "base", label: "base" },
  { borderRadius: "lg", label: "lg" },
  { borderRadius: "xl", label: "xl" },
  { borderRadius: "full", label: "full" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col gap-2" key={variant.borderRadius}>
        <Label htmlFor={`combobox-radius-${variant.borderRadius}`}>
          {variant.label}
        </Label>
        <Combobox items={items}>
          <ComboboxInput
            id={`combobox-radius-${variant.borderRadius}`}
            placeholder="Placeholder"
            borderRadius={variant.borderRadius}
          />
          <ComboboxContent>
            <ComboboxEmpty />
            <ComboboxList>
              {(item: string) => (
                <ComboboxItem key={item} value={item}>
                  {item}
                </ComboboxItem>
              )}
            </ComboboxList>
          </ComboboxContent>
        </Combobox>
      </div>
    ))}
  </div>
);

export default Example;

With icon

start and end on ComboboxInput set an Icon inside the field, before the text or after it, and the list still opens under the whole field.

import { Search01Icon, Tick02Icon } from "@hugeicons/core-free-icons";
import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import { Icon } from "@produkto/ui/Icon";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-icon-start">Label</Label>
      <Combobox items={items}>
        <ComboboxInput
          id="combobox-icon-start"
          placeholder="Placeholder"
          start={<Icon icon={Search01Icon} />}
        />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-icon-end">Label</Label>
      <Combobox items={items}>
        <ComboboxInput
          end={<Icon icon={Tick02Icon} />}
          id="combobox-icon-end"
          placeholder="Placeholder"
        />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
  </div>
);

export default Example;

Multiple

multiple picks several items, each a ComboboxChip in ComboboxChips with its own remove button, keeps the list open while picking, and Backspace takes out the last; by default a combobox picks one.

Item 1Item 2
import {
  Combobox,
  ComboboxChip,
  ComboboxChips,
  ComboboxChipsInput,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
  ComboboxValue,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-single">Label</Label>
      <Combobox defaultValue={items[0]} items={items}>
        <ComboboxInput id="combobox-single" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-multiple">Label</Label>
      <Combobox defaultValue={[items[0], items[1]]} items={items} multiple>
        <ComboboxChips>
          <ComboboxValue>
            {(values: string[]) => (
              <>
                {values.map((value) => (
                  <ComboboxChip key={value}>{value}</ComboboxChip>
                ))}
                <ComboboxChipsInput id="combobox-multiple" />
              </>
            )}
          </ComboboxValue>
        </ComboboxChips>
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
  </div>
);

export default Example;

Groups

Grouped items fill ComboboxGroups under a ComboboxLabel, drawn by ComboboxCollection, with a ComboboxSeparator between; a group with no match hides.

import {
  Combobox,
  ComboboxCollection,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxGroup,
  ComboboxInput,
  ComboboxItem,
  ComboboxLabel,
  ComboboxList,
  ComboboxSeparator,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

interface Group {
  value: string;
  items: string[];
}

const groups: Group[] = [
  { value: "Group 1", items: ["Item 1", "Item 2", "Item 3"] },
  { value: "Group 2", items: ["Item 4", "Item 5", "Item 6"] },
  { value: "Group 3", items: ["Item 7", "Item 8", "Item 9"] },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-2">
    <Label htmlFor="combobox-groups">Label</Label>
    <Combobox items={groups}>
      <ComboboxInput id="combobox-groups" placeholder="Placeholder" />
      <ComboboxContent>
        <ComboboxEmpty />
        <ComboboxList>
          {(group: Group, index: number) => (
            <ComboboxGroup items={group.items} key={group.value}>
              <ComboboxLabel>{group.value}</ComboboxLabel>
              <ComboboxCollection>
                {(item: string) => (
                  <ComboboxItem key={item} value={item}>
                    {item}
                  </ComboboxItem>
                )}
              </ComboboxCollection>
              {index < groups.length - 1 ? <ComboboxSeparator /> : null}
            </ComboboxGroup>
          )}
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  </div>
);

export default Example;

Trigger

ComboboxTrigger opens the list from a button drawn as the field, with ComboboxValue writing the pick on it, and a ComboboxInput inside ComboboxContent searches the list.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
  ComboboxTrigger,
  ComboboxValue,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-2">
    <Label htmlFor="combobox-trigger">Label</Label>
    <Combobox items={items}>
      <ComboboxTrigger id="combobox-trigger">
        <ComboboxValue placeholder="Placeholder" />
      </ComboboxTrigger>
      <ComboboxContent>
        <ComboboxInput placeholder="Placeholder" />
        <ComboboxEmpty />
        <ComboboxList>
          {(item: string) => (
            <ComboboxItem key={item} value={item}>
              {item}
            </ComboboxItem>
          )}
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  </div>
);

export default Example;

Filter

By default the list keeps the items that hold the typed text; filter takes a function of your own instead, or null to keep every item, for a list a server has already searched.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-filter">Label</Label>
      <Combobox items={items}>
        <ComboboxInput id="combobox-filter" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-filter-null">Label</Label>
      <Combobox filter={null} items={items}>
        <ComboboxInput id="combobox-filter-null" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
  </div>
);

export default Example;

Auto highlight

autoHighlight highlights the first match as you type, so Enter picks it; by default nothing is highlighted until an arrow key moves to it.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-highlight-off">Label</Label>
      <Combobox items={items}>
        <ComboboxInput id="combobox-highlight-off" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-highlight">Label</Label>
      <Combobox autoHighlight items={items}>
        <ComboboxInput id="combobox-highlight" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
  </div>
);

export default Example;

Clearable

clearable on ComboboxInput swaps the arrow for an X while something is picked, which empties the field and gives it the focus back; by default a field has none.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-clearable-off">Label</Label>
      <Combobox defaultValue={items[0]} items={items}>
        <ComboboxInput id="combobox-clearable-off" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-clearable">Label</Label>
      <Combobox defaultValue={items[0]} items={items}>
        <ComboboxInput
          clearable
          id="combobox-clearable"
          placeholder="Placeholder"
        />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
  </div>
);

export default Example;

Disabled

disabled on the Combobox, or on its ComboboxInput, dims the field and keeps its list shut, beside one as it is by default.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-enabled">Label</Label>
      <Combobox defaultValue={items[0]} items={items}>
        <ComboboxInput id="combobox-enabled" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-disabled">Label</Label>
      <Combobox defaultValue={items[0]} disabled items={items}>
        <ComboboxInput id="combobox-disabled" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
  </div>
);

export default Example;

Invalid

error writes what is wrong under the field, turns its border to the destructive colour and describes it to screen readers, beside one without an error.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@produkto/ui/Combobox";
import { Label } from "@produkto/ui/Label";

const items = ["Item 1", "Item 2", "Item 3"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-valid">Label</Label>
      <Combobox items={items}>
        <ComboboxInput id="combobox-valid" placeholder="Placeholder" />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="combobox-error">Label</Label>
      <Combobox items={items}>
        <ComboboxInput
          error="Description"
          id="combobox-error"
          placeholder="Placeholder"
        />
        <ComboboxContent>
          <ComboboxEmpty />
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
  </div>
);

export default Example;

API Reference

Combobox

ComboboxProps<Item, Multiple> · components/Combobox/Combobox.types.ts
PropTypeDefault
itemsreadonly (Item | ComboboxItemGroup<Item>)[]-
itemToStringValue(item: NoInfer<Item>) => string-
filter((item: NoInfer<Item>, query: string) => boolean) | null-
multipleMultiple-
valueComboboxSelection<Item, Multiple>-
defaultValueComboboxSelection<Item, Multiple>-
onValueChange(value: ComboboxSelection<NoInfer<Item>, Multiple>) => void-
autoHighlightboolean-
openboolean-
defaultOpenboolean-
onOpenChange(open: boolean) => void-
inputValuestring-
defaultInputValuestring-
onInputValueChange(value: string) => void-
disabledboolean-
namestring-
formstring-
requiredboolean-
childrenReactNode-

ComboboxTrigger

ComboboxTriggerProps · also takes the props of <button>
PropTypeDefault
asChildbooleanfalse
appearanceComboboxAppearance"solid" | "soft" | "outline" | "transparent""solid"
sizeInputSize"sm" | "base" | "lg""base"
borderRadiusInputBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl" | "full""base"

ComboboxValue

ComboboxValueProps
PropTypeDefault
childrenReactNode | { render(value: unknown): ReactNode }["render"]-
placeholderReactNode-

ComboboxInput

ComboboxInputProps · also takes the props of <input>
PropTypeDefault
showTriggerboolean-
clearableboolean-
loadingbooleanfalse
appearanceComboboxAppearance"solid" | "soft" | "outline" | "transparent"-
borderRadiusInputBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl" | "full"-
sizeInputSize"sm" | "base" | "lg"-
startReactNode-
endReactNode-
errorReactNode-

ComboboxContent

ComboboxContentProps · also takes the props of PopoverContent
PropTypeDefault
sideOffsetnumber6

ComboboxList

ComboboxListProps · also takes the props of <div>
PropTypeDefault
childrenReactNode | ComboboxRender-

ComboboxItem

ComboboxItemProps · also takes the props of <div>
PropTypeDefault
valuerequiredunknown-
disabledbooleanfalse

ComboboxGroup

ComboboxGroupProps · also takes the props of <div>
PropTypeDefault
itemsreadonly unknown[]-

ComboboxLabel

ComboboxLabelProps · takes the props of <div>

ComboboxCollection

ComboboxCollectionProps
PropTypeDefault
childrenrequiredComboboxRender-

ComboboxEmpty

ComboboxEmptyProps · takes the props of <div>

ComboboxSeparator

ComboboxSeparatorProps · takes the props of <div>

ComboboxChips

ComboboxChipsProps · also takes the props of <div>
PropTypeDefault
appearanceComboboxAppearance"solid" | "soft" | "outline" | "transparent"-
sizeInputSize"sm" | "base" | "lg"-
borderRadiusInputBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl" | "full"-
showTriggerbooleantrue
errorReactNode-

ComboboxChip

ComboboxChipProps · also takes the props of <span>
PropTypeDefault
valueunknown-
showRemovebooleantrue

ComboboxChipsInput

ComboboxChipsInputProps · takes the props of <input>

ComboboxItemGroup

used by items
PropTypeDefault
valueunknown-
itemsrequiredreadonly Item[]-