Field

레이블, 컨트롤, 도움말 텍스트를 조합해 접근성 있는 폼 필드를 구성합니다.

신청인 정보

본인 확인을 위해 정확한 정보를 입력해 주세요.

주민등록번호 13자리를 모두 입력해 주세요.

연도, 월, 일을 차례로 선택해 주세요. (예: 2024-03-15)

신청 내용

민원 처리에 필요한 신청 사유를 입력해 주세요.

examples/krds/field-demo.tsx
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {

설치

pnpm dlx shadcn@latest add https://krdscn.gwlee.kr/r/field.json

사용법

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

A single control with label, helper text, and validation.

Field
├── FieldLabel
├── Input / Textarea / Switch / Select
├── FieldDescription
└── FieldError

FieldGroup

Related fields in one group. Use FieldSeparator between sections when needed.

FieldGroup
├── Field
│   ├── FieldLabel
│   ├── Input / Textarea / Switch / Select
│   ├── FieldDescription
│   └── FieldError
├── FieldSeparator
└── Field
    ├── FieldLabel
    └── Input / Textarea / Switch / Select

FieldSet

Semantic grouping with a legend and description, usually containing a FieldGroup.

FieldSet
├── FieldLegend
├── FieldDescription
└── FieldGroup
    ├── Field
    │   ├── FieldLabel
    │   ├── Input / Textarea / Switch / Select
    │   ├── FieldDescription
    │   └── FieldError
    └── Field
        ├── FieldLabel
        └── Input / Textarea / Switch / Select

구조

The Field family is designed for composing accessible forms. A typical field is structured as follows:

<Field>
  <FieldLabel htmlFor="input-id">Label</FieldLabel>
  {/* Input, Select, Switch, etc. */}
  <FieldDescription>Optional helper text.</FieldDescription>
  <FieldError>Validation message.</FieldError>
</Field>
  • Field is the core wrapper for a single field.
  • FieldContent is a flex column that groups label and description. Not required if you have no description.
  • Wrap related fields with FieldGroup, and use FieldSet with FieldLegend for semantic grouping.

Form documentation for building forms with the Field component and React Hook Form or Tanstack Form.

예제

Input

영문, 숫자 조합으로 4~16자 이내로 입력해 주세요.

영문, 숫자, 특수문자를 포함하여 8자 이상 입력해 주세요.

examples/krds/field-input.tsx
import {
  Field,
  FieldDescription,

Textarea

소중한 의견은 서비스 개선에 반영됩니다.

examples/krds/field-textarea.tsx
import {
  Field,
  FieldDescription,

Select

문의하실 업무를 담당하는 부서를 선택해 주세요.

examples/krds/field-select.tsx
import {
  Field,
  FieldDescription,

Slider

연령대 범위

조회할 연령대 범위를 설정해 주세요. (20세 ~ 60세)

examples/krds/field-slider.tsx
"use client"

import * as React from "react"

Fieldset

주소 정보

민원 결과 우편 발송을 위해 주소를 입력해 주세요.

examples/krds/field-fieldset.tsx
import {
  Field,
  FieldDescription,

Checkbox

알림 받을 항목

마이페이지에서 알림을 받을 항목을 선택해 주세요.

선택하신 항목의 알림이 가입하신 이메일로 발송됩니다. 언제든 마이페이지에서 변경할 수 있습니다.

examples/krds/field-checkbox.tsx
import { Checkbox } from "@/components/ui/checkbox"
import {
  Field,

Radio

민원 처리 방법

처리 결과를 안내받을 방법을 선택해 주세요.

examples/krds/field-radio.tsx
import {
  Field,
  FieldDescription,

Switch

examples/krds/field-switch.tsx
import { Field, FieldLabel } from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"

Choice Card

Wrap Field components inside FieldLabel to create selectable field groups. This works with RadioItem, Checkbox and Switch components.

서비스 신청 방식

민원 신청 방식을 선택해 주세요.

examples/krds/field-choice-card.tsx
import {
  Field,
  FieldContent,

Field Group

Stack Field components with FieldGroup. Add FieldSeparator to divide them.

접수하신 민원의 처리 단계가 변경될 때 알림을 받을 수 있습니다.

관심 등록한 정책에 변경 사항이 있을 때 알림을 받습니다. 관심 정책 관리

examples/krds/field-group.tsx
import { Checkbox } from "@/components/ui/checkbox"
import {
  Field,

RTL

RTL 지원을 활성화하려면 RTL 설정 가이드를 참고하세요.

طريقة الدفع

جميع المعاملات آمنة ومشفرة

أدخل رقم البطاقة المكون من 16 رقمًا

عنوان الفوترة

عنوان الفوترة المرتبط بطريقة الدفع الخاصة بك

examples/krds/field-rtl.tsx
"use client"

import {

반응형 레이아웃

  • Vertical fields: Default orientation stacks label, control, and helper text—ideal for mobile-first layouts.
  • Horizontal fields: Set orientation="horizontal" on Field to align the label and control side-by-side. Pair with FieldContent to keep descriptions aligned.
  • Responsive fields: Set orientation="responsive" for automatic column layouts inside container-aware parents. Apply @container/field-group classes on FieldGroup to switch orientations at specific breakpoints.
프로필 정보

회원 프로필 정보를 입력해 주세요.

본인 확인을 위해 실명을 입력해 주세요.

examples/krds/field-responsive.tsx
import { Button } from "@/components/ui/button"
import {
  Field,

유효성 검사와 오류

  • Add data-invalid to Field to switch the entire block into an error state.
  • Add aria-invalid on the input itself for assistive technologies.
  • Render FieldError immediately after the control or inside FieldContent to keep error messages aligned with the field.
<Field data-invalid>
  <FieldLabel htmlFor="email">Email</FieldLabel>
  <Input id="email" type="email" aria-invalid />
  <FieldError>Enter a valid email address.</FieldError>
</Field>

접근성

  • FieldSet and FieldLegend keep related controls grouped for keyboard and assistive tech users.
  • Field outputs role="group" so nested controls inherit labeling from FieldLabel and FieldLegend when combined.
  • Apply FieldSeparator sparingly to ensure screen readers encounter clear section boundaries.

API 참조

FieldSet

Container that renders a semantic fieldset with spacing presets.

속성타입기본값
classNamestring
<FieldSet>
  <FieldLegend>Delivery</FieldLegend>
  <FieldGroup>{/* Fields */}</FieldGroup>
</FieldSet>

FieldLegend

Legend element for a FieldSet. Switch to the label variant to align with label sizing.

속성타입기본값
variant"legend" | "label""legend"
classNamestring
<FieldLegend variant="label">Notification Preferences</FieldLegend>

The FieldLegend has two variants: legend and label. The label variant applies label sizing and alignment. Handy if you have nested FieldSet.

FieldGroup

Layout wrapper that stacks Field components and enables container queries for responsive orientations.

속성타입기본값
classNamestring
<FieldGroup className="@container/field-group flex flex-col gap-6">
  <Field>{/* ... */}</Field>
  <Field>{/* ... */}</Field>
</FieldGroup>

Field

The core wrapper for a single field. Provides orientation control, invalid state styling, and spacing.

속성타입기본값
orientation"vertical" | "horizontal" | "responsive""vertical"
classNamestring
data-invalidboolean
<Field orientation="horizontal">
  <FieldLabel htmlFor="remember">Remember me</FieldLabel>
  <Switch id="remember" />
</Field>

FieldContent

Flex column that groups control and descriptions when the label sits beside the control. Not required if you have no description.

속성타입기본값
classNamestring
<Field>
  <Checkbox id="notifications" />
  <FieldContent>
    <FieldLabel htmlFor="notifications">Notifications</FieldLabel>
    <FieldDescription>Email, SMS, and push options.</FieldDescription>
  </FieldContent>
</Field>

FieldLabel

Label styled for both direct inputs and nested Field children.

속성타입기본값
classNamestring
asChildbooleanfalse
<FieldLabel htmlFor="email">Email</FieldLabel>

FieldTitle

Renders a title with label styling inside FieldContent.

속성타입기본값
classNamestring
<FieldContent>
  <FieldTitle>Enable Touch ID</FieldTitle>
  <FieldDescription>Unlock your device faster.</FieldDescription>
</FieldContent>

FieldDescription

Helper text slot that automatically balances long lines in horizontal layouts.

속성타입기본값
classNamestring
<FieldDescription>We never share your email with anyone.</FieldDescription>

FieldSeparator

Visual divider to separate sections inside a FieldGroup. Accepts optional inline content.

속성타입기본값
classNamestring
<FieldSeparator>Or continue with</FieldSeparator>

FieldError

Accessible error container that accepts children or an errors array (e.g., from react-hook-form).

속성타입기본값
errorsArray<{ message?: string } | undefined>
classNamestring
<FieldError errors={errors.username} />

When the errors array contains multiple messages, the component renders a list automatically.

FieldError also accepts issues produced by any validator that implements Standard Schema, including Zod, Valibot, and ArkType. Pass the issues array from the schema result directly to render a unified error list across libraries.