Usage
Use the v-model directive to control the value of the Select or the default-value prop to set the initial value when you do not need to control its state.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" :items="items" />
</template>
Items
Use the items prop as an array of strings, numbers or booleans:
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" :items="items" class="w-48" />
</template>
You can also pass an array of objects with the following properties:
label?: stringvalue?: stringtype?: "label" | "separator" | "item"icon?: stringavatar?: AvatarPropschip?: ChipPropsdisabled?: booleanclass?: anyui?: { label?: ClassNameValue, separator?: ClassNameValue, item?: ClassNameValue, itemLeadingIcon?: ClassNameValue, itemLeadingAvatarSize?: ClassNameValue, itemLeadingAvatar?: ClassNameValue, itemLeadingChipSize?: ClassNameValue, itemLeadingChip?: ClassNameValue, itemLabel?: ClassNameValue, itemTrailing?: ClassNameValue, itemTrailingIcon?: ClassNameValue }
<script setup lang="ts">
import type { SelectItem } from '@nuxt/ui'
const items = ref<SelectItem[]>([
{
label: 'Backlog',
value: 'backlog'
},
{
label: 'Todo',
value: 'todo'
},
{
label: 'In Progress',
value: 'in_progress'
},
{
label: 'Done',
value: 'done'
}
])
const value = ref('backlog')
</script>
<template>
<USelect v-model="value" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { SelectItem } from '@nuxt/ui'
const items = ref<SelectItem[]>([
{
label: 'Backlog',
value: 'backlog'
},
{
label: 'Todo',
value: 'todo'
},
{
label: 'In Progress',
value: 'in_progress'
},
{
label: 'Done',
value: 'done'
}
])
const value = ref('backlog')
</script>
<template>
<USelect v-model="value" :items="items" class="w-48" />
</template>
value property of the object in the v-model directive or the default-value prop.You can also pass an array of arrays to the items prop to display separated groups of items.
<script setup lang="ts">
const items = ref([
['Apple', 'Banana', 'Blueberry', 'Grapes', 'Pineapple'],
['Aubergine', 'Broccoli', 'Carrot', 'Courgette', 'Leek']
])
const value = ref('Apple')
</script>
<template>
<USelect v-model="value" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref([
['Apple', 'Banana', 'Blueberry', 'Grapes', 'Pineapple'],
['Aubergine', 'Broccoli', 'Carrot', 'Courgette', 'Leek']
])
const value = ref('Apple')
</script>
<template>
<USelect v-model="value" :items="items" class="w-48" />
</template>
Value Key
You can change the property that is used to set the value by using the value-key prop. Defaults to value.
<script setup lang="ts">
import type { SelectItem } from '@nuxt/ui'
const items = ref<SelectItem[]>([
{
label: 'Backlog',
id: 'backlog'
},
{
label: 'Todo',
id: 'todo'
},
{
label: 'In Progress',
id: 'in_progress'
},
{
label: 'Done',
id: 'done'
}
])
const value = ref('backlog')
</script>
<template>
<USelect v-model="value" value-key="id" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { SelectItem } from '@nuxt/ui'
const items = ref<SelectItem[]>([
{
label: 'Backlog',
id: 'backlog'
},
{
label: 'Todo',
id: 'todo'
},
{
label: 'In Progress',
id: 'in_progress'
},
{
label: 'Done',
id: 'done'
}
])
const value = ref('backlog')
</script>
<template>
<USelect v-model="value" value-key="id" :items="items" class="w-48" />
</template>
Multiple
Use the multiple prop to allow multiple selections, the selected items will be separated by a comma in the trigger.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref(['Backlog', 'Todo'])
</script>
<template>
<USelect v-model="value" multiple :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref(['Backlog', 'Todo'])
</script>
<template>
<USelect v-model="value" multiple :items="items" class="w-48" />
</template>
default-value prop or the v-model directive.Placeholder
Use the placeholder prop to set a placeholder text.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
</script>
<template>
<USelect placeholder="Select status" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
</script>
<template>
<USelect placeholder="Select status" :items="items" class="w-48" />
</template>
Content
Use the content prop to control how the Select content is rendered, like its align or side for example.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect
v-model="value"
:content="{
align: 'center',
side: 'bottom',
sideOffset: 8
}"
:items="items"
class="w-48"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect
v-model="value"
:content="{
align: 'center',
side: 'bottom',
sideOffset: 8
}"
:items="items"
class="w-48"
/>
</template>
Arrow
Use the arrow prop to display an arrow on the Select.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" arrow :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" arrow :items="items" class="w-48" />
</template>
Color
Use the color prop to change the ring color when the Select is focused.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" color="neutral" highlight :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" color="neutral" highlight :items="items" class="w-48" />
</template>
highlight prop is used here to show the focus state. It's used internally when a validation error occurs.Variant
Use the variant prop to change the variant of the Select.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" color="neutral" variant="subtle" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" color="neutral" variant="subtle" :items="items" class="w-48" />
</template>
Size
Use the size prop to change the size of the Select.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" size="xl" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" size="xl" :items="items" class="w-48" />
</template>
Icon
Use the icon prop to show an Icon inside the Select.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" icon="i-lucide-search" size="md" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" icon="i-lucide-search" size="md" :items="items" class="w-48" />
</template>
Trailing Icon
Use the trailing-icon prop to customize the trailing Icon. Defaults to i-lucide-chevron-down.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect
v-model="value"
trailing-icon="i-lucide-arrow-down"
size="md"
:items="items"
class="w-48"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect
v-model="value"
trailing-icon="i-lucide-arrow-down"
size="md"
:items="items"
class="w-48"
/>
</template>
Selected Icon
Use the selected-icon prop to customize the icon when an item is selected. Defaults to i-lucide-check.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" selected-icon="i-lucide-flame" size="md" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" selected-icon="i-lucide-flame" size="md" :items="items" class="w-48" />
</template>
Avatar
Use the avatar prop to show an Avatar inside the Select.
<script setup lang="ts">
const items = ref(['Nuxt', 'NuxtHub', 'NuxtLabs', 'Nuxt Modules', 'Nuxt Community'])
const value = ref('Nuxt')
</script>
<template>
<USelect
v-model="value"
:avatar="{
src: 'https://github.com/nuxt.png',
loading: 'lazy'
}"
:items="items"
class="w-48"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Nuxt', 'NuxtHub', 'NuxtLabs', 'Nuxt Modules', 'Nuxt Community'])
const value = ref('Nuxt')
</script>
<template>
<USelect
v-model="value"
:avatar="{
src: 'https://github.com/nuxt.png',
loading: 'lazy'
}"
:items="items"
class="w-48"
/>
</template>
Badge
Use the badge prop to show a Badge inside the Select.
<script setup lang="ts">
import type { SelectItem } from '@nuxt/ui'
const items = ref<SelectItem[]>([
{
label: 'Backlog',
id: 'backlog',
badge: {
label: '4',
color: 'error',
variant: 'soft'
}
},
{
label: 'Todo',
id: 'todo',
badge: {
label: '2',
color: 'warning',
variant: 'soft'
}
},
{
label: 'In Progress',
id: 'in_progress',
badge: {
label: '1',
color: 'info',
variant: 'soft'
}
},
{
label: 'Done',
id: 'done',
badge: {
label: '0',
color: 'success',
variant: 'soft'
}
}
])
const value = ref('backlog')
</script>
<template>
<USelect v-model="value" value-key="id" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { SelectItem } from '@nuxt/ui'
const items = ref<SelectItem[]>([
{
label: 'Backlog',
id: 'backlog',
badge: {
label: '4',
color: 'error',
variant: 'soft'
}
},
{
label: 'Todo',
id: 'todo',
badge: {
label: '2',
color: 'warning',
variant: 'soft'
}
},
{
label: 'In Progress',
id: 'in_progress',
badge: {
label: '1',
color: 'info',
variant: 'soft'
}
},
{
label: 'Done',
id: 'done',
badge: {
label: '0',
color: 'success',
variant: 'soft'
}
}
])
const value = ref('backlog')
</script>
<template>
<USelect v-model="value" value-key="id" :items="items" class="w-48" />
</template>
Loading
Use the loading prop to show a loading icon on the Select.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" loading :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" loading :items="items" class="w-48" />
</template>
Loading Icon
Use the loading-icon prop to customize the loading icon. Defaults to i-lucide-loader-circle.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" loading loading-icon="i-lucide-loader" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect v-model="value" loading loading-icon="i-lucide-loader" :items="items" class="w-48" />
</template>
Disabled
Use the disabled prop to disable the Select.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
</script>
<template>
<USelect disabled placeholder="Select status" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
</script>
<template>
<USelect disabled placeholder="Select status" :items="items" class="w-48" />
</template>
Examples
With items type
You can use the type property with separator to display a separator between items or label to display a label.
<script setup lang="ts">
import type { SelectItem } from '@nuxt/ui'
const items = ref<SelectItem[]>([
{
type: 'label',
label: 'Fruits'
},
'Apple',
'Banana',
'Blueberry',
'Grapes',
'Pineapple',
{
type: 'separator'
},
{
type: 'label',
label: 'Vegetables'
},
'Aubergine',
'Broccoli',
'Carrot',
'Courgette',
'Leek'
])
const value = ref('Apple')
</script>
<template>
<USelect v-model="value" :items="items" class="w-48" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { SelectItem } from '@nuxt/ui'
const items = ref<SelectItem[]>([
{
type: 'label',
label: 'Fruits'
},
'Apple',
'Banana',
'Blueberry',
'Grapes',
'Pineapple',
{
type: 'separator'
},
{
type: 'label',
label: 'Vegetables'
},
'Aubergine',
'Broccoli',
'Carrot',
'Courgette',
'Leek'
])
const value = ref('Apple')
</script>
<template>
<USelect v-model="value" :items="items" class="w-48" />
</template>
With icon in items
You can use the icon property to display an Icon inside the items.
<script setup lang="ts">
import type { SelectItem } from '@nuxt/ui'
const items = ref([
{
label: 'Backlog',
value: 'backlog',
icon: 'i-lucide-circle-help'
},
{
label: 'Todo',
value: 'todo',
icon: 'i-lucide-circle-plus'
},
{
label: 'In Progress',
value: 'in_progress',
icon: 'i-lucide-circle-arrow-up'
},
{
label: 'Done',
value: 'done',
icon: 'i-lucide-circle-check'
}
] satisfies SelectItem[])
const value = ref(items.value[0]?.value)
const icon = computed(() => items.value.find(item => item.value === value.value)?.icon)
</script>
<template>
<USelect v-model="value" :items="items" value-key="value" :icon="icon" class="w-48" />
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import type { SelectItem } from '@nuxt/ui'
const items = ref([
{
label: 'Backlog',
value: 'backlog',
icon: 'i-lucide-circle-help'
},
{
label: 'Todo',
value: 'todo',
icon: 'i-lucide-circle-plus'
},
{
label: 'In Progress',
value: 'in_progress',
icon: 'i-lucide-circle-arrow-up'
},
{
label: 'Done',
value: 'done',
icon: 'i-lucide-circle-check'
}
] satisfies SelectItem[])
const value = ref(items.value[0]?.value)
const icon = computed(() => items.value.find(item => item.value === value.value)?.icon)
</script>
<template>
<USelect v-model="value" :items="items" value-key="value" :icon="icon" class="w-48" />
</template>
value property of the selected item.#leading slot to display the selected icon.With avatar in items
You can use the avatar property to display an Avatar inside the items.
<script setup lang="ts">
import type { SelectItem } from '@nuxt/ui'
const items = ref([
{
label: 'benjamincanac',
value: 'benjamincanac',
avatar: {
src: 'https://github.com/benjamincanac.png',
alt: 'benjamincanac',
loading: 'lazy' as const
}
},
{
label: 'romhml',
value: 'romhml',
avatar: {
src: 'https://github.com/romhml.png',
alt: 'romhml',
loading: 'lazy' as const
}
},
{
label: 'noook',
value: 'noook',
avatar: {
src: 'https://github.com/noook.png',
alt: 'noook',
loading: 'lazy' as const
}
},
{
label: 'sandros94',
value: 'sandros94',
avatar: {
src: 'https://github.com/sandros94.png',
alt: 'sandros94',
loading: 'lazy' as const
}
}
] satisfies SelectItem[])
const value = ref(items.value[0]?.value)
const avatar = computed(() => items.value.find(item => item.value === value.value)?.avatar)
</script>
<template>
<USelect v-model="value" :items="items" value-key="value" :avatar="avatar" class="w-48" />
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import type { SelectItem } from '@nuxt/ui'
const items = ref([
{
label: 'benjamincanac',
value: 'benjamincanac',
avatar: {
src: 'https://github.com/benjamincanac.png',
alt: 'benjamincanac',
loading: 'lazy' as const
}
},
{
label: 'romhml',
value: 'romhml',
avatar: {
src: 'https://github.com/romhml.png',
alt: 'romhml',
loading: 'lazy' as const
}
},
{
label: 'noook',
value: 'noook',
avatar: {
src: 'https://github.com/noook.png',
alt: 'noook',
loading: 'lazy' as const
}
},
{
label: 'sandros94',
value: 'sandros94',
avatar: {
src: 'https://github.com/sandros94.png',
alt: 'sandros94',
loading: 'lazy' as const
}
}
] satisfies SelectItem[])
const value = ref(items.value[0]?.value)
const avatar = computed(() => items.value.find(item => item.value === value.value)?.avatar)
</script>
<template>
<USelect v-model="value" :items="items" value-key="value" :avatar="avatar" class="w-48" />
</template>
With badge in items
You can use the badge property to display a Badge inside the items.
<script setup lang="ts">
import type { SelectItem, BadgeProps } from '@nuxt/ui'
const items = ref([
{
label: 'bug',
value: 'bug',
badge: {
label: '4',
color: 'error'
}
},
{
label: 'feature',
value: 'feature',
badge: {
label: '2',
color: 'success'
}
},
{
label: 'enhancement',
value: 'enhancement',
badge: {
label: '1',
color: 'info'
}
}
] satisfies SelectItem[])
const value = ref(items.value[0]?.value)
function getBadge(value: string) {
return items.value.find(item => item.value === value)?.badge
}
</script>
<template>
<USelect v-model="value" :items="items" value-key="value" class="w-48">
<template #leading="{ modelValue, ui }">
<UBadge
v-if="modelValue"
variant="soft"
v-bind="getBadge(modelValue)"
:size="(ui.itemBadgeSize() as BadgeProps['size'])"
:class="ui.itemBadge()"
/>
</template>
</USelect>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { SelectItem, BadgeProps } from '@nuxt/ui'
const items = ref([
{
label: 'bug',
value: 'bug',
badge: {
label: '4',
color: 'error'
}
},
{
label: 'feature',
value: 'feature',
badge: {
label: '2',
color: 'success'
}
},
{
label: 'enhancement',
value: 'enhancement',
badge: {
label: '1',
color: 'info'
}
}
] satisfies SelectItem[])
const value = ref(items.value[0]?.value)
function getBadge(value: string) {
return items.value.find(item => item.value === value)?.badge
}
</script>
<template>
<USelect v-model="value" :items="items" value-key="value" class="w-48">
<template #leading="{ modelValue, ui }">
<UBadge
v-if="modelValue"
variant="soft"
v-bind="getBadge(modelValue)"
:size="(ui.itemBadgeSize() as BadgeProps['size'])"
:class="ui.itemBadge()"
/>
</template>
</USelect>
</template>