<script setup lang="ts">
import { AComboboxAnchor, AComboboxContent, AComboboxEmpty, AComboboxGroup, AComboboxInput, AComboboxItem, AComboboxItemIndicator, AComboboxLabel, AComboboxPortal, AComboboxRoot, AComboboxSeparator, AComboboxTrigger, AComboboxViewport } from 'akar';
const options = [
{
name: 'Fruit',
children: [
{ name: 'Apple' },
{ name: 'Banana' },
{ name: 'Orange' },
{ name: 'Honeydew' },
{ name: 'Grapes' },
{ name: 'Watermelon' },
{ name: 'Cantaloupe' },
{ name: 'Pear' },
],
},
{
name: 'Vegetable',
children: [
{ name: 'Cabbage' },
{ name: 'Broccoli' },
{ name: 'Carrots' },
{ name: 'Lettuce' },
{ name: 'Spinach' },
{ name: 'Bok Choy' },
{ name: 'Cauliflower' },
{ name: 'Potatoes' },
],
},
];
</script>
<template>
<AComboboxRoot
class="inline-flex items-center relative"
>
<AComboboxAnchor
class="text-sm color-text-highlighted px-2.5 py-1.5 pe-9 border-0 rounded-md bg-background gap-1.5 w-full ring ring-ring-accented ring-inset transition-colors-280 placeholder:color-text-dimmed focus:outline-none disabled:opacity-75 disabled:cursor-not-allowed focus-visible:(ring-2 ring-primary ring-inset)"
as-child
>
<AComboboxInput
placeholder="Placeholder..."
/>
<AComboboxTrigger class="group pe-2.5 flex items-center end-0 inset-y-0 absolute disabled:opacity-75 disabled:cursor-not-allowed">
<i
class="i-lucide:chevron-down color-text-dimmed shrink-0 size-5"
/>
</AComboboxTrigger>
</AComboboxAnchor>
<AComboboxPortal>
<AComboboxContent
side="bottom"
:side-offset="8"
position="popper"
class="rounded-md bg-background flex flex-col max-h-60 w-$akar-combobox-trigger-width pointer-events-auto ring ring-ring shadow-lg origin-$akar-combobox-content-transform-origin overflow-hidden data-[state=closed]:(animate-out fade-out-0 zoom-out-95) data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95"
>
<AComboboxViewport class="flex-1 relative overflow-y-auto scroll-py-1">
<AComboboxEmpty class="color-text-muted text-center" />
<template
v-for="(group, index) in options"
:key="group.name"
>
<AComboboxGroup class="p-1 isolate">
<AComboboxSeparator
v-if="index !== 0"
class="my-1 bg-border h-px -mx-1"
/>
<AComboboxLabel class="text-xs color-text-highlighted font-semibold p-1.5 gap-1.5">
{{ group.name }}
</AComboboxLabel>
<AComboboxItem
v-for="option in group.children"
:key="option.name"
:value="option.name"
class="group text-sm color-text p-1.5 outline-none flex gap-1.5 w-full cursor-pointer select-none transition-colors-280 items-start relative before:(rounded-md content-empty transition-colors-280 inset-px absolute -z-1) data-[disabled]:(opacity-75 cursor-not-allowed) data-[highlighted]:not-[[data-disabled]]:color-text-highlighted data-[highlighted]:not-[[data-disabled]]:before:bg-background-elevated/50"
>
<span class="flex flex-1 flex-col min-w-0">
{{ option.name }}
</span>
<span class="ms-auto inline-flex gap-1.5 items-center">
<AComboboxItemIndicator
as-child
>
<i class="i-lucide:check shrink-0 size-5" />
</AComboboxItemIndicator>
</span>
</AComboboxItem>
</AComboboxGroup>
</template>
</AComboboxViewport>
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
Import all parts and piece them together.
<script setup lang="ts">
import {
AComboboxAnchor,
AComboboxArrow,
AComboboxCancel,
AComboboxContent,
AComboboxGroup,
AComboboxInput,
AComboboxItem,
AComboboxItemIndicator,
AComboboxLabel,
AComboboxPortal,
AComboboxRoot,
AComboboxSeparator,
AComboboxTrigger,
AComboboxViewport,
} from 'akar';
</script>
<template>
<AComboboxRoot>
<AComboboxAnchor>
<AComboboxInput />
<AComboboxTrigger />
<AComboboxCancel />
</AComboboxAnchor>
<AComboboxPortal>
<AComboboxContent>
<AComboboxViewport>
<AComboboxItem>
<AComboboxItemIndicator />
</AComboboxItem>
<AComboboxGroup>
<AComboboxLabel />
<AComboboxItem>
<AComboboxItemIndicator />
</AComboboxItem>
</AComboboxGroup>
<AComboboxSeparator />
</AComboboxViewport>
<AComboboxArrow />
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
One benefit of using Akar is its flexibility and low-level control over the components. However, this also means that you may need to manually construct more complex UI elements by combining multiple Akar components together.
If you feel there's a lot of elements that needs to be constructed manually using Akar, consider using Pohon UI instead. It provides a higher-level abstraction over Akar components with pre-defined styles and behaviors that can help you build UIs faster.
Contains all the parts of a Combobox
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
by | string | ((a: AcceptableValue, b: AcceptableValue) => boolean)Use this to compare objects by a particular field, or pass your own comparison function for complete control over how objects are compared. | |
defaultOpen | booleanThe open state of the combobox when it is initially rendered. | |
defaultValue | AcceptableValue | AcceptableValue[]The value of the listbox when initially rendered. Use when you do not need to control the state of the Listbox | |
dir | 'ltr' | 'rtl'The reading direction of the listbox when applicable. | |
disabled | booleanWhen | |
highlightOnHover | booleanWhen | |
ignoreFilter | booleanWhen | |
modelValue | AcceptableValue | AcceptableValue[] | |
multiple | booleanWhether multiple options can be selected or not. | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
open | boolean | |
openOnClick | false | booleanWhether to open the combobox when the input is clicked |
openOnFocus | false | booleanWhether to open the combobox when the input is focused |
required | booleanWhen | |
resetSearchTermOnBlur | true | booleanWhether to reset the searchTerm when the Combobox input blurred |
resetSearchTermOnSelect | true | booleanWhether to reset the searchTerm when the Combobox value is selected |
| Event | Type |
|---|---|
highlight | [payload: { ref: HTMLElement; value: AcceptableValue; }]Event handler when highlighted element changes. |
update:modelValue | [value: AcceptableValue]Event handler called when the value changes. |
update:open | [value: boolean]Event handler called when the open state of the combobox changes. |
| Slot | Type |
|---|---|
open | booleanThe controlled open state of the Combobox. Can be binded with with |
modelValue | AcceptableValue | AcceptableValue[]The controlled value of the listbox. Can be binded with with |
Used as an anchor if you set AComboboxContent's position to popper.
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
reference | ReferenceElementThe reference (or anchor) element that is being referred to for positioning. If not provided will use the current component as anchor. |
The input component to search through the combobox items.
| Prop | Default | Type |
|---|---|---|
as | 'input' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
autoFocus | booleanFocus on element when mounted. | |
disabled | booleanWhen | |
displayValue | ((val: any) => string)The display value of input for selected item. Does not work with | |
modelValue | stringThe controlled value of the listbox. Can be binded with with |
| Event | Type |
|---|---|
update:modelValue | [string]Event handler called when the value changes. |
The button that toggles the Combobox Content.
| Prop | Default | Type |
|---|---|---|
as | 'button' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
disabled | booleanWhen |
| Attribute | Value |
|---|---|
[data-state] | 'open' | 'closed' |
[data-disabled] | Present when disabled |
The button that clears the search term.
| Prop | Default | Type |
|---|---|---|
as | 'button' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
Shown when none of the items match the query.
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
When used, portals the content part into the body.
You need to set position="popper" for AComboboxContent to make sure the position was automatically computed similar to Popover or DropdownMenu.
| Prop | Default | Type |
|---|---|---|
defer | booleanDefer the resolving of a Teleport target until other parts of the application have mounted (requires Vue 3.5.0+) {@link https://vuejs.org/guide/built-ins/teleport.html#deferred-teleport} | |
disabled | booleanWhen | |
forceMount | booleanUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | |
to | string | HTMLElementVue native teleport component prop {@link https://vuejs.org/guide/built-ins/teleport.html#basic-usage} |
The component that pops out when the combobox is open.
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
align | 'start' | 'center' | 'end'The preferred alignment against the trigger. May change when collisions occur. | |
alignFlip | booleanFlip alignment when colliding with boundary.
May only occur when | |
alignOffset | numberAn offset in pixels from the | |
arrowPadding | numberThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. | |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
avoidCollisions | booleanWhen | |
bodyLock | booleanThe document.body will be lock, and scrolling will be disabled. | |
collisionBoundary | Element | (Element | null)[] | nullThe element used as the collision boundary. By default this is the viewport, though you can provide additional element(s) to be included in this check. | |
collisionPadding | number | Partial<Record<Side, number>>The distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { top: 20, left: 20 }. | |
disableOutsidePointerEvents | booleanWhen | |
disableUpdateOnLayoutShift | booleanWhether to disable the update position for the content when the layout shifted. | |
forceMount | booleanUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | |
hideWhenDetached | booleanWhether to hide the content when the trigger becomes fully occluded. | |
position | 'inline' | 'popper'The positioning mode to use, | |
positionStrategy | 'fixed' | 'absolute'The type of CSS position property to use. | |
prioritizePosition | booleanForce content to be position within the viewport. Might overlap the reference element, which may not be desired. | |
reference | ReferenceElementThe reference (or anchor) element that is being referred to for positioning. If not provided will use the current component as anchor. | |
side | 'top' | 'right' | 'bottom' | 'left'The preferred side of the trigger to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled. | |
sideFlip | booleanFlip to the opposite side when colliding with boundary. | |
sideOffset | numberThe distance in pixels from the trigger. | |
sticky | 'always' | 'partial'The sticky behavior on the align axis. | |
updatePositionStrategy | 'always' | 'optimized'Strategy to update the position of the floating element on every animation frame. |
| Event | Type |
|---|---|
escapeKeyDown | [event: KeyboardEvent] |
focusOutside | [event: FocusOutsideEvent] |
interactOutside | [event: PointerDownOutsideEvent | FocusOutsideEvent] |
pointerDownOutside | [event: PointerDownOutsideEvent] |
| Attribute | Value |
|---|---|
[data-state] | 'open' | 'closed' |
[data-side] | 'left' | 'right' | 'bottom' | 'top' |
[data-align] | 'start' | 'end' | 'center' |
| Variable | Description |
|---|---|
--akar-combobox-content-transform-origin | The |
--akar-combobox-content-available-width | The remaining width between the trigger and the boundary edge. Only present when |
--akar-combobox-content-available-height | The remaining height between the trigger and the boundary edge. Only present when |
--akar-combobox-trigger-width | The width of the trigger. Only present when |
--akar-combobox-trigger-height | The height of the trigger. Only present when |
The scrolling viewport that contains all of the items.
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
nonce | stringWill add |
The component that contains the combobox items.
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
disabled | booleanWhen | |
textValue | stringA string representation of the item contents. If the children are not plain text, then the | |
value* | AcceptableValueThe value given as data when submitted with a |
| Event | Type |
|---|---|
select | [event: SelectEvent<AcceptableValue>] |
| Attribute | Value |
|---|---|
[data-state] | 'checked' | 'unchecked' |
[data-highlighted] | Present when highlighted |
[data-disabled] | Present when disabled |
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.
Used to group multiple items. use in conjunction with AComboboxLabel to ensure good accessibility via automatic labelling.
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
Used to render the label of a group. It won't be focusable using arrow keys.
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
for | string |
Used to visually separate items in the Combobox
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
An optional arrow element to render alongside the content. This can be used to help visually link the trigger with the AComboboxContent. Must be rendered inside AComboboxContent. Only available when position is set to popper.
| Prop | Default | Type |
|---|---|---|
as | 'svg' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
height | 5 | numberThe height of the arrow in pixels. |
rounded | booleanWhen | |
width | 10 | numberThe width of the arrow in pixels. |
Virtual container to achieve list virtualization.
See the virtualization guide for more general info on virtualization.
| Prop | Default | Type |
|---|---|---|
estimateSize | numberEstimated size (in px) of each item | |
options* | AcceptableValue[]List of items | |
overscan | numberNumber of items rendered outside the visible area | |
textContent | ((option: AcceptableValue) => string)Text content for each item to achieve type-ahead feature |
| Slot | Type |
|---|---|
option | null | string | number | bigint | Record<string, any> |
virtualizer | Virtualizer<HTMLElement, Element> |
virtualItem | VirtualItem |
Unlike native HTML form controls which only allow you to provide strings as values, akar supports binding complex objects as well.
Make sure to set the displayValue prop to set the input value on item selection.
<script setup lang="ts">
import { AComboboxContent, AComboboxInput, AComboboxItem, AComboboxPortal, AComboboxRoot } from 'akar';
import { ref } from 'vue';
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
];
const selectedPeople = ref(people[0]);
</script>
<template>
<AComboboxRoot v-model="selectedPeople">
<AComboboxInput :display-value="(v) => v.name" />
<AComboboxPortal>
<AComboboxContent>
<AComboboxItem
v-for="person in people"
:key="person.id"
:value="person"
:disabled="person.unavailable"
>
{{ person.name }}
</AComboboxItem>
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
The Combobox component allows you to select multiple values. You can enable this by providing an array of values instead of a single value.
<script setup lang="ts">
import { AComboboxRoot } from 'akar';
import { ref } from 'vue';
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
];
const selectedPeople = ref([people[0], people[1]]);
</script>
<template>
<AComboboxRoot
v-model="selectedPeople"
multiple
>
…
</AComboboxRoot>
</template>
Internally, AComboboxRoot will filter the item based on the rendered text.
However, you may also provide your own custom filtering logic together with setting ignoreFilter="true".
<script setup lang="ts">
import { AComboboxContent, AComboboxInput, AComboboxItem, AComboboxPortal, AComboboxRoot, useFilter } from 'akar';
import { ref } from 'vue';
const people = [
{ id: 1, name: 'Durward Reynolds' },
{ id: 2, name: 'Kenton Towne' },
{ id: 3, name: 'Therese Wunsch' },
{ id: 4, name: 'Benedict Kessler' },
{ id: 5, name: 'Katelyn Rohan' },
];
const selectedPeople = ref(people[0]);
const searchTerm = ref('');
const { startsWith } = useFilter({ sensitivity: 'base' });
const filteredPeople = computed(() => people.filter((p) => startsWith(p.name, searchTerm.value)));
</script>
<template>
<AComboboxRoot
v-model="selectedPeople"
:ignore-filter="true"
>
<AComboboxInput v-model="searchTerm" />
<AComboboxPortal>
<AComboboxContent>
<AComboboxItem
v-for="person in filteredPeople"
:key="person.id"
:value="person"
>
{{ person.name }}
</AComboboxItem>
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
By default the Combobox will use the input contents as the label for screenreaders. If you'd like more control over what is announced to assistive technologies, use the Label component.
<script setup lang="ts">
import { AComboboxInput, AComboboxRoot, Label } from 'akar';
</script>
<template>
<AComboboxRoot v-model="selectedPeople">
<Label for="person">Person: </Label>
<AComboboxInput
id="person"
placeholder="Select a person"
/>
…
</AComboboxRoot>
</template>
You can add special styles to disabled items via the data-disabled attribute.
<script setup lang="ts">
import {
AComboboxContent,
AComboboxInput,
AComboboxItem,
AComboboxPortal,
AComboboxRoot,
} from 'akar';
</script>
<template>
<AComboboxRoot>
<AComboboxInput />
<AComboboxPortal>
<AComboboxContent>
<AComboboxItem
class="AComboboxItem"
disabled
>
…
</AComboboxItem>
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
/* styles.css */
.AComboboxItem[data-disabled] {
color: 'gainsboro';
}
Use the Separator part to add a separator between items.
<script setup lang="ts">
import {
AComboboxContent,
AComboboxInput,
AComboboxItem,
AComboboxPortal,
AComboboxRoot,
AComboboxSeparator
} from 'akar';
</script>
<template>
<AComboboxRoot>
<AComboboxInput />
<AComboboxPortal>
<AComboboxContent>
<AComboboxItem>…</AComboboxItem>
<AComboboxItem>…</AComboboxItem>
<AComboboxItem>…</AComboboxItem>
<AComboboxSeparator />
<AComboboxItem>…</AComboboxItem>
<AComboboxItem>…</AComboboxItem>
<AComboboxItem>…</AComboboxItem>
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
Use the Group and Label parts to group items in a section.
<script setup lang="ts">
import {
AComboboxContent,
AComboboxGroup,
AComboboxInput,
AComboboxItem,
AComboboxLabel,
AComboboxPortal,
AComboboxRoot
} from 'akar';
</script>
<template>
<AComboboxRoot>
<AComboboxInput />
<AComboboxPortal>
<AComboboxContent>
<AComboboxGroup>
<AComboboxLabel>Label</AComboboxLabel>
<AComboboxItem>…</AComboboxItem>
<AComboboxItem>…</AComboboxItem>
<AComboboxItem>…</AComboboxItem>
</AComboboxGroup>
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
You can use custom content in your items.
<script setup lang="ts">
import {
AComboboxContent,
AComboboxInput,
AComboboxItem,
AComboboxItemIndicator,
AComboboxPortal,
AComboboxRoot
} from 'akar';
</script>
<template>
<AComboboxRoot>
<AComboboxInput />
<AComboboxPortal>
<AComboboxContent>
<AComboboxItem>
<img src="…">
Adolfo Hess
<AComboboxItemIndicator />
</AComboboxItem>
…
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
By default, selecting AComboboxItem would close the content, and update the modelValue with the provided value.
You can prevent this behavior by preventing default @select.prevent.
<script setup lang="ts">
import { AComboboxContent, AComboboxInput, AComboboxItem, AComboboxPortal, AComboboxRoot } from 'akar';
</script>
<template>
<AComboboxRoot>
<AComboboxInput />
<AComboboxPortal>
<AComboboxContent>
<AComboboxItem @select.prevent>
Item A
</AComboboxItem>
…
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
ACombobox items must be filtered manually before passing them over to the virtualizer.
See the virtualization guide for more general info on virtualization.
<script setup lang="ts">
import { AComboboxContent, AComboboxInput, AComboboxItem, AComboboxPortal, AComboboxRoot, AComboboxViewport, AComboboxVirtualizer, useFilter } from 'akar';
import { computed, ref } from 'vue';
const people = Array.from({ length: 100000 }).map((_, id) => ({ id, name: `Person #${id}` }));
const selectedPeople = ref(people[0]);
const searchTerm = ref('');
const { contains } = useFilter({ sensitivity: 'base' });
const filteredPeople = computed(() => people.filter((p) => contains(p.name, searchTerm.value)));
</script>
<template>
<AComboboxRoot v-model="selectedPeople">
<AComboboxInput v-model="searchTerm" />
<AComboboxPortal>
<AComboboxContent class="max-h-[40vh] overflow-hidden">
<AComboboxViewport>
<AComboboxVirtualizer
v-slot="{ option }"
:options="filteredPeople"
:text-content="(x) => x.name"
:estimate-size="24"
>
<AComboboxItem :value="option">
{{ option.name }}
</AComboboxItem>
</AComboboxVirtualizer>
</AComboboxViewport>
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
Adheres to the ACombobox WAI-ARIA design pattern.
See the W3C ACombobox Autocomplete List example for more information.
| Key | Description |
|---|---|
Enter | When focus is on |
ArrowDown | When focus is on |
ArrowUp | When focus is on |
Esc | Closes ACombobox and restores the selected item in the |
Create your own API by abstracting the primitive parts into your own component.
ACombobox can be use to build your own Command Menu.
<script setup lang="ts">
import { Command, CommandItem } from './your-command';
</script>
<template>
<Command>
<CommandItem value="1">
Item 1
</CommandItem>
<CommandItem value="2">
Item 2
</CommandItem>
<CommandItem value="3">
Item 3
</CommandItem>
</Command>
</template>
// your-command.ts
export { default as Command } from 'Command.vue';
export { default as CommandItem } from 'CommandItem.vue';
<!-- Command.vue -->
<script setup lang="ts">
import type { AComboboxRootEmits, AComboboxRootProps } from 'akar';
import { AComboboxContent, AComboboxInput, AComboboxPortal, AComboboxRoot, useForwardPropsEmits } from 'akar';
const props = defineProps<AComboboxRootProps>();
const emits = defineEmits<AComboboxRootEmits>();
const forward = useForwardPropsEmits(props, emits);
</script>
<template>
<AComboboxRoot
v-bind="forward"
:open="true"
model-value=""
>
<AComboboxInput placeholder="Type a command or search…" />
<AComboboxPortal>
<AComboboxContent
@escape-key-down.prevent
@focus-outside.prevent
@interact-outside.prevent
@pointer-down-outside.prevent
>
<AComboboxViewport>
<slot />
</AComboboxViewport>
</AComboboxContent>
</AComboboxPortal>
</AComboboxRoot>
</template>
<!-- AComboboxItem.vue -->
<script setup lang="ts">
import type { AComboboxItemProps } from 'akar';
import { AComboboxItem } from 'akar';
const props = defineProps<AComboboxItemProps>();
</script>
<template>
<AComboboxItem
v-bind="props"
@select.prevent
>
<slot />
</AComboboxItem>
</template>