Logobaseui-cn

Combobox

An input combined with a listbox for selecting from a list of options.

Newformoverlayinteractive
Loading preview...

Installation

npx baseui-cn add combobox

Usage

import {
  Combobox,
  ComboboxInput,
  ComboboxContent,
  ComboboxList,
  ComboboxItem,
  ComboboxEmpty,
} from "@/components/ui/combobox"
<Combobox>
  <ComboboxInput placeholder="Select framework..." showTrigger />
  <ComboboxContent>
    <ComboboxList>
      <ComboboxItem value="next">Next.js</ComboboxItem>
      <ComboboxItem value="remix">Remix</ComboboxItem>
      <ComboboxEmpty>No results.</ComboboxEmpty>
    </ComboboxList>
  </ComboboxContent>
</Combobox>

Examples

Basic

A single-value selector with a flat filtered list, trigger, and clear button.

Loading preview...

With trigger button

Use ComboboxTrigger with a custom Button as the anchor. The search input lives inside the popup with autoFocus={false} to prevent scroll-jank on open.

Loading preview...

Multi-select with chips

Manage multiple selections as dismissible chips using ComboboxChips, ComboboxChip, and ComboboxValue.

Loading preview...

Chips with overflow

When many items are selected, show only the first few chips and collapse the rest behind a +N more toggle. Click to expand, click Show less to collapse.

Loading preview...

Async

Debounce input changes and load matching options on each keystroke. Shows a live result count while the request is in flight.

Loading preview...

API

Combobox

Root component — a thin alias for ComboboxPrimitive.Root.

PropTypeDefaultDescription
itemsT[]Full list of items to render
multiplebooleanfalseEnables multi-select mode
valuestring | string[]Controlled selected value(s)
defaultValuestring | string[]Uncontrolled initial value
inputValuestringControlled text in the search input
onValueChange(value) => voidFires when the selection changes
onInputValueChange(value) => voidFires when the input text changes
disabledbooleanfalseDisables the entire combobox

ComboboxInput

PropTypeDefaultDescription
showTriggerbooleantrueShow the chevron trigger button at the trailing edge
showClearbooleanfalseShow an X clear button when the input has a value
autoFocusbooleantrueFocus the input when the popup opens. Set to false when the input lives inside the popup (e.g. trigger-button pattern) to prevent scroll-jank
startAddonReact.ReactNodeContent rendered at the leading edge (e.g. <SearchIcon />)
disabledbooleanfalseDisables the input and its buttons

ComboboxTrigger

PropTypeDefaultDescription
showIconbooleantrueRender the built-in chevron icon
iconReact.ReactNode<ChevronDownIcon />Custom icon to render when showIcon is true
renderReact.ReactElementCustom element to render as the trigger (e.g. <Button variant="outline" />)

ComboboxItem

PropTypeDefaultDescription
valueTThe item value
disabledbooleanfalsePrevents selection
checkPosition"right" | "left""right"Position of the selected-state checkmark indicator

ComboboxContent

PropTypeDefaultDescription
side"top" | "bottom" | "left" | "right""bottom"Which side of the anchor the popup opens toward
sideOffsetnumber6Gap in px between anchor and popup
align"start" | "center" | "end""start"Alignment relative to the anchor
alignOffsetnumber0Offset in px along the alignment axis
anchorReact.RefObjectExplicit anchor ref for pinning popup width (required for chips pattern)

ComboboxChips

PropTypeDefaultDescription
startAddonReact.ReactNodeIcon or content at the leading edge of the chips container

ComboboxChip

PropTypeDefaultDescription
removePropsComboboxChipRemove.PropsProps forwarded to the inner remove button

useComboboxAnchor

Returns a RefObject<HTMLDivElement> to pass as anchor to ComboboxContent. Use this when the combobox has a chips input or a custom trigger button so the popup width is pinned to a stable outer wrapper instead of the dynamic chips container.

const anchor = useComboboxAnchor()

<div ref={anchor}>
  <Combobox multiple ...>
    ...
    <ComboboxContent anchor={anchor}>...</ComboboxContent>
  </Combobox>
</div>

useComboboxFilter

Re-export of ComboboxPrimitive.useFilter. Returns a contains function for client-side filtering.

API Reference

See the Base UI Combobox documentation for the full API reference, including all props, data attributes, and CSS classes.