21 lines
1.2 KiB
Vue
21 lines
1.2 KiB
Vue
<script setup lang="ts">
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
|
|
// A Select whose options may include the empty value, which reka-ui reserves
|
|
// for clearing: it travels as a sentinel and comes back as "".
|
|
const EMPTY = "\u0000";
|
|
defineOptions({ inheritAttrs: false });
|
|
type Option = { value: string; label: string; disabled?: boolean };
|
|
defineProps<{ modelValue: string; options: Option[]; placeholder?: string; disabled?: boolean; size?: "sm" | "default"; class?: string }>();
|
|
const emit = defineEmits<{ "update:modelValue": [string] }>();
|
|
</script>
|
|
|
|
<template>
|
|
<Select :model-value="modelValue === '' && options.some((o) => o.value === '') ? EMPTY : modelValue || undefined" :disabled="disabled" @update:model-value="emit('update:modelValue', $event === EMPTY ? '' : String($event))">
|
|
<SelectTrigger :size="size ?? 'sm'" :class="$props.class" v-bind="$attrs"><SelectValue :placeholder="placeholder" /></SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem v-for="option in options" :key="option.value" :value="option.value === '' ? EMPTY : option.value" :disabled="option.disabled">{{ option.label }}</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</template>
|