Skip to content

Field

A component that provides labelling and validation for form controls.

Installation

pnpm dlx shadcn@latest add @frontal-labs/field

Usage

import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
<Field>
  <FieldLabel>Name</FieldLabel>
  <Input type="text" placeholder="Enter your name" />
  <FieldDescription>Visible on your profile</FieldDescription>
  <FieldError>Please enter a valid name</FieldError>
</Field>

API Reference

Field

Root component. A styled div with role="group" that lays out a label, control, description, and error.

Accepts all div props, plus:

"responsive" stacks vertically and switches to a horizontal layout at the @md breakpoint of the enclosing FieldGroup.

FieldSet

A styled fieldset element for grouping related fields.

FieldLegend

A styled legend element for a FieldSet. Accepts a variant prop of "legend" (default) or "label" to control the text size.

FieldGroup

A styled div that stacks multiple fields or field sets. It also acts as the container query context used by the responsive orientation.

FieldContent

A styled div that groups a field's title and description, typically next to a control in a horizontal field.

FieldLabel

Label for the field. A styled wrapper around the Label component.

FieldTitle

A styled div for label-like text that is not an actual label element, for example inside a FieldContent.

FieldDescription

Description text for the field. Renders a p element with muted foreground color.

FieldSeparator

A styled div that renders a Separator between fields, optionally with centered content passed as children.

FieldError

Error message for the field. Renders a div with role="alert" and destructive text color, and renders nothing when there is no content.

Accepts all div props, plus:

Examples

Required Field

Disabled Field

With Error

Enter an invalid email address and press enter to see the error.

Input Group

Autocomplete Field

Combobox Field

Combobox Multiple Field

Textarea Field

Select Field

Checkbox Field

Checkbox Group Field

Radio Group Field

Switch Field

Slider Field

Number Field

Complete Form Example