select
Select component with grouped options and labels
Select component with grouped options and labels
Загрузка превью…
src/select/c-select-3.vue
<script setup lang="ts">
import { Field } from "@/components/ui/field"
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue } from "@/components/ui/select"
const fruits = [
{ label: "Apple", value: "apple" },
{ label: "Banana", value: "banana" },
{ label: "Blueberry", value: "blueberry" },
]
const vegetables = [
{ label: "Carrot", value: "carrot" },
{ label: "Broccoli", value: "broccoli" },
{ label: "Spinach", value: "spinach" },
]
</script>
<template>
<Field class="max-w-xs">
<Select>
<SelectTrigger>
<SelectValue placeholder="Select an option" />
</SelectTrigger>
<SelectContent position="popper">
<SelectGroup>
<SelectLabel>Fruits</SelectLabel>
<SelectItem v-for="item in fruits" :key="item.value" :value="item.value">
{{ item.label }}
</SelectItem>
</SelectGroup>
<SelectSeparator />
<SelectGroup>
<SelectLabel>Vegetables</SelectLabel>
<SelectItem v-for="item in vegetables" :key="item.value" :value="item.value">
{{ item.label }}
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</Field>
</template>