@biem/ui

Field

A form field that gives a control its label, its description and its error message.

A field combines a control with the text that explains it. Its label names the control, its description says what the value is for, and its error names what users need to correct. Several fields stack in a group, and a field set gathers related fields under one legend.

The item number is printed on the shelf label.

Usage

field-default.tsx
import {
	Field,
	FieldDescription,
	FieldLabel,
} from "@biem/ui/components/ui/field";
import { Input } from "@biem/ui/components/ui/input";

export function FieldDefault() {
	return (
		<div className="w-full max-w-sm">
			<Field>
				<FieldLabel htmlFor="item-number">Item number</FieldLabel>
				<Input id="item-number"/>
				<FieldDescription>The item number is printed on the shelf label.</FieldDescription>
			</Field>
		</div>
	);
}

Examples

Vertical

Values that users type, such as an address or a note, need the full width of the form, and users read the label before they begin. A field arranges its label, control and description in this order by default, and orientation set to "vertical" states it explicitly.

The warehouse counts the quantity in cases.

Horizontal

Switches and checkboxes only turn a setting on or off and need little room. With orientation set to "horizontal", label and control share one row, so a list of settings stays short and users scan it quickly.

Horizontal with Description

Before users turn on a setting, they sometimes need to know what it will cause. Inside FieldContent, the label and the description form one column beside the control, so the explanation stays next to the decision it belongs to.

The store manager receives a message when the transfer leaves the warehouse.

Responsive

The same form can appear in a narrow side panel and on a wide page. Set to "responsive", orientation stacks the parts of a field while space is short and places them in one row once the surrounding FieldGroup is at least 28rem wide. The field responds to the width of its group rather than the screen, so it adapts wherever users open the form.

The name appears on delivery notes and shelf labels.

Group

Most tasks ask users for more than one value. Within a FieldGroup, fields stack with even spacing, so users work through them in order and see where one field ends and the next begins.

The warehouse reads the note before it packs the transfer.

Legend

Longer forms divide into sections, and users find their way by the name of each one. A FieldSet gathers the related fields under a FieldLegend, and with variant set to "legend", which is the default, that name ranks above the labels of the fields and heads the section.

Store contact

The warehouse calls this contact when a delivery is late.

Label Legend

Sometimes a set of options answers a single question and forms no section of its own. Here, variant set to "label" gives the legend the rank of a field label, so the question and its options read as one field.

Count frequency

The store counts this item on the chosen schedule.

With Separator

Partway through a form, the topic of the fields can change. Placed between them, FieldSeparator marks the boundary, so users notice where one topic ends and the next begins without a heading for each part.

The store orders again when the stock falls to this number of cases.

Separator with Text

Some forms accept either of two inputs, and users fill in whichever they have at hand. Content passed as children names how the fields on either side of the separator relate, so users know at once that one of them is enough.

or

Choice Card

Options with real consequences need a sentence of explanation before users can weigh one against the other. Wrapped around a Field, FieldLabel makes each option a card that responds as a whole, so a click anywhere on it selects the option. FieldTitle names the option there, where a label does not fit.

Disabled

A value can be fixed for the moment, for example because another setting determines it. With disabled on the control and data-disabled on the field, the control accepts no input and its label is marked as unavailable along with it, so users still read the value without trying to change it.

The region of the store sets the warehouse.

Invalid

When a value breaks a rule, users need to learn what to correct right where they entered it. Marked with data-invalid, the field takes on the error state, and aria-invalid on the control exposes that state to assistive technology. FieldError then names what to correct, and assistive technology announces it as an alert.

Error List

Validation often finds several problems in one value at the same time. Given an array through errors, FieldError lists every message and shows a repeated message only once, so users fix the value in one pass instead of one problem after another.

API Reference

Field

Proporientation
Type"vertical" | "horizontal" | "responsive"
Default"vertical"
DescriptionControls the layout of the field. Vertical stacks the label, the control and the description. Horizontal places them in a row. Responsive stacks them and changes to a row once the FieldGroup around the field is at least 28rem wide.

FieldContent

FieldContent stacks the label and the description in one column beside the control. It renders a div and has no props of its own.

FieldLabel

ProphtmlFor
Typestring
Default–
DescriptionSets the ID of the control that the label names. A click on the label then focuses or toggles that control.

FieldTitle

FieldTitle names a field where a label does not fit, such as inside a choice card. It renders a div and has no props of its own.

FieldDescription

FieldDescription says what a field or a field set is for. It renders a p and has no props of its own.

FieldError

Properrors
TypeArray<{ message?: string } | undefined>
Default–
DescriptionSets the messages of the error. One message renders as text, several messages render as a list, and a message that repeats appears once. Without a message and without children, FieldError renders nothing.
Propchildren
TypeReactNode
Default–
DescriptionSets the content of the error directly. When it is set, FieldError ignores errors.

FieldGroup

FieldGroup stacks fields in a column with even spacing and is the container whose width a responsive field follows. It renders a div and has no props of its own.

FieldSeparator

Propchildren
TypeReactNode
Default–
DescriptionSets the content in the middle of the line, such as the word "or". Without it, the separator draws only the line.

FieldSet

FieldSet gathers related fields under one legend. It renders a fieldset and has no props of its own.

FieldLegend

Propvariant
Type"legend" | "label"
Default"legend"
DescriptionControls the text size of the legend. With "legend", the text is one size larger than a field label and heads a section of a form. With "label", the text has the size of a field label, which fits a set that holds one group of options.