Dinachi

Combobox

A combobox that combines text input with a selectable popup list of options.

View Source

#Installation

npx @dinachi/cli@latest add combobox

#Usage

tsx
import {
  Combobox,
  ComboboxInputGroup,
  ComboboxInput,
  ComboboxTrigger,
  ComboboxClear,
  ComboboxLabel,
  ComboboxContent,
  ComboboxList,
  ComboboxItem,
  ComboboxGroup,
  ComboboxGroupLabel,
  ComboboxEmpty,
  ComboboxStatus,
  ComboboxSeparator,
  createComboboxItems,
} from "@/components/ui/combobox"

#Examples

#Selecting by ID

createComboboxItems derives each item's value and label from your objects, so value and onValueChange use IDs while the list still receives the full object. Create the collection at module scope, or memoize it for runtime data:

tsx
const userItems = React.useMemo(
  () => createComboboxItems(users, { getValue: (user) => user.id, getLabel: (user) => user.name }),
  [users]
)

#API Reference

#Combobox (Root)

PropTypeDefaultDescription
itemsT[] | GroupedItems[] | ItemCollection—The items to display. Can be a flat array, an array of groups (objects with value and items properties), or a collection from createComboboxItems. Required for filtering to work.
openOnInputClickbooleanfalseWhether the popup opens when clicking the input.
valueany—The controlled selected value.
defaultValueany—The uncontrolled initial selected value.
onValueChange(value: any, eventDetails) => void—Callback fired when the selected value changes.
onInputValueChange(value: string, eventDetails) => void—Callback fired when the input text changes.
onOpenChange(open: boolean, eventDetails) => void—Callback fired when the popup is opened or closed.
multiplebooleanfalseWhether multiple items can be selected.
disabledbooleanfalseWhether the component should ignore user interaction.

#ComboboxItem

PropTypeDefaultDescription
valueany—The value of the item. Required.
insetbooleanfalseAdds extra left padding for grouped or nested option content.

#ComboboxGroup

PropTypeDefaultDescription
itemsany[]—Items to be rendered within this group. Child Collection components will use these items.

#Other Parts

PropTypeDefaultDescription
ComboboxContent.portalbooleantrueWhether to render in a portal. Set to false inside Dialog or Drawer.
ComboboxTrigger.childrenReact.ReactNode—Optional trigger content. Defaults to a chevron icon.
ComboboxClear.childrenReact.ReactNode—Optional clear action content. Defaults to an X icon.