Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Combobox for Vue UI SDK

A text field that filters a long list as people type, with chips for several picks, grouped options and an empty state. For Vue apps using UI SDK.

On this page9 sections

A combobox is a text field with a list under it: type a few letters, the list narrows to the options that match, and the arrow keys or the pointer pick one. Reach for it when the list is too long to scan, such as countries, time zones or the people on a team.

For a handful of fixed options, a Select is quicker. When any typed text is a valid answer and the list only suggests, use an Autocomplete.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Combobox anatomy: control, input, trigger, content, item, item indicator

Usage

<script setup lang="ts">
import { computed, unref } from "vue"
import { useFilter, useListCollection } from "@/lib/list-collection"
import {
  Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem,
  ComboboxList,
} from "@/components/ui/combobox"

const frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"];

const filterApi = useFilter({ sensitivity: "base" })

const { collection, filter } = useListCollection<(typeof frameworks)[number]>(computed(() => ({
  filter: unref(filterApi).contains,
  initialItems: frameworks,
})))

const handleInputValueChange = (inputValue: string) => {
  filter(inputValue);
}
</script>

<template>
  <Combobox :collection="collection" @input-value-change="handleInputValueChange">
    <ComboboxInput aria-label="Framework" placeholder="Select a framework" />
    <ComboboxContent>
      <ComboboxEmpty>No items found.</ComboboxEmpty>
      <ComboboxList>
        <ComboboxItem v-for="item in collection.items" :item="item" :key="item">
          {{ item }}
        </ComboboxItem>
      </ComboboxList>
    </ComboboxContent>
  </Combobox>
</template>

Accessibility

The input has role="combobox" and reports aria-expanded, and focus stays in it while the arrow keys move a highlight through the list, which it reports with aria-activedescendant. Naming the field is up to you: give ComboboxInput an aria-label, as most demos here do, use ComboboxLabel, which UI SDK ties to the input, or put the combobox in a Field, whose label is tied to the input for you. UI SDK warns in development when the input has no name.

Arrow Down
When the list is closed, opens it on the first option. When it's open, moves the highlight to the next option, and from the last one back to the first.
Arrow Up
When the list is closed, opens it on the last option. When it's open, moves the highlight to the previous option, and from the first one to the last.
Page Down
When the list is open, moves the highlight down by ten options.
Page Up
When the list is open, moves the highlight up by ten options.
Enter
Selects the highlighted option and, in a single combobox, closes the list. With nothing highlighted, selects the option whose label matches the typed text exactly.
Escape
Closes the list and puts back the text of the current selection.
Tab
When the list is open, closes it, and focus moves on.
Home
Moves the text cursor to the start of the input.
End
Moves the text cursor to the end of the input.
Backspace
In a multiple combobox, removes the last chip when the input is empty, or the chip that has focus.
Arrow Left
In a multiple combobox, with the cursor at the start of the input, moves focus to the last chip, and from there between chips. In a right-to-left layout, ArrowRight does this.

Demos

Basic

Five front-end frameworks in a text field. Type "nu" and only Nuxt.js is left. Type a word that matches none of them and ComboboxEmpty says "No items found." This is the same setup as the preview at the top of the page: one choice from a flat list, and the starting point for every demo below.

Preview width

Multiple

Next.js starts as a chip, every framework you pick joins it, and the text field sits at the end of the row. ComboboxValue hands the picked values to the row, and each ComboboxChip given one as its value gets a button that removes it. Backspace in the empty field removes the last one. Use it for tags or filters, where several answers are normal.

Preview width

Clear

The field starts on Next.js, and showClear on ComboboxInput adds a button that empties it, shown in place of the chevron. Offer it when an empty answer is allowed or people often change their mind, so they don't have to select the text and delete it. Leave it off a required field, where empty is never a valid answer.

Preview width

Groups

