Skip to content

Field

Form field layout: label, control, description and error, in vertical, horizontal and responsive orientations.

Label and description

With an error

Several errors

Horizontal

Responsive

Grouped

Billing contact
Invoice footer

Choice cards

Include in the export

Disabled

Installation

npx shadcn@latest add @khaeli/field

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • class-variance-authority ^0.7.1

Accessible name

  • FieldLabel is a @khaeli/label: its htmlFor is the id of the control.
  • FieldDescription and FieldError are not tied to the control for you. Give each an id and list it in the control's aria-describedby.
  • For an error, set data-invalid="true" on Field (it colours the label and the message) and aria-invalid on the control (it tells assistive technology). FieldError has role="alert", so a message that appears is announced.
  • FieldSet with a FieldLegend names a group of fields. Use it for a set of checkboxes and for a section of a form.
  • For a disabled field, set data-disabled="true" on Field and disabled on the control.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/field.json