Back to Shark UI

Combobox

docs/components/combobox

latest10.4 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Combobox

Copy Markdown

Displays a searchable list of options.

DocsAPI

PreviewCode

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/combobox

Anatomy#

Combobox
  ├── ComboboxInput
  └── ComboboxContent
      ├── ComboboxEmpty
      └── ComboboxList
        └── ComboboxGroup
          ├── ComboboxGroupLabel
          └── ComboboxItem

Usage#

import { useFilter, useListCollection } from "@ark-ui/react";
import {
  Combobox,
  ComboboxContent,
  ComboboxGroup,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@/components/ui/combobox";
const { contains } = useFilter({ sensitivity: "base" });
const { collection, filter } = useListCollection({
  initialItems: [
    { label: "Apple", value: "apple" },
    { label: "Banana", value: "banana" },
  ],
  filter: contains,
});

<Combobox
  collection={collection}
  onInputValueChange={({ inputValue }) => filter(inputValue)}
>
  <ComboboxInput placeholder="Select an option" />
  <ComboboxContent>
    <ComboboxList>
      {items.map((item) => (
        <ComboboxItem item={item} key={item.value}>
          {item.label}
        </ComboboxItem>
      ))}
    </ComboboxList>
  </ComboboxContent>
</Combobox>

Controlled#

Control the selected value with inputValue and onValueChange props.

PreviewCode

Selected: banana

Size#

Small#

PreviewCode

Medium#

PreviewCode

Large#

PreviewCode

States#

Invalid#

PreviewCode

Disabled#

PreviewCode

Examples#

Auto highlight#

Automatically highlight the first matching item as the user types.

PreviewCode

Group#

PreviewCode

With Field#

Use Combobox with Field components to style the combobox with the field components.

PreviewCode

Country

We'll use this for shipping estimates

Scrollable#

PreviewCode

Multiple#

Enable multiple selection by setting the multiple prop to Combobox.

PreviewCode

With clear button#

Pass showClear to ComboboxInput to show a clear button.

PreviewCode

With start icon#

PreviewCode

API Reference#

Combobox#

Root component.

PropTypeDefault
collectionListCollection<T>required
value`stringstring[]`
defaultValue`stringstring[]`
onValueChange(details: ValueChangeDetails<T>) => void-
onInputValueChange(details: InputValueChangeDetails) => void-
multiplebooleanfalse
disabledboolean-
openOnClickbooleantrue
lazyMountbooleantrue
unmountOnExitbooleantrue
classNamestring-

ComboboxControl#

Optional wrapper for custom layouts.

PropTypeDefault
classNamestring-
asChildboolean-

ComboboxInput#

Input with dropdown trigger and optional clear button. Combines search and selection.

PropTypeDefault
size`"sm""md"
showTriggerbooleantrue
showClearbooleanfalse
disabledboolean-
classNamestring-

ComboboxTrigger#

Opens the dropdown on click.

PropTypeDefault
classNamestring-
asChildboolean-

ComboboxClear#

Button to clear the input value.

PropTypeDefault
asChildboolean-

ComboboxContent#

Holds the dropdown options. Displayed in a portal.

PropTypeDefault
classNamestring-
asChildboolean-

ComboboxList#

Wraps the list of options. Use with collection.

PropTypeDefault
classNamestring-
asChildboolean-

ComboboxItem#

A single selectable option.

PropTypeDefault
itemTrequired
classNamestring-
asChildboolean-

ComboboxGroup#

Groups related options under an optional heading.

PropTypeDefault
heading`stringReactNode`
classNamestring-
asChildboolean-

ComboboxGroupLabel#

Label for an option group.

PropTypeDefault
classNamestring-
asChildboolean-

ComboboxEmpty#

Shown when no options match the current filter. Use for empty state.

PropTypeDefault
classNamestring-
childrenReactNodeNo results found.

For a complete list of props, see the Ark UI documentation.

[

Previous page

Color Picker ](/docs/components/color-picker)[

Next page

Command ](/docs/components/command)

On This Page

InstallationAnatomyUsageControlledSizeSmallMediumLargeStatesInvalidDisabledExamplesAuto highlightGroupWith FieldScrollableMultipleWith clear buttonWith start iconAPI ReferenceComboboxComboboxControlComboboxInputComboboxTriggerComboboxClearComboboxContentComboboxListComboboxItemComboboxGroupComboboxGroupLabelComboboxEmpty