DitherCharts

Combobox

Updated

Combobox is a searchable select: type to filter its dithered listbox (in the field, or in the popup with a button trigger), arrows move the active option, and Enter or a click picks it. Leaving the field puts back the chosen label, so the value is always an option. Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

FranceJapan

Pick a region with data

import "@/components/dithercharts/controls.css"
import { Combobox } from "@/components/dithercharts/combobox"

<Combobox
  label="Country"
  placeholder="Search countries…"
  options={[
    { value: "ar", label: "Argentina" },
    { value: "au", label: "Australia" },
    { value: "br", label: "Brazil" },
    // …
  ]}
/>
// The search box moves into the popup, under a select-style button.
<Combobox label="Market" trigger="button" options={countries} />
// Several at once, as chips; the value is an array.
<Combobox label="Compare" multiple defaultValue={["fr", "jp"]} options={countries} />

Install

Controls install with DitherCharts Pro. See Installation to log in, then import controls.css once, e.g. in your root layout.

npx dithercharts add combobox

Props

It renders a native element, so every other attribute that element takes passes through.

Combobox props
PropTypeDefaultDescription
labelrequiredType ReactNodeDefault –The caption above the field, and its accessible name.
optionsrequiredType readonly ComboboxOption[]Default –
multipleType booleanDefault falseLets several options be chosen, shown as chips in the field; the value becomes an array.
valueType string | readonly string[]Default –The chosen value (an array when multiple), for a controlled combobox; pair it with onValueChange.
defaultValueType string | readonly string[]Default –The value chosen at first (an array when multiple), for an uncontrolled combobox.
onValueChangeType ((value: string) => void) | ((value: string[]) => void)Default –Called with the chosen value, or "" when cleared; with multiple, the chosen values in option order.
triggerType "input" | "button"Default –"input" (the default) types into the field itself. "button" shows the chosen label on a select-style button and puts the search box at the top of the popup. Not with multiple.
placeholderType stringDefault "Search…", or "Select…" with a button triggerShown while nothing is chosen.
nameType stringDefault –The form field name; a hidden input carries the value.
disabledType booleanDefault false
collisionPaddingType { top?: number; bottom?: number }Default 8 eachSpace in px the popup keeps clear at the window's top and bottom, e.g. a sticky header's height. It opens on the side with more room and shrinks to fit.
classNameType stringDefault –
hintType ReactNodeDefault –Help text under the field, read after its label.
errorType ReactNodeDefault –An error under the field; it also marks the field invalid.