Eighteen time zones under three headings, Americas, Europe and Asia/Pacific, with a separator between the groups and "No timezones found." when nothing matches. groupBy in useListCollection groups them, and each heading comes from the heading prop on ComboboxGroup. Group the options when people know the region before the city.

Preview width

Custom

Nineteen countries, each row an Item inside ComboboxItem with the name over the continent and the country code. Typing still matches on the name alone, so the second line is there to read, not to search. Use a richer row when the name isn't enough to choose, and keep it to two lines so the list doesn't turn into a table.

Preview width

Invalid

The framework field in its error state. aria-invalid on ComboboxInput turns the border red and tells screen readers the value is wrong. Nothing here says why, so show it after a submit fails, with a sentence under the field in a Field. An empty optional field isn't invalid, so don't paint it red on first view.

Preview width

Disabled

The framework field, shown but switched off. disabled on both Combobox and ComboboxInput turns off the whole field, so nothing can be typed and the list can't open. Use it when the value is fixed by the plan or the person's role, and showing it still matters. When there's nothing to choose at all, plain text reads better than a control that looks broken.

Preview width

Auto highlight

inputBehavior set to autohighlight on Combobox highlights the first match as soon as you type, so Enter picks it with no arrow key first. Turn it on when the top match is nearly always the one people want, and leave it off when the first hit is often wrong, since Enter would take it.

Preview width

A button that reads "Select country" opens a popup with its own search field above 19 countries, because ComboboxInput sits inside ComboboxContent with showTrigger turned off. selectionBehavior set to clear empties that field after each pick, so the next search starts fresh while the button shows the choice. The prompt is also the first row of the list, so picking it resets the choice.

Preview width

Input group

A globe icon sits at the start of the field, an InputGroupAddon passed to ComboboxInput, over the grouped time zones. UI SDK places the popup against the text input, which starts after the icon, and w-60 on ComboboxContent widens it to 240 pixels for the longer city names. Add an icon when it says what the field is for faster than the placeholder.

Preview width

RTL

Arabic categories in a multiple combobox, starting with one chip, inside a Direction provider set to right to left, with dir set to rtl on the Field. The list renders in a portal but keeps the direction of where it's written, so the chips, the text field and the list all run right to left, and the empty message is in Arabic too.

Preview width

FAQ

Should I use a Combobox or a Select?

Use a Combobox when the list is long enough that people would rather type than scroll: countries, time zones, the people on a team. Typing narrows the list, so a hundred options feel like five.

Use a Select for a short, fixed set such as a status or a sort order, where a text field would be one more thing to fill in. If any typed text is a valid answer and the list only suggests, that's an Autocomplete.

How do I filter Combobox options as the user types?

With a collection, this component leaves filtering to you, as Ark UI's does. Build the options with useListCollection and a filter such as contains from useFilter, then call the filter it returns with the new text each time the input value changes, as every demo here does. Pass the resulting collection to Combobox and render its items.

How do I load Combobox options from an API as someone types?

Fetch each time the input value changes, and pass the results to the set function from useListCollection instead of calling filter, since the server has already matched them. Show a loading row inside ComboboxContent while the request runs.

Keep each response with the query that asked for it, and drop one that arrives after a newer query, or a slow request can replace a fresh list with stale results.

How do I select multiple values in a Combobox?

Add multiple to Combobox, and the value becomes an array. Inside ComboboxChips, render a ComboboxChip for each value ComboboxValue hands you, with that value as its value, and end the row with ComboboxFieldInput, as the Multiple demo does.

How do I control the Combobox value in Vue?

Bind the selection with v-model: the chosen item's value, null once cleared, or an array with multiple. Listen to @value-change as well when you need its details, which come second. The typed text is separate, and inputValue with @input-value-change controls it.

Can users type a value that isn't in the Combobox list?

Yes. Add allowCustomValue to Combobox, and text that matches no option becomes the value itself, when Enter is pressed with nothing highlighted or, in a single combobox, when the list closes. The value then holds that string rather than an option's value.

When free text is the normal answer and the list only suggests, an Autocomplete fits better, because its value is the text itself.

