Skip to Content

Combobox

Autocomplete input and command palette with a list of suggestions.

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@dapplelight/signet-ui/components/combobox"

const customers = ["Acme Corp", "Globex", "Initech", "Umbrella Ltd", "Wayne Enterprises", "Stark Industries"]

export function Demo() {
  return (
    <Combobox items={customers}>
      <ComboboxInput placeholder="Select a customer" />
      <ComboboxContent>
        <ComboboxEmpty>No customers found.</ComboboxEmpty>
        <ComboboxList>
          {(item) => (
            <ComboboxItem key={item} value={item}>
              {item}
            </ComboboxItem>
          )}
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import {
  Combobox,
  ComboboxChip,
  ComboboxChips,
  ComboboxChipsInput,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
  ComboboxValue,
  useComboboxAnchor,
} from "@dapplelight/signet-ui/components/combobox"

const items = ["Acme Corp", "Globex", "Initech"]

<Combobox items={items}>
  <ComboboxInput placeholder="Search" />
  <ComboboxContent>
    <ComboboxEmpty>No results.</ComboboxEmpty>
    <ComboboxList>
      {(item) => <ComboboxItem key={item} value={item}>{item}</ComboboxItem>}
    </ComboboxList>
  </ComboboxContent>
</Combobox>

Examples

Clear button

import { Combobox, ComboboxInput } from "@dapplelight/signet-ui/components/combobox"

const customers = ["Acme Corp", "Globex", "Initech"]

<Combobox items={customers} defaultValue="Globex">
  <ComboboxInput placeholder="Select a customer" showClear />
  ...
</Combobox>

Multiple

import {
  Combobox,
  ComboboxChip,
  ComboboxChips,
  ComboboxChipsInput,
  ComboboxContent,
  ComboboxValue,
  useComboboxAnchor,
} from "@dapplelight/signet-ui/components/combobox"

const customers = ["Acme Corp", "Globex", "Initech"]
const anchor = useComboboxAnchor()

<Combobox multiple items={customers} defaultValue={["Acme Corp", "Initech"]}>
  <ComboboxChips ref={anchor}>
    <ComboboxValue>
      {(values: string[]) => (
        <>
          {values.map((value) => (
            <ComboboxChip key={value}>{value}</ComboboxChip>
          ))}
          <ComboboxChipsInput placeholder="Add customer" />
        </>
      )}
    </ComboboxValue>
  </ComboboxChips>
  <ComboboxContent anchor={anchor}>
    ...
  </ComboboxContent>
</Combobox>

Controlled

Billing: Umbrella Ltd

import * as React from "react"
import { Combobox } from "@dapplelight/signet-ui/components/combobox"

const customers = ["Acme Corp", "Globex", "Umbrella Ltd"]
const [value, setValue] = React.useState<string | null>("Umbrella Ltd")

<Combobox items={customers} value={value} onValueChange={setValue}>
  ...
</Combobox>

API Reference

Built on the Base UI combobox. Combobox is the Base UI Combobox.Root, so it takes its props.

Combobox

PropTypeDefaultDescription
itemsT[] or groups-The options. Filtering is done for you.
filternull | (item, query, itemToString?) => booleanbuilt-inCustom match; null turns filtering off (for server-side search).
inputValue / onInputValueChangestring / (value, details) => void-Control the typed text.
autoHighlightbooleanfalseHighlight the first match while typing.
valueT | T[] | null-Controlled value.
defaultValueT | T[] | null-Initial value when uncontrolled.
onValueChange(value, details) => void-Runs when the selection changes.
multiplebooleanfalseAllow several values. Value becomes an array.
open / onOpenChangeboolean / (open) => void-Control the popup.
disabled / readOnly / requiredbooleanfalseField state.
namestring-Form field name.

ComboboxInput

PropTypeDefaultDescription
showTriggerbooleantrueShow the chevron button.
showClearbooleanfalseShow a clear button.
disabledbooleanfalseDisable the input and its buttons.
classNamestring-Merged onto the input group.

Plus every Base UI combobox input prop, such as placeholder.

ComboboxContent

PropTypeDefaultDescription
sidetop | bottom | left | right | inline-start | inline-endbottomSide of the anchor.
alignstart | center | endstartAlignment on that side.
sideOffsetnumber6Gap from the anchor.
alignOffsetnumber0Shift along the alignment axis.
anchorelement or ref-Anchor to position against. Use useComboboxAnchor() with chips.

ComboboxList, ComboboxItem, ComboboxEmpty

ComboboxList takes a render function of each item. ComboboxItem takes value and shows a check when selected. ComboboxEmpty shows only when nothing matches.

ComboboxGroup, ComboboxLabel, ComboboxCollection, ComboboxSeparator

For grouped lists: a group, its label, the group's item collection and a divider.

ComboboxChips, ComboboxChip, ComboboxChipsInput

PropTypeDefaultDescription
showRemove (ComboboxChip)booleantrueShow the remove button on a chip.

ComboboxChips is the field for multiple selection, ComboboxChip one selected value and ComboboxChipsInput the typing area.

ComboboxValue, ComboboxTrigger

ComboboxValue renders the selected value, or a render function of it. ComboboxTrigger is the chevron button, for building your own field.

useComboboxAnchor

Returns a ref to place on ComboboxChips, then pass to ComboboxContent as anchor.