Skip to content
HomeCobalt

Field

Names a control and ties its description and error to it.

Examples

An email field with a description, checked when you leave it.

Where we send the receipt.

A label on its ownA plain Label wraps a checkbox that needs no description, below a field named by its FieldLabel.
Other controlsA Select, a Checkbox and a Switch take their name and description from the Field, with no ids.

Booking times show in this zone.

Copies go to ana.lima@example.com.

Kept on this device only.

In a formTwo fields and one submit, so Enter submits the form.

Where we send the invitation.

Variants

Variant

RowA full-width row the height of a menu row, with a hover fill and regular weight, so the whole row is the target, for a list of checkboxes or switches in a settings list, a sheet or a popover.

Side

Two fields in a rowTwo names in one row get a Field each, so each control has its own label.

States

Set when the workspace was created.

DisabledDisabling the Field disables its control and fades its label.
Enter an address with a domain, such as ada@example.com.
InvalidAfter a check, the error under the control and the red wash on it.

Usage

Use it when

  • A control has a visible name, and a description or an error now or later: a Field.
  • A form has more than one field, so each one's wiring must not drift from the others: a Field each.
  • A checkbox or a switch with only its words, such as a filter or a setting row: a plain Label around the control.

Use something else when

  • The words introduce several controls, such as a group of switches. Use a fieldset with a legend instead, with a Label per control (rule/label-only-for-a-control).
  • The words are a caption, a key in a key-value row or a heading. Use Section instead, or plain text.
  • The fields need to submit together. Use a form around the Fields with one submit Button instead of a Field around the form.

Rules

General

Content

Avoid

Limits

Install

npx shadcn@latest add https://kaanarici.com/r/cobalt/field.json https://kaanarici.com/r/cobalt/label.json
import { Field, FieldLabel, FieldControl, FieldDescription, FieldError } from "@/components/cobalt/ui/field"
import { Label } from "@/components/cobalt/ui/label"