How do I show a message when no Combobox options match?

Put a ComboboxEmpty inside ComboboxContent with the text, such as "No items found.", as the demos do. UI SDK shows it only while no option matches, so it can stay in the markup all the time, and with no text of its own it says "No results found."

Say what to do next where you can, such as checking the spelling or creating the missing item.

How do I submit a Combobox with a form?

Set name on Combobox, and UI SDK renders a hidden input with the chosen item's value, or one per value with multiple, so the form gets the value rather than the label in the field. Add required to block an empty submission.

With a form library, connect the field's value to the controlled value and its change handler, and wrap the combobox in a Field for the label and the error.

API Reference

Combobox

PropType
items?ItemList

The items ComboboxList maps over when its child is a function: strings, { value, label } objects, or groups of them ({ value, items }). UI SDK filters what they render as you type. Without value or defaultValue, they give the value its type.

itemToStringLabel?(value: ValueOf<T, ItemList>) → string

The other bases' name for itemToLabel.

Type
(value: ValueOf<T, ItemList>) → string
Parameters

value – ValueOf<T

ItemList>

Returns
string
itemToStringValue?(value: ValueOf<T, ItemList>) → string

The other bases' name for itemToValue.

Type
(value: ValueOf<T, ItemList>) → string
Parameters

value – ValueOf<T

ItemList>

Returns
string
EventType
@input-value-change(query: string, details: TextChangeDetails<ComboboxQueryChangeReason>) → void

The other bases' name for onQueryChange.

Type
(query: string, details: TextChangeDetails<ComboboxQueryChangeReason>) → void
Parameters

query – string

details – TextChangeDetails<ComboboxQueryChangeReason>

Returns
void

ComboboxValue

PropType
getMoreLabel?(count: number) → string

The words for the labels past maxLabels.

Default
(count) => `${count} more`
Parameters

count – number

Returns
string
maxLabels?number

With multiple, how many labels the label in its state shows before the rest are counted, as in "France, Chile and 2 more", joined the way the page's language joins lists, or in English with the default getMoreLabel.

ComboboxTrigger

<button> data-slot="combobox-trigger"

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-closed?string

Present while the list is closed, including while it animates out.

data-disabled?string

Present when the combobox is disabled, by its own prop, a field or a <fieldset>.

data-open?string

Present while the list is open.

data-readonly?string

Present when the combobox is read-only.

data-required?string

Present when the combobox is required.

ComboboxClear

<button> data-slot="combobox-clear"

PropType
keepMounted?boolean

Whether the clear button stays in the page while there's nothing to clear.

Default
false
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the combobox is disabled or read-only.

ComboboxInput

<input> data-slot="combobox-input"

PropType
showClear?boolean

Shows a button that clears the input.

Default
false
showTrigger?boolean

Shows the button that opens the list.

Default
true
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-closed?string

Present while the list is closed, including while it animates out.

data-disabled?string

Present when the combobox is disabled, by its own prop, a field or a <fieldset>.

data-open?string

Present while the list is open.

data-readonly?string

Present when the combobox is read-only.

data-required?string

Present when the combobox is required.

ComboboxContent

<div> data-slot="combobox-content"

PropType
align?Align

How the popup lines up with the anchor along that side. start and end follow the reading direction. How the list lines up with the input along that side.

Default
"start"
alignOffset?number

Shift along the anchor, in pixels. Shift along the input, in pixels.

Default
0
anchor?AnchorProp | React.RefObject<HTMLElement | null>

What the list opens against: an element, a ref to one (useComboboxAnchor), a selector or a point.

Type
AnchorProp | React.RefObject<HTMLElement | null>
arrowPadding?number

Space to keep between the arrow and the popup's corners, in pixels.

Default
6
collisionPadding?number

Space to keep from the viewport edges, in pixels.

Default
8
container?DocumentFragment | Element | null

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type
DocumentFragment | Element | null
keepMounted?boolean

