Skip to content

Combobox

Alpha
Choose from a list of suggested values with full keyboard support.

Features

  • Can be controlled or uncontrolled.
  • Offers 2 positioning modes.
  • Supports items, labels, groups of items.
  • Focus is fully managed.
  • Full keyboard navigation.
  • Supports custom placeholder.
  • Supports Right to Left direction.

Installation

Install the component from your command line.

bash
npm install radix-vue

Anatomy

Import all parts and piece them together.

vue
<script setup lang="ts">
import {
  ComboboxArrow,
  ComboboxCancel,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxGroup,
  ComboboxHeader,
  ComboboxInput,
  ComboboxItem,
  ComboboxItemIndicator,
  ComboboxLabel,
  ComboboxPortal,
  ComboboxRoot,
  ComboboxSeparator,
  ComboboxTrigger,
  ComboboxViewport,
} from 'radix-vue'
</script>

<template>
  <ComboboxRoot>
    <ComboboxHeader>
      <ComboboxInput />
      <ComboboxTrigger />
      <ComboboxCancel />
    </ComboboxHeader>

    <ComboboxPortal>
      <ComboboxContent>
        <ComboboxViewport>
          <ComboboxEmpty />

          <ComboboxItem>
            <ComboboxItemIndicator />
          </ComboboxItem>

          <ComboboxGroup>
            <ComboboxLabel />
            <ComboboxItem>
              <ComboboxItemIndicator />
            </ComboboxItem>
          </ComboboxGroup>
          <ComboboxSeparator />
        </ComboboxViewport>

        <ComboboxArrow />
      </ComboboxContent>
    </ComboboxPortal>
  </ComboboxRoot>
</template>

API Reference

Root

Contains all the parts of a Combobox

PropTypeDefault
defaultValue
string | string[] | object | object[]
modelValue
string | string[] | object | object[]
defaultOpen
boolean
open
boolean
searchTerm
string
multiple
boolean
dir
enum
name
string
disabled
boolean
EmitType
@update:modelValue
(value: string) => void
@update:open
(open: boolean) => void
@update:searchTerm
(value: string) => void

The header section of Combobox. Used as an anchor if you set ComboboxContent's position to popper.

PropTypeDefault
asChild
boolean
false

Input

The input component to search through the combobox items.

Trigger

The button that toggles the Combobox Content.

PropTypeDefault
asChild
boolean
false
Data AttributeValue
[data-state]"open" | "closed"
[data-disabled]Present when disabled

Cancel

The button that clears the search term.

PropTypeDefault
asChild
boolean
false

Portal

When used, portals the content part into the body.

PropTypeDefault
to
string | HTMLElement
body

Content

The component that pops out when the combobox is open.

PropTypeDefault
position
enum
"inline"
bodyLock
boolean
false
disableOutsidePointerEvents
boolean
false
side
enum
"bottom"
sideOffset
number
0
align
enum
"start"
alignOffset
number
0
avoidCollisions
boolean
true
collisionBoundary
Boundary
[]
collisionPadding
number | Padding
10
arrowPadding
number
0
sticky
enum
"partial"
hideWhenDetached
boolean
false
asChild
boolean
false
EmitType
@closeAutoFocus
(event: Event) => void
@escapeKeyDown
(event: KeyboardEvent) => void
@pointerDownOutside
(event: PointerDownOutsideEvent) => void
Data AttributeValue
[data-state]"open" | "closed"
[data-side]"left" | "right" | "bottom" | "top"
[data-align]"start" | "end" | "center"
CSS VariableDescription
--radix-combobox-content-transform-origin
The transform-origin computed from the content and arrow positions/offsets. Only present when position="popper".
--radix-combobox-content-available-width
The remaining width between the trigger and the boundary edge. Only present when position="popper".
--radix-combobox-content-available-height
The remaining height between the trigger and the boundary edge. Only present when position="popper".
--radix-combobox-trigger-width
The width of the trigger. Only present when position="popper".
--radix-combobox-trigger-height
The height of the trigger. Only present when position="popper".

Viewport

The scrolling viewport that contains all of the items.

PropTypeDefault
asChild
boolean
false

Item

The component that contains the combobox items.

PropTypeDefault
value*
string
disabled
boolean
asChild
boolean
false
Data AttributeValue
[data-state]"checked" | "unchecked"
[data-highlighted]Present when highlighted
[data-disabled]Present when disabled

ItemIndicator

Renders when the item is selected. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.

PropTypeDefault
asChild
boolean
false

Group

Used to group multiple items. use in conjunction with ComboboxLabel to ensure good accessibility via automatic labelling.

PropTypeDefault
asChild
boolean
false

Label

Used to render the label of a group. It won't be focusable using arrow keys.

PropTypeDefault
asChild
boolean
false

Separator

Used to visually separate items in the Combobox

PropTypeDefault
asChild
boolean
false

Arrow

An optional arrow element to render alongside the content. This can be used to help visually link the trigger with the ComboboxContent. Must be rendered inside ComboboxContent. Only available when position is set to popper.

PropTypeDefault
asChild
boolean
false
width
number
10
height
number
5