Combobox
Autocomplete input with a list of suggestions.
Preview
Installation
npx sigma-ui@latest add comboboxUsage
<script setup lang="ts">
import { Combobox, ComboboxAnchor, ComboboxEmpty, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxList } from '@/components/ui/combobox';
</script>
<template>
<Combobox>
<ComboboxAnchor>
<ComboboxInput placeholder="Select a framework..." />
</ComboboxAnchor>
<ComboboxList>
<ComboboxEmpty>No framework found.</ComboboxEmpty>
<ComboboxGroup>
<ComboboxItem value="nuxt">
Nuxt
</ComboboxItem>
</ComboboxGroup>
</ComboboxList>
</Combobox>
</template>- Bind the selection with
v-model. bycompares objects by a key, for exampleby="label".- Use
ComboboxTriggerwhen the field should open from a button instead of the input.
Combobox or Autocomplete
Use Combobox when the value must be one of the options, such as a framework or a status. Typing only filters the list, and the value is the selected option. Use Autocomplete when any text is a valid answer and the options are only suggestions. Its value is the typed string.
Examples
Basic
Trigger
API Reference
Combobox
Props
| Prop | Type | Default |
|---|---|---|
openThe controlled open state of the Combobox. Can be binded with | boolean | - |
defaultOpenThe open state of the combobox when it is initially rendered. <br> Use when you do not need to control its open state. | boolean | - |
resetSearchTermOnBlurWhether to reset the searchTerm when the Combobox input blurred | boolean | `true` |
resetSearchTermOnSelectWhether to reset the searchTerm when the Combobox value is selected | boolean | `true` |
openOnFocusWhether to open the combobox when the input is focused | boolean | `false` |
openOnClickWhether to open the combobox when the input is clicked | boolean | `false` |
ignoreFilterWhen | boolean | - |
resetModelValueOnClearWhen | boolean | - |
unmountOnHideWhen set to | boolean | true |
multipleWhether multiple options can be selected or not. | boolean | - |
disabledWhen | boolean | - |
dirThe reading direction of the listbox when applicable. <br> If omitted, inherits globally from | Direction | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
modelValueThe controlled value of the listbox. Can be binded with | AcceptableValue | AcceptableValue[] | - |
defaultValueThe value of the listbox when initially rendered. Use when you do not need to control the state of the Listbox | AcceptableValue | AcceptableValue[] | - |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
highlightOnHoverWhen | boolean | - |
loopWhen | boolean | - |
byUse this to compare objects by a particular field, or pass your own comparison function for complete control over how objects are compared. | string | ((a: AcceptableValue, b: AcceptableValue) => boolean) | - |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value changes. | [value: AcceptableValue] |
update:openEvent handler called when the open state of the combobox changes. | [value: boolean] |
highlightEvent handler when highlighted element changes. | [payload: { ref: HTMLElement; value: AcceptableValue; }] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ComboboxAnchor
Props
| Prop | Type | Default |
|---|---|---|
referenceThe reference (or anchor) element that is being referred to for positioning. If not provided will use the current component as anchor. | ReferenceElement | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ComboboxEmpty
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ComboboxGroup
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
headingLabel shown above the group items. | string | - |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ComboboxInput
Props
| Prop | Type | Default |
|---|---|---|
displayValueThe display value of input for selected item. Does not work with | ((val: any) => string) | - |
modelValueThe controlled value of the filter. Can be binded with v-model. | string | - |
autoFocusFocus on element when mounted. | boolean | - |
disabledWhen | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Events
| Event | Payload |
|---|---|
update:modelValue | [string] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ComboboxItem
Props
| Prop | Type | Default |
|---|---|---|
textValueA string representation of the item contents. If the children are not plain text, then the | string | - |
valuerequiredThe value given as data when submitted with a | AcceptableValue | - |
disabledWhen | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Events
| Event | Payload |
|---|---|
selectEvent handler called when the selecting item. <br> It can be prevented by calling | [event: SelectEvent$3<AcceptableValue>] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ComboboxList
Props
| Prop | Type | Default |
|---|---|---|
forceMountUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | boolean | - |
positionThe positioning mode to use, <br>
| "popper" | "inline" | "popper" |
bodyLockThe document.body will be lock, and scrolling will be disabled. | boolean | - |
hideWhenEmptyWhen | boolean | false |
memoDependenciesReactive dependencies that should invalidate the memoized content subtree. | unknown[] | - |
sideThe preferred side of the trigger to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled. | "top" | "right" | "bottom" | "left" | "bottom" |
sideOffsetThe distance in pixels from the trigger. | number | 4 |
sideFlipFlip to the opposite side when colliding with boundary. | boolean | true |
alignThe preferred alignment against the trigger. May change when collisions occur. | "center" | "start" | "end" | "center" |
alignOffsetAn offset in pixels from the | number | 0 |
alignFlipFlip alignment when colliding with boundary.
May only occur when | boolean | true |
avoidCollisionsWhen | boolean | true |
collisionBoundaryThe 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. | Element | (Element | null)[] | null | [] |
collisionPaddingThe 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 }. | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> | 0 |
arrowPaddingThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. | number | 0 |
hideShiftedArrowWhen | boolean | true |
stickyThe sticky behavior on the align axis. | "partial" | "always" | "partial" |
hideWhenDetachedWhether to hide the content when the trigger becomes fully occluded. | boolean | false |
positionStrategyThe type of CSS position property to use. | "absolute" | "fixed" | - |
updatePositionStrategyStrategy to update the position of the floating element on every animation frame. | "always" | "optimized" | 'optimized' |
disableUpdateOnLayoutShiftWhether to disable the update position for the content when the layout shifted. | boolean | false |
prioritizePositionForce content to be position within the viewport. Might overlap the reference element, which may not be desired. | boolean | false |
referenceThe custom element or virtual element that will be set as the reference to position the floating element. If provided, it will replace the default anchor element. | ReferenceElement | - |
dirThe reading direction of the popper content when applicable. <br> If omitted, inherits globally from | Direction | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
disableOutsidePointerEventsWhen | boolean | - |
Events
| Event | Payload |
|---|---|
escapeKeyDownEvent handler called when the escape key is down. Can be prevented. | [event: KeyboardEvent] |
pointerDownOutsideEvent handler called when a | [event: PointerDownOutsideEvent] |
focusOutsideEvent handler called when the focus moves outside of the | [event: FocusOutsideEvent] |
interactOutsideEvent handler called when an interaction happens outside the | [event: PointerDownOutsideEvent | FocusOutsideEvent] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ComboboxSeparator
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Follows the Combobox WAI-ARIA design pattern. Reka UI wires up the input, listbox, and active descendant.
| Key | Description |
|---|---|
| Tab | Moves focus to the input. |
| ArrowDown | Opens the list and moves to the next option. |
| ArrowUp | Moves to the previous option. |
| Enter | Selects the focused option. |
| Escape | Closes the list. |
| Home | Moves to the first option. |
| End | Moves to the last option. |