Whether the list stays in the page, hidden, while closed.

Default
false
side?Side

Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the input the list opens on.

Default
"bottom"
sideOffset?number

Gap between the anchor and the popup, in pixels. Gap between the input and the list, in pixels. UI SDK's default: 4.

Default
6
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-align"start" | "center" | "end"

How the list lines up with the input.

Type
"start" | "center" | "end"
data-closed?string

Present while the list is closed, including while it animates out.

data-ending-style?string

Present while the list animates out. Style the state you animate to.

data-has-icons?string

Present while any item inside holds an icon part, so items without one can line up.

data-modality"keyboard" | "pointer"

Whether the keyboard or a pointer moves the highlight. Style a focus ring for the keyboard only.

Type
"keyboard" | "pointer"
data-open?string

Present while the list is open.

data-presentation"popover" | "sheet"

How the list presents this time it's open.

Type
"popover" | "sheet"
data-side"top" | "right" | "bottom" | "left"

Where the list ended up, after flipping away from edges.

Type
"top" | "right" | "bottom" | "left"
data-starting-style?string

Present for the first frame. Style the state you animate from.

CSS variableType
--anchor-heightstring

Height of the anchor.

--anchor-widthstring

The anchor's width.

--arrow-offsetstring

Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it.

--available-heightstring

The height left between the anchor and the viewport's edge.

--available-widthstring

The width left between the anchor and the viewport's edge.

--drawer-dimstring

While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.

--drawer-expandstring

While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.

--drawer-progressstring

While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.

--drawer-stackstring

While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.

--sheet-backdropstring

Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.

--transform-originstring

Where the content scales from, on its trigger's side.

ComboboxList

<div>

PropType
children?VNode | ItemRenderer

The options, or a function the combobox's items map through.

Type
VNode | ItemRenderer
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

ComboboxItem

<div> data-slot="combobox-item"

PropType
valueT

What the value becomes when the item is chosen. A string, or any value with itemToValue.

disabled?boolean

Keeps the item from being chosen. The keyboard and the pointer skip it. Sets data-disabled and aria-disabled.

index?number

The item's position among all visible items, for virtualized lists that render only some. Sets aria-posinset and aria-setsize.

keywords?string[]

More words filtering matches.

label?string

The text the input shows once chosen, and filtering matches, when the content isn't plain text. Not the accessible name: use aria-label for that.

#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the item can't be chosen, or maxSelected is reached.

data-has-icon?string

Present on an item while it holds an icon part.

data-highlighted?string

Present on the highlighted item. Focus stays in the input.

data-selected?string

Present on selected items, and on the check inside them.

ComboboxGroup

<div> data-slot="combobox-group"

PropType
items?Items

The group's items, which its ComboboxCollection maps through.

#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

ComboboxLabel

<div> data-slot="combobox-group-label"

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

ComboboxCollection

ComboboxEmpty

<div> data-slot="combobox-empty"

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-empty?string

Present while no item matches.

data-loading?string

Present while results load, with status="loading".

ComboboxSeparator

<div> data-slot="combobox-separator"

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

ComboboxChips

<div> data-slot="combobox-chips"

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the combobox is disabled, by its own prop, a field or a <fieldset>.

data-readonly?string

Present when the combobox is read-only.

data-required?string

Present when the combobox is required.

ComboboxChip

<div> data-slot="combobox-chip"

PropType
valueT

The selected value this chip shows.

showRemove?boolean

Shows a button that removes the chip.

Default
true
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the combobox is disabled or read-only, so the chip can't be removed.

data-value"a"

The chip's value, as the string it submits as.

ComboboxChipsInput

<input> data-slot="combobox-input"

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-closed?string

Present while the list is closed, including while it animates out.

data-disabled?string

Present when the combobox is disabled, by its own prop, a field or a <fieldset>.

data-open?string

Present while the list is open.

data-readonly?string

Present when the combobox is read-only.

data-required?string

Present when the combobox is required.