GitHub

Combobox

Searchable selection input that combines free-form filtering with a structured list of options for large or descriptive datasets.

AccessibleDark ModeKeyboard NavAnimated

Install

$npx react-principles add combobox
expand_more

Search and select a frontend stack.

Selected value: next

02

Code Snippet

src/ui/Combobox.tsx
import { Combobox } from "@/ui/Combobox";

<Combobox
  options={frameworks}
  value={framework}
  onValueChange={setFramework}
  label="Framework"
  description="Search and select a frontend stack."
/>
03

Copy-Paste (Single File)

Combobox.tsx
import { useEffect, useMemo, useRef, useState } from "react";
import { cn } from "@/lib/utils";

export interface ComboboxOption {
  label: string;
  value: string;
  description?: string;
  disabled?: boolean;
}

export interface ComboboxProps {
  options: ComboboxOption[];
  value?: string;
  defaultValue?: string;
  onValueChange?: (value: string) => void;
  placeholder?: string;
  emptyText?: string;
  label?: string;
  description?: string;
  className?: string;
}
04

Props

PropTypeDefaultDescription
optionsComboboxOption[]Available options shown in the floating results list.
valuestringControlled selected option value.
defaultValuestringInitial selected option value when uncontrolled.
onValueChange(value: string) => voidCalled when users pick a result.
placeholderstring"Search..."Input placeholder text before search begins.
emptyTextstring"No results"Fallback message when filtering returns no matches.
labelstringOptional field label shown above the input.
descriptionstringHelper text displayed below the combobox.
classNamestringAdditional classes applied to the root wrapper.
react-principles