Field
Shared chrome. Field.Root is the compound scope. The bordered shell is Root. Value lives on Field.TextInput, Field.NumberInput, Field.OneTimeCode, Field.Textarea, Field.ChipInput, Field.Select, Field.DateInput, Field.DateRangeInput, Field.TimeInput or Field.DateTimeInput. Field.Picker is a button beside one of them that opens a panel to pick the value in. Adornments are order-only: put Icon / Affix before the input to lead, after to trail. No side prop. Label.Root is a sibling, not a compound part. Every part inside the field (input, Icon, Affix, chips) is one field line tall, and the shell's padding is the inset.
On this page
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>
</>
);
}
Inputs
Each input part has its own page:
- Field.TextInput: a single line of text.
- Field.NumberInput: a number typed in the locale's format or stepped, with
Field.IncrementandField.Decrementbuttons beside it. - Field.OneTimeCode: a sign-in or verification code drawn as boxes over one input.
- Field.Textarea: multi-line text.
- Field.ChipInput: chips plus an input.
- Field.Select: the native
<select>. There is no JavaScript listbox. Children are<option>or<optgroup>, and a browser that supports it draws the control withappearance: base-select. - Field.DateInput: a date, typed in the locale's own way.
- Field.DateRangeInput: a start and an end date, typed in the locale's own way.
- Field.TimeInput: a time of day, typed in the locale's own way.
- Field.DateTimeInput: a date and a time, typed in the locale's own way.
- Field.Picker: a button that opens a panel, such as a calendar, a list of times or a color picker, beside the input that holds the value.
Label
Label.Root is a sibling, not a compound part. It takes the same id you pass to Field.Root. Wrap the pair in one Field.Group, which puts the label field.label.gap above the shell. See Label for the API.
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 works with Icon, Affix, and 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>
</>
);
}
Affix is text, not a control. Decorative Icon is aria-hidden. Interactive Icon keeps its name. Clear is not a built-in prop. For a button in the field's line, such as a clear button or a password's show button, put an icon-only Button.Root before or after the input: in a one-line field it is one field line tall, so the field keeps its height. A press on it leaves focus where it is when focus is in the field, so an input's caret stays; Tab still reaches it. It is a button of its own, not the field's control, and Field.Root's disabled doesn't reach it; pass disabled to it too. Sign-in and sign-up shows a show-password toggle.
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>
</>
);
}
Messages
Description and ErrorMessage sit under the shell as siblings. They are not Field parts. Put aria-describedby on Field.Root. Root copies it onto the input.
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>
);
}
That is the wiring by hand. Inside a Form, a Field.Group reads the browser's own validation, and an ErrorMessage.Root with no id shows the problem and does this wiring for you.
Counter
Field.Counter shows a live count for Field.TextInput or Field.Textarea. It takes its own row. Write it after the input so the server HTML includes the count. One counter per Field.Root. The input stays controlled; defaultValue is not read.
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>
);
}
On the same row, set flex-basis: auto on the Counter and still write it last. On a textarea that inline count sits on the last line. The bare field under each pair is the height check.
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>
</>
);
}
A narrow field. An inline count wider than the row can wrap under the input.
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>
);
}
A Counter written before the input still sits on the bottom row. Prefer writing it after the input so the count is in the server 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>
);
}
Past maxLength the count uses the error color. The shell stays as it is.
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>
);
}
Without maxLength the count is just the number.
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>
);
}
With maxLength, the Counter also tells screen readers the limit and, from 20 characters left, how many remain. That text comes from the characterLimit, charactersLeft and characterLimitReached strings of StringsProvider, English unless you set them.
Row
A Field.Row is a full-width line. Write it before the input to sit above, or after to sit below. Put Field.Counter inside the Row when the field has a bottom row. For the prompt input of a chat, wrap the field in the chat composer mentions recipe, as the example does, and use autoGrow. Don't put bare text in a Row; wrap it in Field.Affix. Push trailing items to the end with style={{ marginInlineStart: 'auto' }} on the first of them. For chips, set chipLayout="row"; ChipInput draws its own chip line. Don't hand-roll chips in a 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
onSubmit={(event) => {
event.preventDefault();
setValue('');
}}
>
<Field.Root aria-label="Message">
<Field.Textarea
value={value}
onChange={(event) => setValue(event.target.value)}
autoGrow
maxRows={6}
maxLength={280}
/>
<Field.Row>
<Button.Root variant="ghost" aria-label="Attach file">
<Button.Icon>{attachIcon()}</Button.Icon>
</Button.Root>
<Field.Counter />
<Button.Root type="submit" variant="primary" disabled={value.trim() === ''} aria-label="Send">
Send
</Button.Root>
</Field.Row>
</Field.Root>
</form>
);
}
export default function RowComposer() {
return <PromptComposer />;
}
The same composer at compact, comfortable, and 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
onSubmit={(event) => {
event.preventDefault();
setValue('');
}}
>
<Field.Root aria-label="Message">
<Field.Textarea
value={value}
onChange={(event) => setValue(event.target.value)}
autoGrow
maxRows={6}
maxLength={280}
/>
<Field.Row>
<Button.Root variant="ghost" aria-label="Attach file">
<Button.Icon>{attachIcon()}</Button.Icon>
</Button.Root>
<Field.Counter />
<Button.Root type="submit" variant="primary" disabled={value.trim() === ''} aria-label="Send">
Send
</Button.Root>
</Field.Row>
</Field.Root>
</form>
);
}
export default function RowComposerDensity() {
return (
<>
{(['compact', 'comfortable', 'spacious'] as const).map((density) => (
<DensityProvider key={density} density={density}>
<PromptComposer />
</DensityProvider>
))}
</>
);
}
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>
</DensityProvider>
);
}
export default function RowChipInput() {
const emptyId = useId();
const textId = useId();
const empty = useChipField({ initialChips: [] });
const [text, setText] = useState('');
return (
<>
{(['compact', 'comfortable', 'spacious'] as const).map((density) => (
<ChipRow key={density} density={density} chips={MANY} />
))}
<Field.Group>
<Label.Root htmlFor={emptyId}>Tags</Label.Root>
<Field.Root id={emptyId}>
<Field.Icon>
<span>⌕</span>
</Field.Icon>
<Field.ChipInput {...empty.getChipInputProps()} chipLayout="row" placeholder="No chips" />
<Field.Affix>tag</Field.Affix>
</Field.Root>
</Field.Group>
<Field.Group>
<Label.Root htmlFor={textId}>Tags</Label.Root>
<Field.Root id={textId}>
<Field.Icon>
<span>⌕</span>
</Field.Icon>
<Field.TextInput
value={text}
onChange={(event) => setText(event.target.value)}
placeholder="Same adornments"
/>
<Field.Affix>tag</Field.Affix>
</Field.Root>
</Field.Group>
</>
);
}
Custom controls
Your own control, such as a rating, joins a Field.Root through useField.
Icons
Field.Icon takes an icon from any library; an svg or img directly inside it takes the field.icon.size token. The glyphs that Field.Select and Field.ChipInput draw are on their own pages.
import { Search } from 'lucide-react';
<Field.Root aria-label="Search">
<Field.Icon>
<Search />
</Field.Icon>
<Field.TextInput />
</Field.Root>
Accessible composition
Todae handles: Field.Root hands its id, name, aria-label, aria-labelledby and aria-describedby to the input. Other ARIA props stay on the shell div. The input gets native disabled and aria-invalid from the Root, or from a surrounding Fieldset. A press on the shell focuses the input, and the shell draws the focus ring while the input is focus-visible. A decorative Field.Icon is aria-hidden. With maxLength, Field.Counter adds the limit to the input's description and, from 20 characters left, announces what remains.
You supply: A name: a Label whose htmlFor is the Root id, or aria-label / aria-labelledby on the Root. The ids of any Description or ErrorMessage in the Root's aria-describedby, and invalid while the error shows. A name for every button inside an interactive Field.Icon. Counter strings in the product's language, through StringsProvider.
Watch for: An id on Field.TextInput is replaced by the Root's; put it on the Root. A role or onClick on Field.Root lands on the shell, which is not a control; open overlays from a real button. invalid marks the input invalid but does not say why, so show an ErrorMessage with it.
When to use
Field.Root
When: Shared field chrome for one text, textarea, or chip input — focus ring, disabled/invalid, density. Value lives on the input part.
When not: Selection controls (Checkbox / Radio / Switch). Overlay triggers that are buttons. Nesting another compound root inside.
Field.Icon
When: Leading/trailing icon or icon control inside Root. Position = DOM order. Decorative → interactive={false} (aria-hidden).
When not: Text adornments → Affix. A clear or show-password button → an icon-only Button.Root in the Root.
Field.Row
When: Group parts on their own full-width line inside the field, such as chips above a Field.ChipInput or attach, Field.Counter and send below a Field.Textarea.
When not: For a single Icon or Affix beside the input, compose it inline without a Row, and don't use a Row to lay out separate fields.
Field.Group
When: Stack a label or caption field.label.gap above its control, with any Description or ErrorMessage below. It sits outside Field.Root and works for any control, such as a RadioGroup under a Text.Root caption. Inside a Form it is also a validation scope for the controls in it.
When not: To space separate fields from each other, use Stack.Root. To group related controls under one legend, use Fieldset.
Field.Affix
When: Static text adornment (currency, unit) inside Root. Order = position.
When not: Icons → Icon. Interactive controls — Affix is not clickable.
Field.Counter
When: Show a live character count for a Field.TextInput or Field.Textarea, as n / max when maxLength is set and n otherwise.
When not: For a hard limit with no visible count, set maxLength alone, and skip it on short fixed-length values like codes or PINs.
Props
| Name | Type | Description |
|---|---|---|
disabled | boolean | Disables the input and marks the shell. Default: false |
invalid | boolean | Marks the shell invalid and sets aria-invalid on the input. Default: false |
customValidity | string | A message for a rule the browser cannot check, set with setCustomValidity on the field's control when that is a native input, select or textarea, else on its value input. A read-only Field.DateInput, Field.TimeInput, Field.DateTimeInput or Field.DateRangeInput gives it to its value input too, since a form leaves the text input unchecked and the value input still blocks a submit. An empty string or undefined means the rule holds. |
id | string | Input id. Auto-generated when omitted. |
aria-describedby | string | Ids of Description and ErrorMessage. Put this on Root. Input parts add their own ids after these. |
name | string | Native input name. |
ref | Ref<HTMLDivElement> | Shell element. Use as a Popover anchorRef. |
children | React.ReactNode | TextInput or ChipInput plus optional Icon and Affix. Order is leading/trailing. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Icon or control. |
interactive | boolean | When false, the wrapper is aria-hidden. Default: false |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Affix content. Strings render as text. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Parts for the line, such as chips, buttons or Field.Counter. |
className | string | Extra class on the row. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | A label or caption, the control, then any Description.Root and ErrorMessage.Root. |
className | string | Extra class on the group. |
| Name | Type | Description |
|---|---|---|
className | string | Class on the count. Use it for the inline flex-basis override. |
style | React.CSSProperties | Inline style. flex-basis: auto places the count on the input row. |