Cài đặt
Chạy lệnh này trong app, sau shadcn-vue init và theme Beehexa (Button › Code):
npx shadcn-vue@latest add https://beehexa.design/r/select.json
Cách dùng
<script setup lang="ts">
import { ref } from 'vue'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
const status = ref<string>()
</script>
<template>
<label for="order-status">Trạng thái đơn hàng</label>
<Select v-model="status">
<SelectTrigger id="order-status">
<SelectValue placeholder="Chọn trạng thái" />
</SelectTrigger>
<SelectContent>
<SelectItem value="pending">Chờ xử lý</SelectItem>
<SelectItem value="shipped">Đã giao cho vận chuyển</SelectItem>
</SelectContent>
</Select>
</template>
Prop
| Phần | Prop | Giá trị | Ghi chú |
|---|---|---|---|
Select |
v-model, defaultValue |
chuỗi, hoặc object kèm by |
Không bao giờ là chuỗi rỗng: chuỗi rỗng xóa lựa chọn |
Select |
multiple |
boolean | Cho chọn nhiều; nên dùng checkbox hoặc combobox thay vào |
Select |
disabled, required, name |
name gửi giá trị cùng biểu mẫu gốc |
|
SelectTrigger |
size |
default (32 px), sm (24 px) |
|
SelectTrigger |
aria-invalid |
boolean | Viền đỏ; dùng kèm thông báo lỗi và aria-describedby |
SelectValue |
placeholder |
chuỗi | Hiện khi chưa chọn gì |
SelectContent |
position |
popper (mặc định), item-aligned |
popper mở ra dưới ô |
SelectItem |
value, disabled, textValue |
||
SelectGroup, SelectLabel, SelectSeparator |
Tiêu đề nhóm và đường kẻ trong danh sách |
Dựng từ
Bọc Select của reka-ui theo API Select của shadcn-vue, từ bản của control-center. reka-ui lo vai trò combobox và listbox, xử lý bàn phím, gõ để nhảy tới lựa chọn, tự đổi bên khi bị che, và select gốc ẩn cho biểu mẫu. Beehexa thêm style cho ô và danh sách.
Giới hạn
- Danh sách hiện và ẩn bằng class animation của shadcn-vue, chưa dùng token motion (
motion.overlay.enter,.exit). - reka-ui chèn một thẻ
<style>vào danh sách, và mức style chặt của Content Security Policy chặn thẻ này. Danh sách vẫn ẩn thanh cuộn bằng CSS của kit; để trình duyệt không báo lỗi ở mức đó, thêm plugin Vite ở Tools › Gói shadcn-vue.