Form Combobox

GitHub

Combobox connected to Form context with server validation errors.

Installation

bash
pnpm dlx shadcn@latest add @cs/form-combobox

Usage

tsx
import { FormCombobox } from "@/components/cs/form-combobox"
tsx
<FormCombobox name="country" />

API Reference

FormCombobox

Combobox connected to Form context with server validation errors and pending-state handling.

Props

NameTypeDefaultDescription
align"center" | "end" | "start" | undefined-Horizontal alignment of the options popover.
classNamestring | undefined-Additional classes applied to the field wrapper and trigger button.
comboboxClassNamestring | undefined-Additional classes applied to the popup search input.
defaultValueTValue | TValue[] | undefined-Initial selected value for uncontrolled usage. Initial selected values for uncontrolled usage.
disabledboolean | undefined-Prevents selection and text input.
errorstring | null | undefined-Validation error message for the field.
fetchOptionsany-Remote option endpoint configuration.
idstring | undefined-DOM id assigned to the combobox input.
labelReactNode-Label displayed above the combobox.
multipleboolean | undefined-Enables multi-selection.
name *string-Form field name used for submission and validation errors.
onNumber((value: number | null) => void) | ((value: number[]) => void) | undefined-Called when a numeric option is selected or cleared. Called when numeric options are selected.
onString((value: string | null) => void) | ((value: string[]) => void) | undefined-Called when a string option is selected or cleared. Called when string options are selected.
optionsComboboxOption<TValue>[] | undefined-Static options displayed in the menu.
requiredboolean | undefined-Requires a value before the form can submit.
searchOnlyboolean | undefined-Shows search results without retaining a selected value.
titlestring | undefined-Accessible title for the combobox input.
translations *{ empty?: string; placeholder: string; nothingFound: string; optionsKey?: string; }-Text used for the empty selection, input placeholder, and empty result state.
valueTValue | TValue[] | undefined-Controlled selected value. Controlled selected values.