Skip to content

Router that virtually distributes inference across connected devices in the home.

Go
47.9 KB
Raw Blame

Combobox

A Combobox combines a text input and listbox to let users filter and pick from declarative items.

Examples

Basic Combobox

<Flex direction="col" gap="2">
    <Combobox
        aria-label="Fruit"
        items={['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']}
        placeholder="Search fruits..."
    />
    <Combobox
        aria-label="Fruit"
        defaultValue={['Apple', 'Banana']}
        multiple
        items={['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']}
        placeholder="Search fruits..."
    />
</Flex>

With Default Value Combobox

<Combobox aria-label="Fruit" items={['Apple', 'Banana', 'Cherry']} defaultValue="Banana" />

Multiple Combobox

Use when users need to select multiple values with type-ahead filtering. By default, the selected values are rendered as tags in the trigger.

<Combobox
    aria-label="Colors"
    items={['Red', 'Green', 'Blue', 'Yellow']}
    multiple
    placeholder="Pick colors..."
/>

Multiple Combobox With Default Values

<Combobox
    aria-label="Colors"
    items={['Red', 'Green', 'Blue', 'Yellow']}
    multiple
    defaultValue={['Red', 'Green']}
    placeholder="Pick colors..."
/>

Combobox With Separate Item Values

<Combobox
    aria-label="Colors"
    items={[
        { value: 'red', children: 'Red (value: red)' },
        { value: 'green', children: 'Green (value: green)' },
        { value: 'blue', children: 'Blue (value: blue)' },
        { value: 'yellow', children: 'Yellow (value: yellow)' }
    ]}
    multiple
    defaultValue={['red', 'green']}
    placeholder="Pick colors..."
/>

Combobox With Rich Item Children

When setting rich children in items, you should also provide a filterValue which is a text only representation of children that will be used for type-ahead filtering.

<Combobox
    aria-label="Colors"
    items={[
        {
            value: 'red',
            filterValue: 'Red',
            children: (
                <Flex align="center" gap="density-md">
                    <CircleFill /> Red
                </Flex>
            )
        }
    ]}
    placeholder="Pick colors..."
/>

Multiple Count Mode Combobox

Use count mode when many selections are expected and individual tags would overflow the trigger.

<Combobox
    aria-label="Tags"
    items={VERY_LONG_LIST}
    multiple
    multipleMode="count"
    placeholder="Select frameworks..."
/>

Grouped Items Combobox

Use when options logically belong to categories that help users scan the list.

<Combobox
    aria-label="Team member"
    items={[
        { slotHeading: 'Engineering', items: ['Ada', 'Grace'] },
        { slotHeading: 'Design', items: ['Charles', 'Dorothy'] }
    ]}
    placeholder="Search team..."
/>

Custom Empty State Combobox

<Combobox aria-label="Fruit" items={[]} emptyStateMessage="No fruits found" />

Dismissible Combobox

Use when users need a quick way to clear their selection.

<Combobox
    aria-label="Fruit"
    items={['Apple', 'Banana', 'Cherry']}
    dismissible
    defaultValue="Apple"
/>

Disabled Combobox

Use when the selection is locked by external conditions.

<Combobox aria-label="Fruit" items={['Apple', 'Banana']} disabled defaultValue="Apple" />

With Slot Start And End Combobox

<Combobox
    aria-label="Fruit"
    items={['Apple', 'Banana']}
    slotStart={<SomeIcon />}
    slotEnd={<SomeIcon />}
/>

With Async Loading Combobox

<Combobox
    aria-label="Fruit"
    items={VERY_LONG_LIST}
    onScrollToBottom={() => {
        console.log('Loading more items...')
    }}
/>

Composed

Use the composed primitives when you need full control over trigger rendering, content layout, or custom items.

<ComboboxRoot defaultValue="Apple">
    <ComboboxTrigger placeholder="Pick a fruit..." />
    <ComboboxContent>
        <ComboboxItem value="Apple">Apple</ComboboxItem>
        <ComboboxItem value="Banana">Banana</ComboboxItem>
        <ComboboxItem value="Cherry">Cherry</ComboboxItem>
    </ComboboxContent>
</ComboboxRoot>

Props

