Todae

Todae

Field

공유 외형입니다. Field.Root는 컴파운드 스코프입니다. 테두리가 있는 셸이 Root입니다. 값은 Field.TextInput, Field.NumberInput, Field.OneTimeCode, Field.Textarea, Field.ChipInput, Field.Select, Field.DateInput, Field.DateRangeInput, Field.TimeInput, Field.DateTimeInput에 있습니다. Field.Picker는 이들 옆에서 값을 고르는 패널을 여는 버튼입니다. 장식 요소는 순서로만 위치가 정해집니다. Icon / Affix를 입력 앞에 두면 앞쪽에, 뒤에 두면 뒤쪽에 놓입니다. side prop은 없습니다. Label.Root은 컴파운드 파트가 아니라 형제 요소입니다. 필드 안의 모든 파트(입력, Icon, Affix, 칩)는 필드 한 줄 높이이고, 셸의 패딩이 안쪽 여백입니다.

이 페이지의 내용
import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function FieldStates() {
  const [value, setValue] = useState('');
  return (
    <>
      <Field.Root aria-label="Idle field">
        <Field.TextInput value={value} onChange={(event) => setValue(event.target.value)} placeholder="Idle" />
      </Field.Root>
      <Field.Root aria-label="Disabled field" disabled>
        <Field.TextInput value="Disabled" onChange={() => undefined} />
      </Field.Root>
      <Field.Root aria-label="Invalid field" invalid>
        <Field.TextInput value="Invalid" onChange={() => undefined} />
      </Field.Root>
    </>
  );
}

입력

입력 파트마다 자체 페이지가 있습니다.

  • Field.TextInput: 한 줄 텍스트.
  • Field.NumberInput: 로캘 형식으로 입력하거나 단계로 바꾸는 숫자. 옆에 Field.Increment와 Field.Decrement 버튼을 둘 수 있습니다.
  • Field.OneTimeCode: 하나의 입력 위에 칸으로 그려지는 로그인·인증 코드.
  • Field.Textarea: 여러 줄 텍스트.
  • Field.ChipInput: 칩과 입력.
  • Field.Select: 네이티브 <select>입니다. JavaScript listbox는 없습니다. 자식은 <option> 또는 <optgroup>이고, 브라우저가 지원하면 appearance: base-select로 컨트롤을 그립니다.
  • Field.DateInput: 로캘의 방식대로 입력하는 날짜.
  • Field.DateRangeInput: 로캘의 방식대로 입력하는 시작일과 종료일.
  • Field.TimeInput: 로캘의 방식대로 입력하는 하루 중 시각.
  • Field.DateTimeInput: 로캘의 방식대로 입력하는 날짜와 시각.
  • Field.Picker: 값을 담는 입력 옆에서 달력, 시각 목록, 색 선택기 같은 패널을 여는 버튼.

Label

Label.Root은 컴파운드 파트가 아니라 형제 요소입니다. Field.Root에 넘기는 것과 같은 id를 받습니다. 둘을 하나의 Field.Group으로 감싸세요. Field.Group은 레이블을 셸 위 field.label.gap 간격에 둡니다. API는 Label을 보세요.

import { Field, Label } from '@tounsoo/todae';
import { useId, useState } from 'react';

export default function FieldLabelStates() {
  const idleId = useId();
  const disabledId = useId();
  const invalidId = useId();
  const [email, setEmail] = useState('');
  return (
    <>
      <Field.Group>
        <Label.Root htmlFor={idleId}>Email</Label.Root>
        <Field.Root id={idleId}>
          <Field.TextInput
            value={email}
            onChange={(event) => setEmail(event.target.value)}
            placeholder="you@example.com"
          />
        </Field.Root>
      </Field.Group>
      <Field.Group>
        <Label.Root htmlFor={disabledId}>Email</Label.Root>
        <Field.Root id={disabledId} disabled>
          <Field.TextInput value="Disabled" onChange={() => undefined} />
        </Field.Root>
      </Field.Group>
      <Field.Group>
        <Label.Root htmlFor={invalidId}>Email</Label.Root>
        <Field.Root id={invalidId} invalid>
          <Field.TextInput value="Invalid" onChange={() => undefined} />
        </Field.Root>
      </Field.Group>
    </>
  );
}

