Select
Select (셀렉트)
Select 컴포넌트는 옵션 목록에서 하나를 선택하는 셀렉트 요소예요. v-model로 값을 제어하고 다양한 변형, 크기, 아이콘 등을 지원해요.
출처: Nuxt UI
본문
사용법 (Usage)
v-model 지시자로 Select의 값을 제어하거나, 상태를 제어할 필요가 없을 때는 default-value prop으로 초기값을 설정할 수 있어요.
<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>
항목 (Items)
문자열, 숫자 또는 불리언의 배열로 items prop을 사용할 수 있어요:
<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>
다음 속성을 가진 객체 배열도 전달할 수 있어요:
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>
[!CAUTION]
객체를 사용할 때는
v-model지시자 또는default-valueprop에서 객체의value속성을 참조해야 해요.
items prop에 배열의 배열을 전달해 구분된 항목 그룹을 표시할 수도 있어요.
<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>
값 키 (Value Key)
value-key prop으로 값을 설정하는 데 사용할 속성을 변경할 수 있어요. 기본값은 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>
다중 선택 (Multiple)
multiple prop으로 여러 항목을 선택할 수 있어요. 선택된 항목은 트리거에서 쉼표로 구분되어 표시돼요.
<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>
[!CAUTION]
default-valueprop 또는v-model지시자에 배열을 전달해야 해요.
플레이스홀더 (Placeholder)
placeholder prop으로 플레이스홀더 텍스트를 설정할 수 있어요.
<script setup lang="ts">
const items = ref([
"Backlog",
"Todo",
"In Progress",
"Done"
])
</script>
<template>
<USelect placeholder="Select status" :items="items" class="w-48" />
</template>
콘텐츠 (Content)
content prop으로 Select 콘텐츠가 렌더링되는 방식을 제어할 수 있어요. 예를 들어 align이나 side를 지정할 수 있어요.
<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>
[!NOTE]
이 옵션은
content.position이popper(기본값)일 때만 적용돼요.
위치 (Position) 4.7+
content.position prop으로 트리거를 기준으로 Select 콘텐츠가 배치되는 방식을 제어할 수 있어요. 기본값은 popper로, 다른 팝오버처럼 콘텐츠를 배치해요. item-aligned로 설정하면 선택된 항목과 콘텐츠를 정렬해요(네이티브 macOS 메뉴와 비슷한 방식).
<script setup lang="ts">
const items = ref([
"Backlog",
"Todo",
"In Progress",
"Done"
])
const value = ref("Todo")
</script>
<template>
<USelect v-model="value" :content="{
position: 'item-aligned'
}" :items="items" class="w-48" />
</template>
화살표 (Arrow)
arrow prop으로 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>
색상 (Color)
color prop으로 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" highlight :items="items" class="w-48" />
</template>
[!NOTE]
여기서
highlightprop은 포커스 상태를 보여주기 위해 사용돼요. 검증 오류가 발생하면 내부적으로 사용돼요.
변형 (Variant)
variant prop으로 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" :highlight="false" :items="items" class="w-48" />
</template>
크기 (Size)
size prop으로 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>
아이콘 (Icon)
icon prop으로 Select 안에 Icon을 표시할 수 있어요.
<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>
트레일링 아이콘 (Trailing Icon)
trailing-icon prop으로 트레일링 Icon을 커스터마이즈할 수 있어요. 기본값은 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>
Nuxt:
[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme
이 아이콘은
app.config.ts의ui.icons.chevronDown키에서 전역으로 커스터마이즈할 수 있어요.
Vue:
[!TIP] See: /docs/getting-started/integrations/icons/vue#theme
이 아이콘은
vite.config.ts의ui.icons.chevronDown키에서 전역으로 커스터마이즈할 수 있어요.
선택 아이콘 (Selected Icon)
selected-icon prop으로 항목이 선택되었을 때의 아이콘을 커스터마이즈할 수 있어요. 기본값은 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>
Nuxt:
[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme
이 아이콘은
app.config.ts의ui.icons.check키에서 전역으로 커스터마이즈할 수 있어요.
Vue:
[!TIP] See: /docs/getting-started/integrations/icons/vue#theme
이 아이콘은
vite.config.ts의ui.icons.check키에서 전역으로 커스터마이즈할 수 있어요.
아바타 (Avatar)
avatar prop으로 Select 안에 Avatar를 표시할 수 있어요.
<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>
로딩 (Loading)
loading prop으로 Select에 로딩 아이콘을 표시할 수 있어요.
<script setup lang="ts">
const items = ref([
"Backlog",
"Todo",
"In Progress",
"Done"
])
const value = ref("Backlog")
</script>
<template>
<USelect v-model="value" loading :trailing="false" :items="items" class="w-48" />
</template>
로딩 아이콘 (Loading Icon)
loading-icon prop으로 로딩 아이콘을 커스터마이즈할 수 있어요. 기본값은 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>
Nuxt:
[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme
이 아이콘은
app.config.ts의ui.icons.loading키에서 전역으로 커스터마이즈할 수 있어요.
Vue:
[!TIP] See: /docs/getting-started/integrations/icons/vue#theme
이 아이콘은
vite.config.ts의ui.icons.loading키에서 전역으로 커스터마이즈할 수 있어요.
비활성화 (Disabled)
disabled prop으로 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>
예제 (Examples)
항목 타입 사용 (With items type)
separator와 함께 type 속성을 사용해 항목 사이에 구분선을 표시하거나, 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>
항목에 아이콘 사용 (With icon in items)
icon 속성으로 항목 안에 Icon을 표시할 수 있어요.
<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>
[!NOTE]
이 예제에서는 선택된 항목의
value속성에서 아이콘을 계산해요.
[!TIP]
#leading슬롯을 사용해 선택된 아이콘을 표시할 수도 있어요.
항목에 아바타 사용 (With avatar in items)
avatar 속성으로 항목 안에 Avatar를 표시할 수 있어요.
<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: 'HugoRCD',
value: 'HugoRCD',
avatar: {
src: 'https://github.com/HugoRCD.png',
alt: 'HugoRCD',
loading: 'lazy' as const
}
},
{
label: 'atinux',
value: 'atinux',
avatar: {
src: 'https://github.com/atinux.png',
alt: 'atinux',
loading: 'lazy' as const
}
},
{
label: 'romhml',
value: 'romhml',
avatar: {
src: 'https://github.com/romhml.png',
alt: 'romhml',
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>
[!NOTE]
이 예제에서는 선택된 항목의
value속성에서 아바타를 계산해요.
[!TIP]
#leading슬롯을 사용해 선택된 아바타를 표시할 수도 있어요.
항목에 칩 사용 (With chip in items)
chip 속성으로 항목 안에 Chip을 표시할 수 있어요.
<script setup lang="ts">
import type { SelectItem, ChipProps } from '@nuxt/ui'
const items = ref([
{
label: 'bug',
value: 'bug',
chip: {
color: 'error'
}
},
{
label: 'feature',
value: 'feature',
chip: {
color: 'success'
}
},
{
label: 'enhancement',
value: 'enhancement',
chip: {
color: 'info'
}
}
] satisfies SelectItem[])
const value = ref(items.value[0]?.value)
function getChip(value: string) {
return items.value.find(item => item.value === value)?.chip
}
</script>
<template>
<USelect v-model="value" :items="items" value-key="value" class="w-48">
<template #leading="{ modelValue, ui }">
<UChip
v-if="modelValue"
v-bind="getChip(modelValue)"
inset
standalone
:size="(ui.itemLeadingChipSize() as ChipProps['size'])"
:class="ui.itemLeadingChip()"
/>
</template>
</USelect>
</template>
[!NOTE]
이 예제에서는 선택된 칩을 표시하기 위해
#leading슬롯을 사용해요.
열림 상태 제어 (Control open state)
default-open prop 또는 v-model:open 지시자로 열림 상태를 제어할 수 있어요.
<script setup lang="ts">
const open = ref(false)
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
defineShortcuts({
o: () => open.value = !open.value
})
</script>
<template>
<USelect v-model="value" v-model:open="open" :items="items" class="w-48" />
</template>
[!NOTE]
이 예제에서는
defineShortcuts를 활용해O키를 눌러 Select를 토글할 수 있어요.
회전 아이콘 사용 (With rotating icon)
Select의 열림 상태를 나타내는 회전 아이콘 예제예요.
<script setup lang="ts">
const items = ref(['Backlog', 'Todo', 'In Progress', 'Done'])
const value = ref('Backlog')
</script>
<template>
<USelect
v-model="value"
:items="items"
:ui="{
trailingIcon: 'group-data-[state=open]:rotate-180 transition-transform duration-200'
}"
class="w-48"
/>
</template>
가져온 항목 사용 (With fetched items)
API에서 항목을 가져와 Select에서 사용할 수 있어요.
<script setup lang="ts">
import type { AvatarProps } from '@nuxt/ui'
const { data: users, status, execute } = await useLazyFetch('https://jsonplaceholder.typicode.com/users', {
key: 'typicode-users',
transform: (data: { id: number, name: string }[]) => {
return data?.map(user => ({
label: user.name,
value: String(user.id),
avatar: { src: `https://i.pravatar.cc/120?img=${user.id}`, loading: 'lazy' as const }
}))
},
immediate: false
})
function getUserAvatar(value: string) {
return users.value?.find(user => user.value === value)?.avatar || {}
}
function onOpen() {
if (!users.value?.length) {
execute()
}
}
</script>
<template>
<USelect
:items="users"
:loading="status === 'pending'"
icon="i-lucide-user"
placeholder="Select user"
value-key="value"
class="w-48"
@update:open="onOpen"
>
<template #leading="{ modelValue, ui }">
<UAvatar
v-if="modelValue"
v-bind="getUserAvatar(modelValue)"
:size="(ui.leadingAvatarSize() as AvatarProps['size'])"
:class="ui.leadingAvatar()"
/>
</template>
</USelect>
</template>
[!NOTE]
이 예제는
immediate: false와 함께useLazyFetch를 사용해 메뉴가 열릴 때만 데이터를 가져와 페이지 로드 시 불필요한 API 호출을 방지해요.
무한 스크롤 사용 4.4+ (With infinite scroll)
useInfiniteScroll 컴포저블을 사용해 사용자가 스크롤할 때 더 많은 데이터를 로드할 수 있어요.
<script setup lang="ts">
import { useInfiniteScroll } from '@vueuse/core'
type User = {
firstName: string
}
type UserResponse = {
users: User[]
total: number
skip: number
limit: number
}
const skip = ref(0)
const { data, status, execute } = await useLazyFetch('https://dummyjson.com/users?limit=10&select=firstName', {
key: 'select-users-infinite-scroll',
params: { skip },
transform: (data?: UserResponse) => {
return data?.users.map(user => user.firstName)
},
immediate: false
})
const users = ref<string[]>([])
watch(data, () => {
users.value = [
...users.value,
...(data.value || [])
]
})
function onOpen() {
if (!users.value?.length) {
execute()
}
}
const select = useTemplateRef('select')
onMounted(() => {
useInfiniteScroll(() => select.value?.viewportRef, () => {
skip.value += 10
}, {
canLoadMore: () => {
return status.value !== 'pending'
}
})
})
</script>
<template>
<USelect
ref="select"
placeholder="Select user"
:items="users"
@update:open="onOpen"
/>
</template>
[!NOTE]
이 예제는
immediate: false와 함께useLazyFetch를 사용해 사용자가 스크롤할 때만 데이터를 로드해요.
콘텐츠 전체 너비 사용 (With full content width)
ui.content 슬롯에 min-w-fit 클래스를 추가해 콘텐츠를 항목의 전체 너비로 확장할 수 있어요.
<script setup lang="ts">
const value = ref<string>()
const { data: users, execute } = await useLazyFetch('https://jsonplaceholder.typicode.com/users', {
key: 'typicode-users-email',
transform: (data: { id: number, name: string, email: string }[]) => {
return data?.map(user => ({
label: user.name,
email: user.email,
value: String(user.id),
avatar: { src: `https://i.pravatar.cc/120?img=${user.id}`, loading: 'lazy' as const }
}))
},
immediate: false
})
function onOpen() {
if (!users.value?.length) {
execute()
}
}
</script>
<template>
<USelect
v-model="value"
:items="users"
placeholder="Select user"
value-key="value"
:ui="{ content: 'min-w-fit' }"
class="w-48"
@update:open="onOpen"
>
<template #item-label="{ item }">
{{ item.label }}
<span class="text-muted">
{{ item.email }}
</span>
</template>
</USelect>
</template>
[!TIP]
app.config.ts에서 콘텐츠 너비를 전역으로 변경할 수도 있어요:export default defineAppConfig({ ui: { select: { slots: { content: 'min-w-fit' } } } })
API
Props (속성)
/**
* Props for the Select component
*/
interface SelectProps {
id?: string | undefined;
/**
* The placeholder text when the select is empty.
*/
placeholder?: string | undefined;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* @default 'outline'
*/
variant?: "outline" | "soft" | "subtle" | "ghost" | "none" | undefined;
/**
* @default 'md'
*/
size?: "sm" | "md" | "xs" | "lg" | "xl" | undefined;
/**
* The icon displayed to open the menu.
* @default appConfig.ui.icons.chevronDown
*/
trailingIcon?: any;
/**
* The icon displayed when an item is selected.
* @default appConfig.ui.icons.check
*/
selectedIcon?: any;
/**
* The content of the menu.
* @default { side: 'bottom', sideOffset: 8, collisionPadding: 8, position: 'popper' }
*/
content?: Omit<SelectContentProps, "as" | "asChild" | "forceMount"> & Partial<EmitsToProps<SelectContentImplEmits>> | undefined;
/**
* Display an arrow alongside the menu.
* `{ rounded: true }`{lang="ts-type"}
* @default false
*/
arrow?: boolean | Omit<SelectArrowProps, "as" | "asChild"> | undefined;
/**
* Render the menu in a portal.
* @default true
*/
portal?: string | false | true | HTMLElement | undefined;
/**
* When `items` is an array of objects, select the field to use as the value.
* @default 'value'
*/
valueKey?: VK | undefined;
/**
* When `items` is an array of objects, select the field to use as the label.
* @default 'label'
*/
labelKey?: keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>> | undefined;
/**
* When `items` is an array of objects, select the field to use as the description.
* @default 'description'
*/
descriptionKey?: keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>> | undefined;
items?: T | undefined;
/**
* The value of the Select when initially rendered. Use when you do not need to control the state of the Select.
*/
defaultValue?: _Number<_Optional<_Nullable<GetModelValue<T, VK, M, ExcludeItem>, Mod>, Mod>, Mod> | undefined;
/**
* The controlled value of the Select. Can be bind as `v-model`.
*/
modelValue?: _Number<_Optional<_Nullable<GetModelValue<T, VK, M, ExcludeItem>, Mod>, Mod>, Mod> | undefined;
modelModifiers?: Mod | undefined;
/**
* Whether multiple options can be selected or not.
*/
multiple?: M | undefined;
/**
* Highlight the ring color like a focus state.
*/
highlight?: boolean | undefined;
/**
* Keep the mobile text size on all breakpoints.
*/
fixed?: boolean | undefined;
autofocus?: boolean | undefined;
/**
* @default 0
*/
autofocusDelay?: number | undefined;
ui?: { base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; value?: SlotClass; placeholder?: SlotClass; arrow?: SlotClass; content?: SlotClass; viewport?: SlotClass; group?: SlotClass; empty?: SlotClass; label?: SlotClass; separator?: SlotClass; item?: SlotClass; itemLeadingIcon?: SlotClass; itemLeadingAvatar?: SlotClass; itemLeadingAvatarSize?: SlotClass; itemLeadingChip?: SlotClass; itemLeadingChipSize?: SlotClass; itemTrailing?: SlotClass; itemTrailingIcon?: SlotClass; itemWrapper?: SlotClass; itemLabel?: SlotClass; itemDescription?: SlotClass; } | undefined;
/**
* When `true`, prevents the user from interacting with Select
*/
disabled?: boolean | undefined;
/**
* The controlled open state of the Select. Can be bind as `v-model:open`.
*/
open?: boolean | undefined;
/**
* The open state of the select when it is initially rendered. Use when you do not need to control its open state.
*/
defaultOpen?: boolean | undefined;
/**
* The value of the hidden native select option when the model value is nullish.
*/
nullableValue?: string | undefined;
/**
* Native html input `autocomplete` attribute.
*/
autocomplete?: string | undefined;
/**
* The name of the field. Submitted with its owning form as part of a name/value pair.
*/
name?: string | undefined;
/**
* When `true`, indicates that the user must set the value before the owning form can be submitted.
*/
required?: boolean | undefined;
/**
* Display an icon based on the `leading` and `trailing` props.
*/
icon?: any;
/**
* Display an avatar on the left side.
*/
avatar?: AvatarProps | undefined;
/**
* When `true`, the icon will be displayed on the left side.
*/
leading?: boolean | undefined;
/**
* Display an icon on the left side.
*/
leadingIcon?: any;
/**
* When `true`, the icon will be displayed on the right side.
*/
trailing?: boolean | undefined;
/**
* When `true`, the loading icon will be displayed.
*/
loading?: boolean | undefined;
/**
* The icon when the `loading` prop is `true`.
* @default appConfig.ui.icons.loading
*/
loadingIcon?: any;
form?: string | undefined;
formaction?: string | undefined;
formenctype?: string | undefined;
formmethod?: string | undefined;
formnovalidate?: false | true | "true" | "false" | undefined;
formtarget?: string | undefined;
}
[!NOTE] See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes
이 컴포넌트는 모든 네이티브
<button>HTML 속성도 지원해요.
Slots (슬롯)
/**
* Slots for the Select component
*/
interface SelectSlots {
leading(): any;
default(): any;
trailing(): any;
item(): any;
item-leading(): any;
item-label(): any;
item-description(): any;
item-trailing(): any;
content-top(): any;
content-bottom(): any;
}
Emits (이벤트)
/**
* Emitted events for the Select component
*/
interface SelectEmits {
update:modelValue: (payload: [value: _Number<_Optional<_Nullable<GetModelValue<T, VK, M, ExcludeItem>, Mod>, Mod>, Mod>]) => void;
update:open: (payload: [value: boolean]) => void;
change: (payload: [event: Event]) => void;
blur: (payload: [event: FocusEvent]) => void;
focus: (payload: [event: FocusEvent]) => void;
}
Expose (노출)
템플릿 ref로 컴포넌트에 접근할 때 다음을 사용할 수 있어요:
| Name | Type |
|---|---|
triggerRef |
Ref<HTMLButtonElement | null> |
viewportRef |
Ref<HTMLDivElement | null> |
테마 (Theme)
export default defineAppConfig({
ui: {
select: {
slots: {
base: [
'relative group rounded-md inline-flex items-center disabled:cursor-not-allowed disabled:opacity-75',
'transition-colors'
],
leading: 'absolute inset-y-0 start-0 flex items-center',
leadingIcon: 'shrink-0 text-dimmed',
leadingAvatar: 'shrink-0',
leadingAvatarSize: '',
trailing: 'absolute inset-y-0 end-0 flex items-center',
trailingIcon: 'shrink-0 text-dimmed',
value: 'truncate pointer-events-none',
placeholder: 'truncate text-dimmed',
arrow: 'fill-bg stroke-default',
content: 'max-h-[min(15rem,var(--reka-select-content-available-height,15rem))] w-(--reka-select-trigger-width) bg-default shadow-lg rounded-md ring ring-default overflow-hidden origin-(--reka-select-content-transform-origin) pointer-events-auto data-[state=closed]:pointer-events-none! flex flex-col',
viewport: 'relative divide-y divide-default scroll-py-1 overflow-y-auto flex-1',
group: 'p-1 isolate',
empty: 'text-center text-muted',
label: 'font-semibold text-highlighted',
separator: '-mx-1 my-1 h-px bg-border',
item: [
'group relative w-full flex items-start select-none outline-none before:absolute before:z-[-1] before:inset-px before:rounded-md data-disabled:cursor-not-allowed data-disabled:opacity-75 text-default data-highlighted:not-data-disabled:text-highlighted data-highlighted:not-data-disabled:before:bg-elevated/50',
'transition-colors before:transition-colors'
],
itemLeadingIcon: [
'shrink-0 text-dimmed group-data-highlighted:not-group-data-disabled:text-default',
'transition-colors'
],
itemLeadingAvatar: 'shrink-0',
itemLeadingAvatarSize: '',
itemLeadingChip: 'shrink-0',
itemLeadingChipSize: '',
itemTrailing: 'ms-auto inline-flex gap-1.5 items-center',
itemTrailingIcon: 'shrink-0',
itemWrapper: 'flex-1 flex flex-col min-w-0',
itemLabel: 'truncate',
itemDescription: 'truncate text-muted'
},
variants: {
fieldGroup: {
horizontal: 'not-only:first:rounded-e-none not-only:last:rounded-s-none not-last:not-first:rounded-none focus-visible:z-[1]',
vertical: 'not-only:first:rounded-b-none not-only:last:rounded-t-none not-last:not-first:rounded-none focus-visible:z-[1]'
},
size: {
xs: {
base: 'px-2 py-1 text-sm/4 gap-1',
leading: 'ps-2',
trailing: 'pe-2',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
label: 'p-1 text-[10px]/3 gap-1',
item: 'p-1 text-xs gap-1',
itemLeadingIcon: 'size-4',
itemLeadingAvatarSize: '3xs',
itemLeadingChip: 'size-4',
itemLeadingChipSize: 'sm',
itemTrailingIcon: 'size-4',
empty: 'p-2 text-xs'
},
sm: {
base: 'px-2.5 py-1.5 text-sm/4 gap-1.5',
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4',
label: 'p-1.5 text-[10px]/3 gap-1.5',
item: 'p-1.5 text-xs gap-1.5',
itemLeadingIcon: 'size-4',
itemLeadingAvatarSize: '3xs',
itemLeadingChip: 'size-4',
itemLeadingChipSize: 'sm',
itemTrailingIcon: 'size-4',
empty: 'p-2.5 text-xs'
},
md: {
base: 'px-2.5 py-1.5 text-base/5 gap-1.5',
leading: 'ps-2.5',
trailing: 'pe-2.5',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
label: 'p-1.5 text-xs gap-1.5',
item: 'p-1.5 text-sm gap-1.5',
itemLeadingIcon: 'size-5',
itemLeadingAvatarSize: '2xs',
itemLeadingChip: 'size-5',
itemLeadingChipSize: 'md',
itemTrailingIcon: 'size-5',
empty: 'p-2.5 text-sm'
},
lg: {
base: 'px-3 py-2 text-base/5 gap-2',
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5',
label: 'p-2 text-xs gap-2',
item: 'p-2 text-sm gap-2',
itemLeadingIcon: 'size-5',
itemLeadingAvatarSize: '2xs',
itemLeadingChip: 'size-5',
itemLeadingChipSize: 'md',
itemTrailingIcon: 'size-5',
empty: 'p-3 text-sm'
},
xl: {
base: 'px-3 py-2 text-base gap-2',
leading: 'ps-3',
trailing: 'pe-3',
leadingIcon: 'size-6',
leadingAvatarSize: 'xs',
trailingIcon: 'size-6',
label: 'p-2 text-sm gap-2',
item: 'p-2 text-base gap-2',
itemLeadingIcon: 'size-6',
itemLeadingAvatarSize: 'xs',
itemLeadingChip: 'size-6',
itemLeadingChipSize: 'lg',
itemTrailingIcon: 'size-6',
empty: 'p-3 text-base'
}
},
variant: {
outline: 'text-highlighted bg-default ring ring-inset ring-accented hover:bg-elevated disabled:bg-default',
soft: 'text-highlighted bg-elevated/50 hover:bg-elevated focus:bg-elevated disabled:bg-elevated/50',
subtle: 'text-highlighted bg-elevated ring ring-inset ring-accented hover:bg-accented/75 disabled:bg-elevated',
ghost: 'text-highlighted bg-transparent hover:bg-elevated focus:bg-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'text-highlighted bg-transparent focus:outline-none'
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
},
type: {
file: 'file:me-1.5 file:font-medium file:text-muted file:outline-none'
},
position: {
popper: {
content: 'data-[state=open]:animate-[scale-in_100ms_var(--ease-out)] data-[state=closed]:animate-[scale-out_100ms_var(--ease-out)]'
},
'item-aligned': {
content: ''
}
},
multiple: {
true: ''
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 focus-visible:outline-3 focus-visible:ring-primary'
},
{
color: 'secondary',
variant: [
'outline',
'subtle'
],
class: 'outline-secondary/25 focus-visible:outline-3 focus-visible:ring-secondary'
},
{
color: 'success',
variant: [
'outline',
'subtle'
],
class: 'outline-success/25 focus-visible:outline-3 focus-visible:ring-success'
},
{
color: 'info',
variant: [
'outline',
'subtle'
],
class: 'outline-info/25 focus-visible:outline-3 focus-visible:ring-info'
},
{
color: 'warning',
variant: [
'outline',
'subtle'
],
class: 'outline-warning/25 focus-visible:outline-3 focus-visible:ring-warning'
},
{
color: 'error',
variant: [
'outline',
'subtle'
],
class: 'outline-error/25 focus-visible:outline-3 focus-visible:ring-error'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 focus-visible:outline-3'
},
{
color: 'secondary',
variant: [
'soft',
'ghost'
],
class: 'outline-secondary/25 focus-visible:outline-3'
},
{
color: 'success',
variant: [
'soft',
'ghost'
],
class: 'outline-success/25 focus-visible:outline-3'
},
{
color: 'info',
variant: [
'soft',
'ghost'
],
class: 'outline-info/25 focus-visible:outline-3'
},
{
color: 'warning',
variant: [
'soft',
'ghost'
],
class: 'outline-warning/25 focus-visible:outline-3'
},
{
color: 'error',
variant: [
'soft',
'ghost'
],
class: 'outline-error/25 focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'secondary',
highlight: true,
class: 'ring ring-inset ring-secondary'
},
{
color: 'success',
highlight: true,
class: 'ring ring-inset ring-success'
},
{
color: 'info',
highlight: true,
class: 'ring ring-inset ring-info'
},
{
color: 'warning',
highlight: true,
class: 'ring ring-inset ring-warning'
},
{
color: 'error',
highlight: true,
class: 'ring ring-inset ring-error'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-inverted/25 focus-visible:outline-3 focus-visible:ring-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-inverted/25 focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-inverted'
},
{
leading: true,
size: 'xs',
class: 'ps-7'
},
{
leading: true,
size: 'sm',
class: 'ps-8'
},
{
leading: true,
size: 'md',
class: 'ps-9'
},
{
leading: true,
size: 'lg',
class: 'ps-10'
},
{
leading: true,
size: 'xl',
class: 'ps-11'
},
{
trailing: true,
size: 'xs',
class: 'pe-7'
},
{
trailing: true,
size: 'sm',
class: 'pe-8'
},
{
trailing: true,
size: 'md',
class: 'pe-9'
},
{
trailing: true,
size: 'lg',
class: 'pe-10'
},
{
trailing: true,
size: 'xl',
class: 'pe-11'
},
{
loading: true,
leading: true,
class: {
leadingIcon: 'animate-spin'
}
},
{
loading: true,
leading: false,
trailing: true,
class: {
trailingIcon: 'animate-spin'
}
},
{
fixed: false,
size: 'xs',
class: 'md:text-xs'
},
{
fixed: false,
size: 'sm',
class: 'md:text-xs'
},
{
fixed: false,
size: 'md',
class: 'md:text-sm'
},
{
fixed: false,
size: 'lg',
class: 'md:text-sm'
}
],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'outline',
position: 'popper'
}
}
}
})