Skip to content

Combobox

Autocomplete input and command palette with a list of suggestions.

Examples

Default

vue
<script setup>
import { ref } from 'vue'
import {
  Combobox,
  ComboboxAnchor,
  ComboboxEmpty,
  ComboboxGroup,
  ComboboxInput,
  ComboboxItem,
  ComboboxItemIndicator,
  ComboboxList,
  ComboboxTrigger,
  ComboboxViewport
} from '@empathyds/vue'

const frameworks = [
  { value: 'next.js', label: 'Next.js' },
  { value: 'sveltekit', label: 'SvelteKit' },
  { value: 'nuxt.js', label: 'Nuxt.js' },
  { value: 'remix', label: 'Remix' },
  { value: 'astro', label: 'Astro' },
]

const value = ref('')
</script>

<template>
  <Combobox v-model="value">
    <ComboboxAnchor class="relative">
      <ComboboxInput placeholder="Select framework..." />
      <ComboboxTrigger class="absolute inset-y-0 right-0 flex items-center px-2">
        <span class="text-muted-foreground text-xs">▼</span>
      </ComboboxTrigger>
    </ComboboxAnchor>
    <ComboboxList class="mt-1 w-full border rounded-md bg-popover text-popover-foreground shadow-md">
      <ComboboxViewport>
        <ComboboxEmpty class="py-2 text-center text-sm">No framework found.</ComboboxEmpty>
        <ComboboxGroup>
          <ComboboxItem
            v-for="framework in frameworks"
            :key="framework.value"
            :value="framework.value"
          >
            <ComboboxItemIndicator class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">

            </ComboboxItemIndicator>
            <span>{{ framework.label }}</span>
          </ComboboxItem>
        </ComboboxGroup>
      </ComboboxViewport>
    </ComboboxList>
  </Combobox>
</template>

Props

Combobox

PropTypeDefaultDescription
model-valueany-The verified value of the combobox
default-valueany-The default value of the combobox
openbooleanfalseWhether the combobox is open
default-openbooleanfalseThe default open state
disabledbooleanfalseWhether the combobox is disabled
multiplebooleanfalseWhether to allow multiple selections

Slots

Combobox

SlotDescription
defaultThe combobox content

ComboboxInput

SlotDescription
defaultThe input content

ComboboxTrigger

SlotDescription
defaultThe trigger content

ComboboxContent

SlotDescription
defaultThe content of the popover

ComboboxItem

SlotDescription
defaultThe item content