- 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
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- 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
import { Button } from "@/components/ui/radix/button"
import { Checkbox } from "@/components/ui/radix/checkbox"
import {インストール#
pnpm dlx shadcn@latest add field
使い方#
import {
Field,
FieldContent,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSeparator,
FieldSet,
FieldTitle,
} from "@/components/ui/field"<FieldSet>
<FieldLegend>Profile</FieldLegend>
<FieldDescription>This appears on invoices and emails.</FieldDescription>
<FieldGroup>
<Field>
<FieldLabel htmlFor="name">Full name</FieldLabel>
<Input id="name" autoComplete="off" placeholder="Evil Rabbit" />
<FieldDescription>This appears on invoices and emails.</FieldDescription>
</Field>
<Field>
<FieldLabel htmlFor="username">Username</FieldLabel>
<Input id="username" autoComplete="off" aria-invalid />
<FieldError>Choose another username.</FieldError>
</Field>
<Field orientation="horizontal">
<Switch id="newsletter" />
<FieldLabel htmlFor="newsletter">Subscribe to the newsletter</FieldLabel>
</Field>
</FieldGroup>
</FieldSet>構成#
Field#
ラベル、ヘルパー テキスト、および検証を含む単一のコントロール。
Field
├── FieldLabel
├── Input / Textarea / Switch / Select
├── FieldDescription
└── FieldErrorFieldGroup#
1 つのグループ内の関連フィールド。必要に応じて、セクション間で FieldSeparator を使用します。
FieldGroup
├── Field
│ ├── FieldLabel
│ ├── Input / Textarea / Switch / Select
│ ├── FieldDescription
│ └── FieldError
├── FieldSeparator
└── Field
├── FieldLabel
└── Input / Textarea / Switch / SelectFieldSet#
凡例と説明を含むセマンティック グループ。通常は FieldGroup が含まれます。
FieldSet
├── FieldLegend
├── FieldDescription
└── FieldGroup
├── Field
│ ├── FieldLabel
│ ├── Input / Textarea / Switch / Select
│ ├── FieldDescription
│ └── FieldError
└── Field
├── FieldLabel
└── Input / Textarea / Switch / Select構造#
Field ファミリは、アクセシビリティ対応のフォームを作成するために設計されています。一般的なフィールドは次のように構成されています。
<Field>
<FieldLabel htmlFor="input-id">Label</FieldLabel>
{/* Input, Select, Switch, etc. */}
<FieldDescription>Optional helper text.</FieldDescription>
<FieldError>Validation message.</FieldError>
</Field>Fieldは、単一フィールドのコア ラッパーです。FieldContentは、ラベルと説明をグループ化するフレックス列です。記載がない場合は不要です。- 関連フィールドを
FieldGroupでラップし、セマンティック グループ化にFieldSetをFieldLegendとともに使用します。
フォーム#
Field コンポーネントと React Hook Form、Tanstack Form、または Formisch を使用したフォームの構築については、Form のドキュメントを参照してください。
入力#
import {
Field,
FieldDescription,テキストエリア#
import {
Field,
FieldDescription,選択#
所属部門または業務領域を選択してください。
import {
Field,
FieldDescription,スライダー#
予算の範囲を設定してください($200 ~ 800)。
"use client"
import * as React from "react"FieldSet#
import {
Field,
FieldDescription,チェックボックス#
デスクトップと書類フォルダはiCloud Driveと同期されています。他のデバイスからもアクセスできます。
import { Checkbox } from "@/components/ui/radix/checkbox"
import {
Field,ラジオ#
import {
Field,
FieldDescription,スイッチ#
import { Field, FieldLabel } from "@/components/ui/radix/field"
import { Switch } from "@/components/ui/radix/switch"
選択カード#
Field コンポーネントを FieldLabel 内にラップして、選択可能なフィールド グループを作成します。これは、RadioItem、Checkbox、および Switch コンポーネントで機能します。
import {
Field,
FieldContent,フィールド グループ#
FieldGroup を使用して Field コンポーネントをスタックします。区切るには FieldSeparator を追加します。
import { Checkbox } from "@/components/ui/radix/checkbox"
import {
Field,RTL#
shadcn/ui で RTL サポートを有効にするには、RTL 構成ガイドを参照してください。
"use client"
import {レスポンシブ レイアウト#
- 垂直フィールド: デフォルトの向きでは、ラベル、コントロール、ヘルパー テキストが縦に並びます。モバイルファーストのレイアウトに最適です。
- 水平フィールド: ラベルとコントロールを並べて配置するには、
Fieldにorientation="horizontal"を設定します。FieldContentと組み合わせて説明を統一します。 - レスポンシブ フィールド: コンテナ対応の親内の自動列レイアウト用に
orientation="responsive"を設定します。FieldGroupに@container/field-groupクラスを適用して、特定のブレークポイントで方向を切り替えます。
import { Button } from "@/components/ui/radix/button"
import {
Field,検証とエラー#
data-invalidをFieldに追加して、ブロック全体をエラー状態に切り替えます。- 支援技術のために、入力自体に
aria-invalidを追加します。 - コントロールの直後または
FieldContent内にFieldErrorをレンダリングして、エラー メッセージをフィールドに合わせて配置します。
<Field data-invalid>
<FieldLabel htmlFor="email">Email</FieldLabel>
<Input id="email" type="email" aria-invalid />
<FieldError>Enter a valid email address.</FieldError>
</Field>アクセシビリティ#
FieldSetおよびFieldLegendは、キーボードおよび支援技術ユーザー向けに関連するコントロールをグループ化します。Fieldはrole="group"を出力するため、ネストされたコントロールは結合時にFieldLabelおよびFieldLegendからラベル付けを継承します。FieldSeparatorは慎重に適用して、スクリーン リーダーが明確なセクション境界に遭遇するようにします。
API リファレンス#
FieldSet#
間隔プリセットを使用してセマンティック fieldset をレンダリングするコンテナー。
| Prop | Type | Default |
|---|---|---|
className | string |
<FieldSet>
<FieldLegend>Delivery</FieldLegend>
<FieldGroup>{/* Fields */}</FieldGroup>
</FieldSet>FieldLegend#
FieldSet の凡例要素。ラベルのサイズに合わせて label バリアントに切り替えます。
| Prop | Type | Default |
|---|---|---|
variant | "legend" | "label" | "legend" |
className | string |
<FieldLegend variant="label">Notification Preferences</FieldLegend>FieldLegend には、legend と label の 2 つのバリアントがあります。 label バリアントは、ラベルのサイズ変更と配置を適用します。 FieldSet をネストしている場合に便利です。
FieldGroup#
Field コンポーネントをスタックし、応答性の高い方向に対するコンテナー クエリを可能にするレイアウト ラッパー。
| Prop | Type | Default |
|---|---|---|
className | string |
<FieldGroup className="@container/field-group flex flex-col gap-6">
<Field>{/* ... */}</Field>
<Field>{/* ... */}</Field>
</FieldGroup>Field#
単一フィールドのコア ラッパー。向きの制御、無効な状態のスタイル、および間隔を提供します。
| Prop | Type | Default |
|---|---|---|
orientation | "vertical" | "horizontal" | "responsive" | "vertical" |
className | string | |
data-invalid | boolean |
<Field orientation="horizontal">
<FieldLabel htmlFor="remember">Remember me</FieldLabel>
<Switch id="remember" />
</Field>FieldContent#
ラベルがコントロールの横にあるときにコントロールと説明をグループ化するフレックス列。記載がない場合は不要です。
| Prop | Type | Default |
|---|---|---|
className | string |
<Field>
<Checkbox id="notifications" />
<FieldContent>
<FieldLabel htmlFor="notifications">Notifications</FieldLabel>
<FieldDescription>Email, SMS, and push options.</FieldDescription>
</FieldContent>
</Field>FieldLabel#
直接入力とネストされた Field 子の両方に対してスタイル設定されたラベル。
| Prop | Type | Default |
|---|---|---|
className | string | |
asChild | boolean | false |
<FieldLabel htmlFor="email">Email</FieldLabel>FieldTitle#
FieldContent 内にラベル スタイルを使用してタイトルをレンダリングします。
| Prop | Type | Default |
|---|---|---|
className | string |
<FieldContent>
<FieldTitle>Enable Touch ID</FieldTitle>
<FieldDescription>Unlock your device faster.</FieldDescription>
</FieldContent>FieldDescription#
水平レイアウトで長い行のバランスを自動的に調整するヘルパー テキスト スロット。
| Prop | Type | Default |
|---|---|---|
className | string |
<FieldDescription>We never share your email with anyone.</FieldDescription>FieldSeparator#
FieldGroup 内のセクションを区切る視覚的な区切り線。オプションのインライン コンテンツを受け入れます。
| Prop | Type | Default |
|---|---|---|
className | string |
<FieldSeparator>Or continue with</FieldSeparator>FieldError#
子または errors 配列 (例: react-hook-form から) を受け入れる、アクセス可能なエラー コンテナー。
| Prop | Type | Default |
|---|---|---|
errors | Array<{ message?: string } | undefined> | |
className | string |
<FieldError errors={errors.username} />errors 配列に複数のメッセージが含まれている場合、コンポーネントはリストを自動的に表示します。
FieldError は、Zod、Valibot、ArkType など、標準スキーマ を実装するバリデーターによって生成された問題も受け入れます。スキーマの結果から issues 配列を直接渡して、ライブラリ全体で統一されたエラー リストをレンダリングします。