Fields
Live examples of every shipped @zeno-lib/forms field
Every shipped field handles its own label, description, and error message,
and sets aria-invalid and aria-describedby on its control. Destructure a
field from the form returned by useForm and drop it inside <Form>. Its
name prop autocompletes against your schema (or defaultValues when you
pass no schema).
const form = useForm({ schema })
const { InputField, SubmitButton } = form
<FormProvider form={form}>
<Form>
<FieldGroup>
<InputField name="…" />
</FieldGroup>
<SubmitButton>Save</SubmitButton>
</Form>
</FormProvider>Every field accepts an optional validators prop, which it forwards to
TanStack Form's <Field> to add checks to that one field. See
Validation modes.
name is required on every field, presets included. Array rows use
TanStack Form's bracket syntax (name="members[0].name").
Test hooks
Every field's root <Field> element renders data-field={name}, a stable
hook for end-to-end tests that doesn't depend on labels or copy:
const email = page.locator('[data-field="email"]')
await expect(email.getByRole("textbox")).toHaveAttribute("aria-invalid", "true")
await expect(page.locator('[data-field="members[1].name"]')).toBeVisible()The root also carries data-invalid, and the control inside carries
aria-invalid="true" while its error is shown.
Disabling the form
Disable the whole form with useForm({ disabled }),
<FormProvider disabled> or FormDialog's disabled. Every field turns off,
the checkbox, switch, radio and slider fields included, and so do
SubmitButton and ResetButton. <Form disabled> does the same for what it
wraps, and ignores a submit. A button outside the <form> (form="profile")
isn't wrapped, so reach it with one of the others.
const form = useForm({ disabled: !canEdit, schema })A field's own disabled still disables that field alone, and
disabled={false} doesn't enable a field in a disabled form. Each form keeps
its own state: a form rendered inside a disabled one (a quick-add popover)
stays enabled. A control of your own reads the state with
useIsFormDisabled(), or gets it in disabled through
ControlField. Only FormDialog also disables native
controls of your own, through a <fieldset disabled>.
Input field
<InputField
description="Shown next to your avatar."
label="Display name"
name="name"
placeholder="Ada Lovelace"
/>Email field
EmailField is a preset over InputField that sets type="email",
inputMode="email", and autoComplete="email", and turns off
auto-capitalisation, autocorrect and spell check. It defaults label to
"Email"; name is required, as on every other field.
<EmailField name="email" placeholder="you@zeno.dev" />Password field
PasswordField is a preset over InputField that sets type="password"
and autoComplete="current-password". Pass autoComplete="new-password" on
a signup form. It defaults label to "Password"; name is required.
<PasswordField autoComplete="new-password" name="password" />Text area field
<TextAreaField
description="160 characters max."
label="Bio"
name="bio"
placeholder="I build things on the web."
/>Number field
NumberField stores the input as a number (its
empty value
when emptied), so
you never convert the input's string yourself. It sets inputMode="decimal",
so phone keypads keep the decimal key; pass inputMode="numeric" for whole
numbers.
<NumberField label="Age" min={13} name="age" />Money field
MoneyField is a text input that shows the currency as an addon. It
re-inserts the locale's thousands separators as the user types and keeps the
caret in place. The form value is a number, or the field's
empty value
when emptied (null when the schema allows nothing else). The
field also accepts pasted amounts in other locales' formats: CHF 1'234.50,
1.234,50 € and 1,234.50 all become 1234.5, whatever the input's locale.
On blur, the field pads a non-integer amount to the currency's minor units
(12.5 becomes 12.50); integers stay bare.
<MoneyField currency="CHF" label="Budget" locale="de-CH" name="budget" />| Prop | Type | What it does |
|---|---|---|
currency | string | ISO 4217 code for the addon ("CHF", "EUR"). Omit for a bare amount. |
currencyDisplay | "symbol" | "narrowSymbol" | "code" | "name" | How the addon reads. Defaults to "symbol". |
currencyPosition | "start" | "end" | Which side the addon sits on. Defaults to the locale's convention (CHF 1’234 in de-CH, 1.234 € in de-DE). |
locale | string | BCP 47 locale for the separators. Defaults to the runtime locale. |
fractionDigits | number | Decimals allowed. Defaults to the currency's minor units (2 for CHF, 0 for JPY), else 2. |
allowNegative | boolean | Accept a leading minus. Defaults to false. |
min / max | number | Clamp on blur. For an error message instead, validate in the schema. |
While the user types, only the locale's decimal separator starts the
fraction (. in de-CH, , in de-DE), and the field drops any other
non-digit character.
To give every MoneyField your app's currency and locale, set them once in
default props.
Percentage field
PercentageField uses the same formatting hook as MoneyField, with a %
addon. Pick what the form value means with scale:
scale="percent"(default): the value is the number shown, so12.5shows as12.5 %.scale="fraction": the value is a ratio, so0.125shows as12.5 %, which is what most APIs and databases store.
<PercentageField label="Interest rate" name="rate" scale="fraction" />fractionDigits (default 2) counts the decimals of the shown percentage.
min/max clamp on blur, in the form value's scale, and default to 0 and
100 % (0–1 on the fraction scale), as a percentage() column's do. Pass
max for a ratio that can exceed 100 %, or a min below 0 for a rate that
can go negative. allowNegative defaults to whether min is below 0.
A field bound to a
percentage() column
takes scale from the column's hint, and min and max from its schema's
.min() and .max(), a refinement's included, so it needs none of the three
props. A prop wins, and so does one from defaultProps, which is why no
scale, min or max belongs there. The hint sits in a registry of its own,
not in .meta(), so z.toJSONSchema never sees it.
Year field
YearField takes a four-digit integer year (number | null). It accepts
digits only, with no thousands separator, and sets inputMode="numeric".
min/max clamp the value on blur, and a min below 0 lets it take a
negative year. A field bound to a year() column takes them from the column's
schema, as PercentageField does.
<YearField label="Founded" max={2100} min={1900} name="founded" />Formatting your own inputs
The three fields above are thin wrappers over a headless hook that ships on
npm. Spread its result on any <input>:
import { useFormattedNumber } from "@zeno-lib/forms/lib/use-formatted-number"
const inputProps = useFormattedNumber({
locale: "de-CH",
maximumFractionDigits: 3,
onBlur: field.handleBlur,
onValueChange: field.handleChange,
value: field.state.value,
})
<InputGroupInput {...inputProps} />It returns value, onChange, onBlur, onPaste, inputMode and
type="text". It also takes padFraction, useGrouping, allowNegative,
maxIntegerDigits, min/max, and a toDisplay/fromDisplay pair that
maps the stored value to the shown number and back (that's how
scale="fraction" works). The pure helpers
(parseLocaleNumber, formatNumber, …) live in
@zeno-lib/forms/lib/formatted-number.
Composing addons (input groups)
InputField, EmailField, PasswordField, NumberField, and
TextAreaField accept addon children that render inside an
<InputGroup>:
prefix icons, suffix actions, block-level toolbars. Without children the
field renders a plain input.
<InputGroupAddon align> accepts inline-start, inline-end,
block-start, and block-end. CSS sets the visual order, so the JSX order
doesn't matter.
Prefix icon
import { InputGroupAddon } from "@zeno-lib/ui/input-group"
import { MailIcon } from "lucide-react"
<EmailField name="email" placeholder="you@zeno.dev">
<InputGroupAddon align="inline-start">
<MailIcon />
</InputGroupAddon>
</EmailField>Prefix and suffix text
import { InputGroupAddon, InputGroupText } from "@zeno-lib/ui/input-group"
<InputField label="Handle" name="handle" placeholder="acme">
<InputGroupAddon align="inline-start">
<InputGroupText>https://</InputGroupText>
</InputGroupAddon>
<InputGroupAddon align="inline-end">
<InputGroupText>.zeno.dev</InputGroupText>
</InputGroupAddon>
</InputField>Block toolbar
block-start and block-end render above and below the input inside the
same focus ring. Use them for textarea toolbars, helper rows, or character
counters.
import { InputGroupAddon, InputGroupButton } from "@zeno-lib/ui/input-group"
import { BoldIcon, ItalicIcon } from "lucide-react"
<TextAreaField label="Bio" name="bio" placeholder="I build things on the web.">
<InputGroupAddon align="block-start">
<InputGroupButton type="button">
<BoldIcon />
</InputGroupButton>
<InputGroupButton type="button">
<ItalicIcon />
</InputGroupButton>
</InputGroupAddon>
</TextAreaField>Async-validation indicator
@zeno-lib/forms ships <ValidationSpinner />, which shows a spinner in the
input while an async validator runs and renders nothing once it resolves. See
the
Async submission example
for a full setup.
import { ValidationSpinner } from "@zeno-lib/forms/create-form"
<EmailField
name="email"
placeholder="Try taken@example.com"
validators={{
onChangeAsync: async ({ value }: { value: string }) => {
const taken = await checkEmailAvailable(value)
return taken ? "Email already in use" : undefined
},
onChangeAsyncDebounceMs: 500,
}}
>
<ValidationSpinner />
</EmailField>For other state-dependent addons, write a small component that calls
useFieldContext() and returns an addon (or null). The field's
children render inside the field context, so useFieldContext() returns
that field's state.
Don't toggle children directly.
<EmailField>{cond && <Addon />}</EmailField>swaps the field between a plain<Input>and an<InputGroup>wrapper, which remounts the input, so it loses focus. Always render the child element, and let it returnnullwhen it has nothing to show, asValidationSpinnerdoes.
Select field
SelectField wraps @zeno-lib/ui/select. Pass <SelectItem> children for
the options. For database rows with numeric IDs, see
Numeric IDs.
import { SelectItem } from "@zeno-lib/ui/select"
<SelectField label="Role" name="role" placeholder="Pick a role">
<SelectItem value="engineer">Engineer</SelectItem>
<SelectItem value="designer">Designer</SelectItem>
<SelectItem value="manager">Manager</SelectItem>
</SelectField>Checkbox field
<CheckboxField
description="You can revoke this at any time."
label="I accept the terms of service"
name="terms"
/>Checkbox group field
CheckboxGroupField binds a set of checkboxes to one array value ([] when
none is checked) and renders them as a <fieldset> with the label as its
legend. Pass items as strings or numbers, or as
{ value, label, description?, disabled? } objects. The stored array follows
the order of items, not click order.
<CheckboxGroupField
items={[
{ label: "Email", value: "email" },
{ label: "SMS", value: "sms" },
{ description: "Coming soon.", disabled: true, label: "Push", value: "push" },
]}
label="Notification channels"
name="channels"
/>orientation="horizontal" wraps the options in a row; disabled disables
the whole group.
Switch field
<SwitchField
description="Get notified when something needs your attention."
label="Push notifications"
name="pushNotifications"
/>Radio group field
RadioGroupField wraps @zeno-lib/ui/radio-group. <RadioGroupFieldItem>
pairs each radio with its label and htmlFor, so you don't wire IDs by hand.
import { RadioGroupFieldItem } from "@zeno-lib/forms/create-form"
<RadioGroupField label="Plan" name="plan">
<RadioGroupFieldItem value="free">Free</RadioGroupFieldItem>
<RadioGroupFieldItem value="pro">Pro</RadioGroupFieldItem>
<RadioGroupFieldItem value="team">Team</RadioGroupFieldItem>
</RadioGroupField>Each item's value is stored as is, so value={true} or value={2} gives a
boolean or a number, not a string. Nothing picked is undefined.
Slider field
SliderField wraps @zeno-lib/ui/slider. The form value is a number for a
single thumb and a number[] for a range; the type of your defaultValues
picks which. Pass formatValue to render a live readout next to the label.
<SliderField
description="Used for notification chimes."
formatValue={(v) => `${Array.isArray(v) ? v[0] : v}%`}
label="Volume"
max={100}
min={0}
name="volume"
step={1}
/>OTP field
OtpField wraps @zeno-lib/ui/input-otp and defaults to one group of 6
slots. Change the count with maxLength, restrict input with pattern (a
string regex), or pass children to insert a separator between groups.
<OtpField
description="We sent a code to your email."
label="Verification code"
name="code"
pattern="^[0-9]+$"
/>Date picker field
DatePickerField composes @zeno-lib/ui/popover and @zeno-lib/ui/calendar.
The form value is a Date at local midnight of the picked day, or the field's
empty value.
By default the trigger formats the selected date with toLocaleDateString,
and the calendar opens on its month. Pass formatValue to override the
format, or calendarProps to forward options (disabled, locale, …) to the
underlying <Calendar>. disabled on the field itself disables the trigger.
<DatePickerField
description="Used for age-restricted features."
label="Birthday"
name="birthday"
/>Dates as strings
Dates usually travel as ISO strings. Pick one with valueType:
"iso-date": the day asYYYY-MM-DD, as adatecolumn stores it andz.iso.date()accepts it."iso-datetime": the day's local midnight as an ISO 8601 timestamp, for a timestamp column andz.iso.datetime(). October 9 picked in Zurich is2026-10-08T22:00:00.000Z, which a viewer in New York reads as October 8, as they would aDate. Store a day that must read the same everywhere as"iso-date".
<DatePickerField label="Due date" name="dueDate" valueType="iso-date" />The field reads a Date or either string, whatever valueType says. It reads
YYYY-MM-DD as that day in the user's time zone, where
new Date("2026-10-09") would read UTC midnight, which is October 8 anywhere
west of UTC. The helpers are in @zeno-lib/forms/lib/date-value
(parseDateValue, toDateValue, formatIsoDate), for a date control of
your own.
Combobox field
ComboboxField wraps @zeno-lib/ui/combobox. It selects a single value and
filters the options client-side as the user types. Pass plain strings for
string[] items, or { value, label } objects when the value isn't a string;
see
Numeric IDs.
const FRAMEWORKS = ["Next.js", "Remix", "SvelteKit", "Nuxt.js", "Astro"]
<ComboboxField
description="Filter as you type."
emptyMessage="No framework matches."
items={FRAMEWORKS}
label="Favourite framework"
name="framework"
placeholder="Search frameworks…"
/>| Prop | Type | What it does |
|---|---|---|
items | T[] (string, { value, label }, or { label, items } groups) | Options shown in the dropdown. Filtered client-side unless filter={null}. |
isItemEqualToValue | (itemValue, value) => boolean | Whether an item's value is the stored one. Defaults to Object.is; pass it for object values. |
renderItem | (item) => ReactNode | Override per-row rendering. Gets each item, a group's included, never the group. |
emptyMessage | ReactNode | Shown when filtering produces zero matches. |
showClear | boolean | Show the clear button when a value is selected. Defaults to true on an optional field and false on a required one. |
placeholder | string | Input placeholder when the field is empty. |
inputValue | string | Controlled search text. Pair with onInputValueChange. |
onInputValueChange | (value: string) => void | Fires on every keystroke in the search input. |
filter | ((item, query) => boolean) | null | Replace the built-in filter, or null for server-driven search. |
loading | boolean | Show a spinner inside the input while options load. |
disabled | boolean | Disable the input and its buttons. |
For server-driven search with debouncing, see Async-search combobox.
With { value, label } items, the input shows a stored value only once
items holds its item, so an id never shows raw while options load.
Groups and object values
Pass { label, items } groups as items to show the options under headings.
Plain items beside a group show under no heading. An item's value can be an object, such as a reference into one of several
tables. A refetch rebuilds those objects, so pass isItemEqualToValue to
compare them by what identifies them, as Base UI's Combobox does. Type its
parameters: form.ComboboxField can't infer them from items.
type Party = { kind: "company" | "person"; id: number }
const parties = [
{
label: "People",
items: people.map((p) => ({ label: p.name, value: { kind: "person", id: p.id } })),
},
{
label: "Companies",
items: companies.map((c) => ({ label: c.name, value: { kind: "company", id: c.id } })),
},
]
<ComboboxField
isItemEqualToValue={(a: Party, b: Party) => a.kind === b.kind && a.id === b.id}
items={parties}
label="Payer"
name="payer"
/>Clearing stores the field's
empty value,
null for a .nullable() object. MultiSelectField takes the same items
and isItemEqualToValue, and keeps a stored value whose item items doesn't
hold yet (its group still loading) when the user picks another.
shadcn's ComboboxClear is an icon with no accessible name. Give it one in
your copy of combobox.tsx (aria-label="Clear"), as Zeno's does.
Multi-select field
MultiSelectField is a multi-value combobox that renders the selection as
removable chips inside the input. The form value is an array of the selected
values ([] when empty). For string and number items it holds the items
themselves; for { value, label } objects it holds item.value, so numeric
IDs stay numbers. A clear button empties the selection.
const LANGUAGES = [
{ label: "English", value: "en" },
{ label: "French", value: "fr" },
{ label: "German", value: "de" },
]
<MultiSelectField
items={LANGUAGES}
label="Languages"
name="languages"
placeholder="Search languages…"
/>| Prop | Type | What it does |
|---|---|---|
items | T[] (string, number, { value, label }, or { label, items } groups) | Options, filtered client-side as the user types. |
isItemEqualToValue | (itemValue, value) => boolean | Whether an item's value is a stored one. Defaults to Object.is; pass it for object values. |
renderItem | (item) => ReactNode | Override per-row rendering. Gets each item, a group's included, never the group. |
emptyMessage | ReactNode | Shown when filtering produces zero matches. |
placeholder | string | Shown while nothing is selected. |
showClear | boolean | Show the clear-all button. Defaults to true. |
clearLabel | string | Accessible label of the clear button. Defaults to "Clear". |
disabled | boolean | Disable the whole control. |
For on-the-fly creation, compose your own; see Combobox: multi-select, grouped, creatable.
Custom fields
Control field
ControlField binds a controlled component the kit has no field for (a
phone input, a star rating, a color picker) in one line, in the same layout
as the other fields: the label with its *, the description, the error,
data-field, and the ids and aria-* that tie them to the control.
import { StarRating } from "@/components/star-rating"
<ControlField
description="Tap a star."
label="Rating"
name="rating"
render={(control) => <StarRating {...control} />}
/>render gets the props that bind the control to the field. They are typed
with the value at name, so a control whose value type doesn't match the
field's fails to compile.
| Prop | What it does |
|---|---|
value | The field's value, as stored, its empty value (undefined or null) included. A control that needs a defined value maps it (value ?? ""), or it turns uncontrolled once the field empties. |
onChange(value) | Stores the value. An empty one (null, undefined, "", NaN or []) stores the field's empty value instead. It takes a value, not a change event, and throws on one. It is stable across renders. |
onBlur | Marks the field touched, so its error can show. |
id, name, disabled | For the control's focusable element. The label's htmlFor points at id. disabled is the field's own or the form's. |
aria-labelledby | The label, for a control a <label htmlFor> can't name (a role="radiogroup"). |
aria-describedby, aria-invalid, aria-required | The description and error, and the field's state. Keep aria-invalid on the focusable element, or a group root around it: a failed submit focuses the first invalid field by it. |
A control that reports a change event, or holds a value of another shape,
maps them in render:
<ControlField
label="Phone"
name="phone"
render={({ onChange, value, ...control }) => (
<PhoneInput
{...control}
onChange={(event) => onChange(event.target.value)}
value={value ?? ""}
/>
)}
/>ControlField also takes description, label, disabled and required,
like the other fields. Inside <AppField>, it is field.ControlField, and
its value type comes from the control's annotation
(render={(control: FieldControlProps<string>) => …}) or a type argument.
Your own field component
To reuse a control across forms, write a field component with the hook
ControlField is built on, useFieldControl from
@zeno-lib/forms/lib/use-field-control, and the kit's FieldShell. Put it
next to the kit's fields and add it to fieldComponents in your
create-form, and form.RatingField gets a typed name like the others.
"use client"
import { useFieldControl } from "@zeno-lib/forms/lib/use-field-control"
import type { ReactNode } from "react"
import { StarRating } from "@/components/star-rating"
import { FieldShell } from "./field-shell"
type RatingFieldProps = {
description?: ReactNode
label?: ReactNode
required?: boolean
}
function RatingField({ description, label, required }: RatingFieldProps) {
const { controlProps, ...shell } = useFieldControl<number | null>({
description,
label,
required,
})
return (
<FieldShell {...shell} description={description} label={label}>
<StarRating {...controlProps} />
</FieldShell>
)
}Pass the hook the description and label you render, so the control points
at them. It returns controlProps for the control, and for the layout the
ids, isDisabled, isInvalid, isRequired, showRequiredIndicator (off under
requiredIndicator: false) and the errors to show (none while the form's
validation mode or
hideFieldErrors hides them). InputField and TextAreaField are built
the same way.
For markup of your own, useFieldContext<T>() gives the typed field
state, and useIsInvalid(field) applies the kit's rules for when an error
shows. Use AppField too when you want direct access to a shipped field's
instance.