Install
Run this in the app, after shadcn-vue init and the Beehexa theme (Button › Code):
npx shadcn-vue@latest add https://beehexa.design/r/combobox.json
It also installs Input group, which draws the search field.
Use
<script setup lang="ts">
import { Check } from '@lucide/vue'
import { ref } from 'vue'
import {
Combobox, ComboboxAnchor, ComboboxEmpty, ComboboxInput,
ComboboxItem, ComboboxItemIndicator, ComboboxList, ComboboxViewport,
} from '@/components/ui/combobox'
const warehouses = [{ id: 'hn', name: 'Hanoi, Long Bien' }, { id: 'dn', name: 'Da Nang, Hai Chau' }]
const warehouse = ref<(typeof warehouses)[number]>()
</script>
<template>
<label for="ship-from">Ship from</label>
<Combobox v-model="warehouse" by="id">
<ComboboxAnchor>
<ComboboxInput id="ship-from" :display-value="(item) => item?.name ?? ''" placeholder="Search warehouses…" />
</ComboboxAnchor>
<ComboboxList>
<ComboboxEmpty>No warehouse found.</ComboboxEmpty>
<ComboboxViewport>
<ComboboxItem v-for="item in warehouses" :key="item.id" :value="item">
{{ item.name }}
<ComboboxItemIndicator><Check /></ComboboxItemIndicator>
</ComboboxItem>
</ComboboxViewport>
</ComboboxList>
</Combobox>
</template>
Props
| Part | Prop | Values | Notes |
|---|---|---|---|
Combobox |
v-model, defaultValue |
object or string; an array with multiple |
Never the empty string |
Combobox |
by |
key name or function | Compares object values, such as by="id" |
Combobox |
multiple, disabled, openOnClick, openOnFocus |
boolean | |
Combobox |
ignoreFilter |
boolean | Turn off the built-in filter when the list comes from a server search |
ComboboxInput |
displayValue |
(value) => string |
Text shown in the field for the chosen value |
ComboboxList |
side, align, sideOffset |
Defaults: below, centred, 4 (space.overlay.offset) |
|
ComboboxGroup |
heading |
string | A group heading in font.label.small |
ComboboxItem |
value, disabled |
||
ComboboxTrigger |
as-child |
boolean | Use with a Button to open the list from a button |
Other parts: ComboboxAnchor, ComboboxViewport, ComboboxEmpty, ComboboxItemIndicator, ComboboxSeparator, ComboboxCancel.
Built on
Wraps the reka-ui Combobox with the shadcn-vue Combobox API. reka-ui gives the combobox and listbox roles, filtering, keyboard handling and collision handling. Beehexa adds the styles and the text-field focus on the search field.
Limitations
- The list appears and leaves with the shadcn-vue animation classes, not the motion tokens (
motion.overlay.enter,.exit), for now. - reka-ui adds a
<style>element to the list, which the strict style level of the Content Security Policy blocks. The list still hides its scrollbar with the kit’s CSS; to stop the browser’s error at that level, add the Vite plugin from Tools › shadcn-vue package.