Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Message
- Message Scroller
- Native Select
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Typography
Sections
@shadcn/react
@shadcn/helpers
Utilities
import {
Select,
SelectContent,インストール#
pnpm dlx shadcn@latest add select
使い方#
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"const items = [
{ label: "Light", value: "light" },
{ label: "Dark", value: "dark" },
{ label: "System", value: "system" },
]
<Select placeholder="Theme">
<SelectTrigger className="w-[180px]">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{items.map((item) => (
<SelectItem key={item.value} id={item.value}>
{item.label}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>構成#
次の構成を使用して、Select を構築します。
Select
├── SelectTrigger
│ └── SelectValue
└── SelectContent
├── SelectGroup
│ ├── SelectLabel
│ ├── SelectItem
│ └── SelectItem
├── SelectSeparator
└── SelectGroup
├── SelectLabel
├── SelectItem
└── SelectItemグループ#
SelectGroup、SelectLabel、SelectSeparator を使用して項目をグループ化します。
import {
Select,
SelectContent,スクロール可能#
多くの項目を含み、スクロール可能なセレクト。
import {
Select,
SelectContent,無効#
import {
Select,
SelectContent,無効な状態#
エラー状態を表示するには、Field コンポーネントに data-invalid 属性を追加し、SelectTrigger コンポーネントに isInvalid プロパティを追加します。
<Field data-invalid>
<FieldLabel>Fruit</FieldLabel>
<Select isInvalid>{/* ... */}</Select>
</Field>フルーツを選択してください。
import { Field, FieldError, FieldLabel } from "@/components/ui/aria/field"
import {
Select,検索可能#
React Aria の Autocomplete コンポーネントを使用して、検索サポートを追加します。
"use client"
import { Autocomplete, useFilter } from "react-aria-components"RTL#
shadcn/ui で RTL サポートを有効にするには、RTL 構成ガイドを参照してください。
"use client"
import * as React from "react"API リファレンス#
詳細については、React Aria Select のドキュメントを参照してください。