Label은 Icon, Affix, ChipInput과 함께 동작합니다.

import { Field, Label } from '@tounsoo/todae';
import { useId, useState } from 'react';

export default function FieldLabelAdornments() {
  const searchId = useId();
  const amountId = useId();
  const [search, setSearch] = useState('query');
  const [amount, setAmount] = useState('12');
  return (
    <>
      <Field.Group>
        <Label.Root htmlFor={searchId}>Search</Label.Root>
        <Field.Root id={searchId}>
          <Field.Icon>
            <span>⌕</span>
          </Field.Icon>
          <Field.TextInput value={search} onChange={(event) => setSearch(event.target.value)} />
        </Field.Root>
      </Field.Group>
      <Field.Group>
        <Label.Root htmlFor={amountId}>Amount</Label.Root>
        <Field.Root id={amountId}>
          <Field.Affix>$</Field.Affix>
          <Field.TextInput value={amount} onChange={(event) => setAmount(event.target.value)} />
          <Field.Affix>USD</Field.Affix>
        </Field.Root>
      </Field.Group>
    </>
  );
}
$USD

Affix는 컨트롤이 아니라 텍스트입니다. 장식용 Icon은 aria-hidden입니다. 인터랙티브 Icon은 이름을 유지합니다. 지우기는 내장 prop이 아닙니다. 지우기 버튼이나 비밀번호 보기 버튼처럼 필드의 줄 안에 버튼을 두려면 입력 앞이나 뒤에 아이콘만 있는 Button.Root를 넣으세요. 한 줄 필드에서는 필드 글자 한 줄 높이라서 필드의 높이가 그대로입니다. 포커스가 필드 안에 있으면 버튼을 눌러도 포커스가 그 자리에 남아 입력의 캐럿도 그대로이고, Tab으로는 여전히 버튼에 갈 수 있습니다. 필드의 컨트롤이 아니라 따로인 버튼이라 Field.Root의 disabled가 닿지 않으니, 버튼에도 disabled를 넘기세요. Sign-in and sign-up에 비밀번호 보기 토글이 있습니다.

import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function FieldAdornments() {
  const [amount, setAmount] = useState('12');
  const [search, setSearch] = useState('query');
  return (
    <>
      <Field.Root aria-label="Amount">
        <Field.Affix>$</Field.Affix>
        <Field.TextInput value={amount} onChange={(event) => setAmount(event.target.value)} />
        <Field.Affix>.00</Field.Affix>
      </Field.Root>
      <Field.Root aria-label="Search">
        <Field.Icon>
          <span>⌕</span>
        </Field.Icon>
        <Field.TextInput value={search} onChange={(event) => setSearch(event.target.value)} />
        <Field.Icon interactive>
          <button type="button" aria-label="Clear search" onClick={() => setSearch('')}>
            Clear
          </button>
        </Field.Icon>
      </Field.Root>
    </>
  );
}
$.00

메시지

Description과 ErrorMessage는 셸 아래에 형제 요소로 놓입니다. Field 파트가 아닙니다. aria-describedby는 Field.Root에 두세요. Root가 그 값을 입력에 복사합니다.

import { Description, ErrorMessage, Field, Label } from '@tounsoo/todae';
import { useId, useState } from 'react';