Prop Type Default Description
items * string | ({ children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string }) | ({ items: string | ({ children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string })[]; children: never; kind: "section"; filterValue: never; slotHeading: ReactNode })[] - The items to render in the Combobox.
allowBackspaceRemoval boolean - In multi-select mode, pressing Backspace while the input is empty removes the last selected value. When omitted, the default is derived from the selected-values display: enabled when ComboboxSelectedTags is mounted in the default mode="tags" with no custom renderer (so each selected value has a visible, clearly labelled tag the shortcut targets), and disabled otherwise (mode="count", custom renderer, or no selected-values display at all). Pass an explicit boolean to override the derived default.
children (props: { mode: "count" | "tags"; removeSelectedValue: (value: string) => void; selectedItems: { label: string; value: string; }[]; summaryLabel: string }) => ReactNode - Optional custom renderer for the selected values. When provided, ComboboxRoot treats the display as custom and disables allowBackspaceRemoval by default.
className string -
defaultInputValue string - The input value when the Combobox is initially rendered.
defaultOpen boolean - The open state of the Combobox when it is initially rendered.
defaultValue string | string[] - The selected value when the Combobox is initially rendered.
density "compact" | "standard" | "spacious" "standard" The "density" of the component. This affects the padding/spacing of the component and its children. By default, the component will inherit density from its parent, which is usually standard. - Setting to null or undefined will allow the component to inherit density from its parent. - Setting to compact will reduce the padding/spacing of the component and its children. - Setting to standard will use the standard padding/spacing of the component and its children. - Setting to spacious will increase the padding/spacing of the component and its children.
disabled boolean - Disables the Combobox.
dismissible boolean - When true, renders a dismiss button that clears the Combobox.
emptyStateMessage string "No results found" The message to display when no results are found.
filteringBehavior "after-input" | "on-open" "after-input" Controls when the option list begins filtering. - "after-input" shows all options when the popover opens, then filters after the user types. - "on-open" filters immediately using the current input value.
filterMatchFn (matchTerm: string, value: string) => boolean - Overrides the default substring matching used to filter items.
formatSummaryLabel (count: number) => string - Optional formatter for the count summary label used when mode="count" and by render-prop consumers.
hideOnEscape boolean true Whether the Combobox should close when the escape key is pressed.
id string - The id used for the input element.
inputValue string - Controlled input value.
kind "flat" | "floating" "flat" The kind of input to render. - "flat" - renders with a border and background - "floating" - renders borderless with no background
multiple boolean false Enables single-select mode.
multipleMode "count" | "tags" "tags" Controls how selected values are rendered in multi-select mode. Forwarded to ComboboxSelectedTags as its mode prop. - "tags" renders each selection as an individual, clearly labelled tag. - "count" renders a compact summary of how many values are selected. The choice also drives the default for allowBackspaceRemoval: the shortcut is enabled by default only when "tags" is used with no custom renderValue/children.
name string - The form field name used by the hidden native <select>.
onInputValueChange (value: string) => void - Callback fired when the input text changes.
onOpenChange (open: boolean) => void - Callback fired when the popover opens or closes.
onScrollToBottom () => void - Callback fired when the listbox scrolls to the bottom. Useful for async loading scenarios.
onValueChange ((value: string) => void) | ((value: string[]) => void) - Callback fired when the selected value changes.
open boolean - Controlled open state.
placeholder string - Placeholder text shown before a value is selected or typed. Pass null to explicitly show no placeholder.
readOnly boolean - Prevents the value from being changed while preserving form submission.
renderValue (value: string | string[], setValue: ((nextValue: string | string[]) => void) | ((nextValueFunc: (prevValue: string | string[]) => string | string[]) => void)) => ReactNode - Controls the value rendered when a multi-select Combobox is closed.
required boolean - Whether the field is required.
resetValueOnBlur boolean false Restores the input text to the selected option label on blur, or clears unmatched text when nothing is selected.
selectRef ((instance: HTMLSelectElement) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; })) | React.RefObject<HTMLSelectElement> - Callback ref for the hidden native <select> used for form submission.
side "right" | "bottom" | "left" | "top" "bottom" Side used for the popover positioning.
size "small" | "medium" | "large" "medium" Visual size of the Combobox trigger.
slotEnd ReactNode - Content rendered after the input.
slotStart ReactNode - Content rendered before the input.
status "error" | "success" - The status of the input. Use withValidation to automatically apply success/error states based on :user-valid and :user-invalid pseudo classes.
style React.CSSProperties -
value string | string[] - Controlled selected value.

* = required prop