<BaseAutocomplete /> ยท An interactive search box.
<template>
<BaseAutocomplete
v-model="fields.first"
placeholder="Ex: nuxt"
>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</template>
<script setup lang="ts">
const fields = reactive({
first: '',
})
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
</script>
This component has a default slot that can be used to add items, labels, groups of items, and separators. You can customize the autocomplete's visual style by using the available props.
<template>
<BaseAutocomplete>
<BaseAutocompleteItem>
<!-- Your content here -->
</BaseAutocompleteItem>
</BaseAutocomplete>
</template>
This component has props that you can use to modify its visual style and behavior.
| Model | Type |
|---|---|
model-value | AcceptableValue | AcceptableValue[]The controlled value of the listbox. Can be binded with with `v-model`. |
| Prop | Type |
|---|---|
querydefault: - | stringThe controlled value of the filter. |
itemsdefault: [] | BaseAutocompleteItemProps<AcceptableValue>[]Items to display in the autocomplete list instead of slots. |
variantdefault: "default" | "default" | "muted" | "none"The variant of the autocomplete |
roundeddefault: "md" | "none" | "sm" | "md" | "lg" | "full"The radius of the component. |
sizedefault: "md" | "sm" | "md" | "lg" | "xl"The size of the autocomplete component. |
clearabledefault: - | booleanDisplay the clear button to reset the query. |
presetdefault: "popper" | "inline" | "popper"Bindings presets |
bindingsdefault: {} | { anchor?: ComboboxAnchorProps; trigger?: ComboboxTriggerProps; portal?: ComboboxPortalProps; content?: ComboboxContentProps; viewport?: ComboboxViewportProps; empty?: ComboboxEmptyProps; }Optional bindings to pass to the inner components. |
classesdefault: {} | { root?: string | string[]; anchor?: string | string[]; cancel?: string | string[]; trigger?: string | string[]; content?: string | string[]; viewport?: string | ... 1 more ...; empty?: string | ... 1 more ...; }Optional classes to pass to the inner components. |
opendefault: - | booleanThe controlled open state of the Combobox. Can be binded with with `v-model:open`. |
default-opendefault: - | booleanThe open state of the combobox when it is initially rendered. Use when you do not need to control its open state. |
reset-search-term-on-blurdefault: - | booleanWhether to reset the searchTerm when the Combobox input blurred |
reset-search-term-on-selectdefault: - | booleanWhether to reset the searchTerm when the Combobox value is selected |
ignore-filterdefault: - | booleanWhen `true`, disable the default filters |
default-valuedefault: - | AcceptableValue | AcceptableValue[]The value of the listbox when initially rendered. Use when you do not need to control the state of the Listbox |
multipledefault: - | booleanWhether multiple options can be selected or not. |
dirdefault: - | DirectionThe reading direction of the listbox when applicable. If omitted, inherits globally from `ConfigProvider` or assumes LTR (left-to-right) reading mode. |
disableddefault: - | booleanWhen `true`, prevents the user from interacting with listbox |
highlight-on-hoverdefault: - | booleanWhen `true`, hover over item will trigger highlight |
bydefault: - | 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. |
as-childdefault: - | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
asdefault: - | AsTag | ComponentThe element or component this component should render as. Can be overwritten by `asChild`. |
namedefault: - | stringThe name of the field. Submitted with its owning form as part of a name/value pair. |
requireddefault: - | booleanWhen `true`, indicates that the user must set the value before the owning form can be submitted. |
| Event | Emitted Value Type |
|---|---|
update:query | [value: string] |
highlight | [payload: { ref: HTMLElement; value: AcceptableValue; } | undefined] |
update:open | [value: boolean] |
| Slot | Type |
|---|---|
#default | any |
#empty | { open: boolean; query: string; modelValue: AcceptableValue | AcceptableValue[]; } |
#content-start | { open: boolean; query: string; modelValue: AcceptableValue | AcceptableValue[]; } |
#content-end | { open: boolean; query: string; modelValue: AcceptableValue | AcceptableValue[]; } |
#viewport-start | { open: boolean; query: string; modelValue: AcceptableValue | AcceptableValue[]; } |
#viewport-end | { open: boolean; query: string; modelValue: AcceptableValue | AcceptableValue[]; } |
| Prop | Type |
|---|---|
as-childdefault: - | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
asdefault: - | AsTag | ComponentThe element or component this component should render as. Can be overwritten by `asChild`. |
| Slot | Type |
|---|---|
#default | any |
| Prop | Type |
|---|---|
text-valuedefault: - | stringA string representation of the item contents. If the children are not plain text, then the `textValue` prop must also be set to a plain text representation, which will be used for autocomplete in the ComboBox. |
valuedefault: - | AcceptableValueThe value given as data when submitted with a `name`. |
disableddefault: - | booleanWhen `true`, prevents the user from interacting with the item. |
as-childdefault: - | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
asdefault: - | AsTag | ComponentThe element or component this component should render as. Can be overwritten by `asChild`. |
| Event | Emitted Value Type |
|---|---|
select | [event: ListboxItemSelectEvent<AcceptableValue>] |
| Slot | Type |
|---|---|
#default | any |
| Prop | Type |
|---|---|
labeldefault: "" | stringThe label to display for the Autocomplete. |
fordefault: - | string |
as-childdefault: - | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
asdefault: - | AsTag | ComponentThe element or component this component should render as. Can be overwritten by `asChild`. |
| Slot | Type |
|---|---|
#default | any |
| Prop | Type |
|---|---|
as-childdefault: - | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
asdefault: - | AsTag | ComponentThe element or component this component should render as. Can be overwritten by `asChild`. |
Your can override the component default CSS variables in your main.css file.
@theme {
/* Default input variables */
--color-input-default-border: var(--color-muted-300);
--color-input-default-bg: var(--color-white);
--color-input-default-text: var(--color-muted-600);
--color-input-default-placeholder: var(--color-muted-300);
--color-input-default-button-bg: var(--color-muted-100);
--color-input-default-button-bg-active: var(--color-muted-200);
--color-input-default-button-text: var(--color-muted-700);
/* Muted input variables */
--color-input-muted-border: var(--color-muted-300);
--color-input-muted-bg: var(--color-muted-50);
--color-input-muted-text: var(--color-muted-600);
--color-input-muted-placeholder: var(--color-muted-300);
--color-input-muted-button-bg: var(--color-muted-200);
--color-input-muted-button-bg-active: var(--color-muted-300);
--color-input-muted-button-text: var(--color-muted-700);
}
Use the size prop to change the size of the autocomplete.
<template>
<BaseAutocomplete
v-model="fields.second"
size="md"
placeholder="Ex: nuxt"
>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</template>
<script setup lang="ts">
const fields = reactive({
first: '',
})
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
</script>
Use the variant prop to change the contrast of the autocomplete.
<template>
<BaseAutocomplete
v-model="fields.second"
variant="muted"
placeholder="Ex: nuxt"
>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</template>
<script setup lang="ts">
const fields = reactive({
first: '',
})
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
</script>
Use the BaseAutocompleteGroup component to group items.
<template>
<BaseAutocomplete
v-model="fields.first"
rounded="md"
placeholder="Ex: nuxt"
>
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Frameworks
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
</BaseAutocomplete>
</template>
<script setup lang="ts">
const fields = reactive({
first: '',
})
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
const languages = [
'JavaScript',
'TypeScript',
'Python',
'Ruby',
'Java',
'C#',
'PHP',
'Go',
'Rust',
'Swift',
'Kotlin',
'Dart',
'Scala',
'Elixir',
'Clojure',
]
</script>
Use the available presets to quickly change the autocomplete's visual style.
<template>
<BaseAutocomplete preset="popper" placeholder="popper">
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Frameworks
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
</BaseAutocomplete>
<BaseAutocomplete preset="inline" placeholder="Inline">
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Frameworks
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
<BaseAutocompleteSeparator />
<BaseAutocompleteGroup>
<BaseAutocompleteLabel>
Languages
</BaseAutocompleteLabel>
<BaseAutocompleteItem v-for="item in languages" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocompleteGroup>
</BaseAutocomplete>
</template>
<script setup lang="ts">
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
const languages = [
'JavaScript',
'TypeScript',
'Python',
'Ruby',
'Java',
'C#',
'PHP',
'Go',
'Rust',
'Swift',
'Kotlin',
'Dart',
'Scala',
'Elixir',
'Clojure',
]
</script>
Use the multiple prop to be able to select multiple items at once.
<template>
<div class="flex items-center justify-center px-4 pb-0 pt-4">
<div class="w-full rounded-xl bg-muted-100 p-4 dark:bg-muted-900 md:p-6">
<div class="max-w-xs">
<BaseAutocomplete
v-model="multipleValue"
rounded="md"
placeholder="Ex: nuxt"
multiple
>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</div>
</div>
</div>
</template>
<script setup lang="ts">
const multipleValue = ref<string[]>(['Nuxt', 'Vue.js'])
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
</script>
Use the multiple prop to be able to select multiple items at once.
<template>
<div class="flex items-center justify-center px-4 pb-0 pt-4">
<div class="w-full rounded-xl bg-muted-100 p-4 dark:bg-muted-900 md:p-6">
<div class="max-w-xs">
<BaseAutocomplete
v-model="multiplePerson"
by="id"
rounded="md"
placeholder="Search..."
multiple
>
<BaseAutocompleteItem v-for="item in persons" :key="item.id" :value="item">
{{ item.name }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</div>
</div>
</div>
</template>
<script setup lang="ts">
const persons = [
{
id: 1,
name: 'Clarissa Perez',
text: 'Sales Manager',
media: 'https://tairo.cssninja.io/img/avatars/19.svg',
},
{
id: 2,
name: 'Aaron Splatter',
text: 'Project Manager',
media: 'https://tairo.cssninja.io/img/avatars/16.svg',
},
{
id: 3,
disabled: true,
name: 'Mike Miller',
text: 'UI/UX Designer',
media: 'https://tairo.cssninja.io/img/avatars/3.svg',
},
{
id: 4,
name: 'Benedict Kessler',
text: 'Mobile Developer',
media: 'https://tairo.cssninja.io/img/avatars/22.svg',
},
{
id: 5,
name: 'Maya Rosselini',
text: 'Product Manager',
media: 'https://tairo.cssninja.io/img/avatars/2.svg',
},
]
const multiplePerson = ref([persons[1]!])
</script>
Use the clearable prop to add a clear button to the autocomplete.
<template>
<div class="flex items-center justify-center px-4 pb-0 pt-4">
<div class="w-full rounded-xl bg-muted-100 p-4 dark:bg-muted-900 md:p-6">
<div class="max-w-xs">
<BaseAutocomplete
v-model="fields.first"
rounded="md"
placeholder="Ex: nuxt"
clearable
>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</div>
</div>
</div>
</template>
<script setup lang="ts">
const fields = reactive({
first: '',
})
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
</script>
Use the aria-invalid prop to indicate that the input has an error.
<template>
<div class="flex items-center justify-center px-4 pb-0 pt-4">
<div class="w-full rounded-xl bg-muted-100 p-4 dark:bg-muted-900 md:p-6">
<div class="max-w-xs">
<BaseAutocomplete
v-model="fields.first"
rounded="md"
placeholder="Ex: nuxt"
aria-invalid="true"
>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</div>
</div>
</div>
</template>
<script setup lang="ts">
const fields = reactive({
first: '',
})
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
</script>
Use the disabled prop to disable the autocomplete.
<template>
<div class="flex items-center justify-center px-4 pb-0 pt-4">
<div class="w-full rounded-xl bg-muted-100 p-4 dark:bg-muted-900 md:p-6">
<div class="max-w-xs">
<BaseAutocomplete
v-model="fields.first"
rounded="md"
placeholder="Ex: nuxt"
disabled
>
<BaseAutocompleteItem v-for="item in frameworks" :key="item" :value="item">
{{ item }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</div>
</div>
</div>
</template>
<script setup lang="ts">
const fields = reactive({
first: '',
})
const frameworks = [
'Nuxt',
'Vue.js',
'React.js',
'Angular',
'Alpine.js',
]
</script>
This component has multiple slots that you can use to customize how your items render and behave.
<template>
<div class="flex items-center justify-center px-4 pb-0 pt-4">
<div class="w-full rounded-xl bg-muted-100 p-4 dark:bg-muted-900 md:p-6">
<div class="max-w-xs">
<BaseAutocomplete
placeholder="Hide create prompt"
>
<template #empty>
<BaseCard variant="muted">
#empty
</BaseCard>
</template>
<template #viewport-start="{ query }">
<BaseCard variant="muted">
#viewport-start { {{ query }} }
</BaseCard>
</template>
<template #viewport-end>
<BaseCard variant="muted">
#viewport-end
</BaseCard>
</template>
<template #content-start>
<BaseCard>
#content-start
</BaseCard>
</template>
<template #content-end>
<BaseCard>
#content-end
</BaseCard>
</template>
<BaseAutocompleteItem v-for="item in persons" :key="item.id" :value="item">
{{ item.name }}
</BaseAutocompleteItem>
</BaseAutocomplete>
</div>
</div>
</div>
</template>
<script setup lang="ts">
const persons = [
{
id: 1,
name: 'Clarissa Perez',
text: 'Sales Manager',
media: 'https://tairo.cssninja.io/img/avatars/19.svg',
},
{
id: 2,
name: 'Aaron Splatter',
text: 'Project Manager',
media: 'https://tairo.cssninja.io/img/avatars/16.svg',
},
{
id: 3,
disabled: true,
name: 'Mike Miller',
text: 'UI/UX Designer',
media: 'https://tairo.cssninja.io/img/avatars/3.svg',
},
{
id: 4,
name: 'Benedict Kessler',
text: 'Mobile Developer',
media: 'https://tairo.cssninja.io/img/avatars/22.svg',
},
{
id: 5,
name: 'Maya Rosselini',
text: 'Product Manager',
media: 'https://tairo.cssninja.io/img/avatars/2.svg',
},
]
</script>