export default function ErrorMessageSibling() {
  const id = useId();
  const hintId = useId();
  const errorId = useId();
  const [email, setEmail] = useState('not-an-email');
  const invalid = email !== '' && !email.includes('@');
  const describedBy = invalid ? `${hintId} ${errorId}` : hintId;
  return (
    <Field.Group>
      <Label.Root htmlFor={id}>Work email</Label.Root>
      <Field.Root id={id} invalid={invalid} aria-describedby={describedBy}>
        <Field.TextInput value={email} onChange={(event) => setEmail(event.target.value)} />
      </Field.Root>
      <Description.Root id={hintId}>We only use this for billing receipts.</Description.Root>
      {invalid ? <ErrorMessage.Root id={errorId}>Enter an address that contains an @.</ErrorMessage.Root> : null}
    </Field.Group>
  );
}
We only use this for billing receipts.Enter an address that contains an @.

이것은 직접 하는 연결입니다. Form 안에서는 Field.Group이 브라우저 자체의 검증을 읽고, id 없는 ErrorMessage.Root가 문제를 보여 주면서 이 연결을 대신 해 줍니다.

Counter

Field.Counter는 Field.TextInput이나 Field.Textarea의 실시간 글자 수를 보여 줍니다. 자체 줄을 차지합니다. 서버 HTML에 글자 수가 포함되도록 입력 뒤에 쓰세요. Field.Root마다 Counter는 하나입니다. 입력은 계속 제어 상태이며, defaultValue는 읽지 않습니다.

import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function CounterDefault() {
  const [value, setValue] = useState('Hello');
  return (
    <Field.Root aria-label="Username">
      <Field.TextInput value={value} onChange={(event) => setValue(event.target.value)} maxLength={20} />
      <Field.Counter />
    </Field.Root>
  );
}
Up to 20 characters15 characters left

같은 줄에 두려면 Counter에 flex-basis: auto를 설정하고, 여전히 마지막에 쓰세요. textarea에서는 그 인라인 글자 수가 마지막 줄에 놓입니다. 각 쌍 아래의 빈 필드는 높이 확인용입니다.

import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function CounterInline() {
  const [value, setValue] = useState('Hello');
  const [note, setNote] = useState('Notes');
  return (
    <>
      <Field.Root aria-label="Username">
        <Field.TextInput value={value} onChange={(event) => setValue(event.target.value)} maxLength={20} />
        <Field.Counter style={{ flexBasis: 'auto' }} />
      </Field.Root>
      <Field.Root aria-label="Username">
        <Field.TextInput value={value} onChange={(event) => setValue(event.target.value)} />
      </Field.Root>
      <Field.Root aria-label="Note">
        <Field.Textarea value={note} onChange={(event) => setNote(event.target.value)} rows={3} maxLength={80} />
        <Field.Counter style={{ flexBasis: 'auto' }} />
      </Field.Root>
      <Field.Root aria-label="Note">
        <Field.Textarea value={note} onChange={(event) => setNote(event.target.value)} rows={3} />
      </Field.Root>
    </>
  );
}
Up to 20 characters15 characters left
Up to 80 characters

좁은 필드입니다. 줄보다 넓은 인라인 글자 수는 입력 아래로 줄바꿈될 수 있습니다.

import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function CounterNarrow() {
  const [value, setValue] = useState('Hi');
  return (
    <div style={{ width: 160 }}>
      <Field.Root aria-label="Price">
        <Field.Affix>$</Field.Affix>
        <Field.TextInput value={value} onChange={(event) => setValue(event.target.value)} maxLength={20} />
        <Field.Counter style={{ flexBasis: 'auto' }} />
      </Field.Root>
    </div>
  );
}
$Up to 20 characters18 characters left

입력 앞에 쓴 Counter도 맨 아래 줄에 놓입니다. 글자 수가 서버 HTML에 들어가도록 입력 뒤에 쓰는 편이 좋습니다.

import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function CounterBefore() {
  const [value, setValue] = useState('Hello');
  return (
    <Field.Root aria-label="Username">
      <Field.Counter />
      <Field.TextInput value={value} onChange={(event) => setValue(event.target.value)} maxLength={20} />
    </Field.Root>
  );
}
import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function CounterTextarea() {
  const [value, setValue] = useState('Notes');
  return (
    <Field.Root aria-label="Note">
      <Field.Textarea value={value} onChange={(event) => setValue(event.target.value)} rows={3} maxLength={80} />
      <Field.Counter />
    </Field.Root>
  );
}
Up to 80 characters

maxLength를 넘으면 글자 수가 오류 색상을 씁니다. 셸은 그대로입니다.

import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function CounterOver() {
  const [value, setValue] = useState('Too long');
  return (
    <Field.Root aria-label="Code">
      <Field.TextInput value={value} onChange={(event) => setValue(event.target.value)} maxLength={4} />
      <Field.Counter />
    </Field.Root>
  );
}
Up to 4 charactersCharacter limit reached

maxLength가 없으면 글자 수는 숫자만 표시됩니다.

import { Field } from '@tounsoo/todae';
import { useState } from 'react';

export default function CounterPlain() {
  const [value, setValue] = useState('Hello');
  return (
    <Field.Root aria-label="Username">
      <Field.TextInput value={value} onChange={(event) => setValue(event.target.value)} />
      <Field.Counter />
    </Field.Root>
  );
}

maxLength가 있으면 Counter는 스크린 리더에 한도를 알리고, 남은 글자가 20자 이하가 되면 몇 자 남았는지도 알립니다. 이 텍스트는 StringsProvider의 characterLimit, charactersLeft, characterLimitReached 문자열에서 오며, 설정하지 않으면 영어입니다.

Row

Field.Row는 전체 너비 줄입니다. 입력 앞에 쓰면 위에, 뒤에 쓰면 아래에 놓입니다. 필드에 아래쪽 줄이 있으면 Field.Counter를 Row 안에 두세요. 채팅의 프롬프트 입력창이라면 예시처럼 필드를 채팅 작성창 멘션 레시피로 감싸고 autoGrow를 쓰세요. Row에 텍스트를 그대로 넣지 말고 Field.Affix로 감싸세요. 뒤쪽 항목은 그 첫 항목에 style={{ marginInlineStart: 'auto' }}를 주어 끝으로 밀어 냅니다. 칩에는 chipLayout="row"를 설정하세요. ChipInput이 자체 칩 줄을 그립니다. Field.Row 안에서 칩을 직접 만들지 마세요.

import { Button, Field } from '@tounsoo/todae';
import { useState } from 'react';

function attachIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
      <path
        d="M6 8.5 9.5 5a2 2 0 0 1 3 3L7 13.5a3 3 0 0 1-4.5-4L8 4"
        fill="none"
        stroke="currentColor"
        strokeWidth="1.5"
      />
    </svg>
  );
}

function PromptComposer() {
  const [value, setValue] = useState('');
  return (
    <form
Up to 280 characters

compact, comfortable, spacious에서의 같은 작성기.

import { Button, DensityProvider, Field } from '@tounsoo/todae';
import { useState } from 'react';

function attachIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
      <path
        d="M6 8.5 9.5 5a2 2 0 0 1 3 3L7 13.5a3 3 0 0 1-4.5-4L8 4"
        fill="none"
        stroke="currentColor"
        strokeWidth="1.5"
      />
    </svg>
  );
}

function PromptComposer() {
  const [value, setValue] = useState('');
  return (
    <form
Up to 280 characters
Up to 280 characters
Up to 280 characters
import { DensityProvider, Field, Label, useChipField } from '@tounsoo/todae';
import { useId, useState } from 'react';

const MANY = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta'];

function ChipRow({ density, chips }: { density: 'compact' | 'comfortable' | 'spacious'; chips: string[] }) {
  const id = useId();
  const field = useChipField({ initialChips: chips });
  return (
    <DensityProvider density={density}>
      <Field.Group>
        <Label.Root htmlFor={id}>Tags</Label.Root>
        <Field.Root id={id} style={{ maxWidth: '18rem' }}>
          <Field.Icon>
            <span>⌕</span>
          </Field.Icon>
          <Field.ChipInput {...field.getChipInputProps()} chipLayout="row" maxRows={2} placeholder="Tags" />
          <Field.Affix>tag</Field.Affix>
        </Field.Root>
      </Field.Group>
alphabetagammadeltaepsilonzetaetatheta
tag
alphabetagammadeltaepsilonzetaetatheta
tag
alphabetagammadeltaepsilonzetaetatheta
tag
tag
tag

커스텀 컨트롤

별점처럼 직접 만든 컨트롤은 useField로 Field.Root에 연결됩니다.

아이콘

Field.Icon에는 어떤 라이브러리의 아이콘도 넣을 수 있고, 그 안에 바로 들어간 svg나 img는 field.icon.size 토큰의 크기를 따릅니다. Field.Select와 Field.ChipInput이 그리는 글리프는 각 파트의 페이지에 있습니다.

import { Search } from 'lucide-react';

<Field.Root aria-label="Search">
  <Field.Icon>
    <Search />
  </Field.Icon>
  <Field.TextInput />
</Field.Root>

접근성을 지키는 조합

Todae가 맡는 것: Field.Root는 자신의 id, name, aria-label, aria-labelledby, aria-describedby를 입력에 넘깁니다. 다른 ARIA props는 셸 div에 남습니다. 입력은 Root나 바깥 Fieldset에서 네이티브 disabled와 aria-invalid를 받습니다. 셸을 누르면 입력에 포커스가 가고, 입력이 focus-visible인 동안 셸이 포커스 링을 그립니다. 장식용 Field.Icon은 aria-hidden입니다. maxLength가 있으면 Field.Counter가 한도를 입력의 설명에 더하고, 20자 남았을 때부터 남은 글자 수를 알립니다.

직접 제공할 것: 이름. htmlFor가 Root id인 Label이나, Root의 aria-label / aria-labelledby입니다. Description이나 ErrorMessage의 id는 Root의 aria-describedby에 넣고, 오류가 보이는 동안 invalid를 켜세요. 상호작용하는 Field.Icon 안의 버튼마다 이름을 주세요. 글자 수 문구는 StringsProvider로 제품의 언어에 맞추세요.

주의할 점: Field.TextInput에 준 id는 Root의 id로 바뀝니다. id는 Root에 두세요. Field.Root에 준 role이나 onClick은 셸에 붙는데, 셸은 컨트롤이 아닙니다. 오버레이는 실제 버튼으로 여세요. invalid는 입력을 유효하지 않다고 표시하지만 이유는 말하지 않으므로 ErrorMessage를 함께 보여 주세요.

언제 쓰나요

Field.Root

언제: 텍스트, textarea, 칩 입력 하나를 위한 공유 필드 외형 — 포커스 링, disabled/invalid, 밀도. 값은 입력 파트에 있습니다.

쓰지 않을 때: 선택 컨트롤(Checkbox / Radio / Switch). 버튼인 오버레이 트리거. 안에 다른 컴파운드 루트를 중첩할 때.

Field.Icon

언제: Root 안의 앞쪽/뒤쪽 아이콘이나 아이콘 컨트롤. 위치 = DOM 순서. 장식용 → interactive={false}(aria-hidden).

쓰지 않을 때: 텍스트 장식 → Affix. 지우기나 비밀번호 보기 버튼 → Root 안의 아이콘만 있는 Button.Root.

Field.Row

언제: 필드 안에서 파트를 자체 전체 너비 줄로 묶을 때. 예를 들어 Field.ChipInput 위의 칩, 또는 Field.Textarea 아래의 첨부, Field.Counter, 보내기.

쓰지 않을 때: 입력 옆의 Icon이나 Affix 하나는 Row 없이 인라인으로 구성하고, 별개의 필드를 배치하는 데 Row를 쓰지 마세요.

Field.Group

언제: 레이블이나 캡션을 컨트롤 위 field.label.gap 간격에 두고, Description이나 ErrorMessage를 그 아래에 쌓을 때. Field.Root 바깥에 두며, Text.Root 캡션 아래의 RadioGroup처럼 어떤 컨트롤에도 씁니다. Form 안에서는 그 안의 컨트롤에 대한 검증 범위이기도 합니다.

쓰지 않을 때: 서로 다른 필드 사이 간격은 Stack.Root를 쓰세요. 관련 컨트롤을 범례 하나로 묶을 때는 Fieldset을 쓰세요.

Field.Affix

언제: Root 안의 정적 텍스트 장식(통화, 단위). 순서 = 위치.

쓰지 않을 때: 아이콘 → Icon. 인터랙티브 컨트롤 — Affix는 클릭할 수 없습니다.

Field.Counter

언제: Field.TextInput이나 Field.Textarea의 실시간 글자 수를 보여 줄 때. maxLength가 설정되면 n / max로, 그렇지 않으면 n으로 표시합니다. 쓰지 않을 때: 글자 수를 보이지 않는 엄격한 제한에는 maxLength만 설정하고, 코드나 PIN 같은 짧은 고정 길이 값에는 쓰지 마세요.

Props

Field.Root props
이름타입설명
disabledboolean

입력을 비활성화하고 셸도 비활성 상태로 표시합니다.

기본값: false

invalidboolean

셸을 유효하지 않음으로 표시하고 입력에 aria-invalid를 설정합니다.

기본값: false

customValiditystring

브라우저가 검사할 수 없는 규칙의 메시지입니다. 필드의 컨트롤이 네이티브 input, select, textarea일 때 그 컨트롤에, 아니면 값 입력(value input)에 setCustomValidity로 설정합니다. 읽기 전용인 Field.DateInput, Field.TimeInput, Field.DateTimeInput, Field.DateRangeInput도 값 입력에 둡니다. 폼은 그 텍스트 입력을 검사하지 않지만 값 입력은 여전히 제출을 막기 때문입니다. 빈 문자열이나 undefined는 규칙이 지켜졌다는 뜻입니다.

idstring

입력 id. 생략하면 자동 생성됩니다.

aria-describedbystring

Description과 ErrorMessage의 id. Root에 넣습니다. 입력 파트는 자기 id를 이 뒤에 더합니다.

namestring

네이티브 입력 name.

refRef<HTMLDivElement>

셸 요소. Popover의 anchorRef로 씁니다.

childrenReact.ReactNode

TextInput 또는 ChipInput과 선택적인 Icon, Affix. 순서에 따라 앞쪽 또는 뒤쪽에 놓입니다.

Field.Icon props
이름타입설명
childrenReact.ReactNode

아이콘 또는 컨트롤.

interactiveboolean

false면 래퍼가 aria-hidden이 됩니다.

기본값: false

Field.Affix props
이름타입설명
childrenReact.ReactNode

Affix 내용. 문자열은 텍스트로 렌더링됩니다.

Field.Row props
이름타입설명
childrenReact.ReactNode

줄에 놓을 파트. 칩, 버튼, Field.Counter 등.

classNamestring

행에 붙는 추가 클래스.

Field.Group props
이름타입설명
childrenReact.ReactNode

레이블이나 캡션, 컨트롤, 그리고 Description.Root와 ErrorMessage.Root.

classNamestring

그룹에 붙는 추가 클래스.

Field.Counter props
이름타입설명
classNamestring

카운트에 붙는 클래스. 인라인 flex-basis 재정의에 씁니다.

styleReact.CSSProperties

인라인 스타일. flex-basis: auto면 카운트가 입력 행에 놓입니다.