Beta

Search Documentation

Search through documentation pages

Components

Field

A set of components for building structured form layouts with labels, descriptions, and validation.

Preview

'use client';

import {
  Field,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSet,
} from '@/registry/san-francisco/ui/field';
import { Input } from '@/registry/san-francisco/ui/input';

export default function FieldDemo() {
  return (
    <Field className="max-w-xs">
      <FieldLabel>Email</FieldLabel>
      <Input placeholder="you@example.com" />
      <FieldDescription>We&apos;ll never share your email.</FieldDescription>
    </Field>
  );
}

Installation

bun
bunx shadcn@latest add @sft-ui/field

Orientation

Fields support vertical, horizontal, and responsive orientations.

'use client';

import {
  Field,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSet,
} from '@/registry/san-francisco/ui/field';
import { Input } from '@/registry/san-francisco/ui/input';

export default function FieldDemoOrientation() {
  return (
    <FieldGroup className="max-w-xs">
      <Field orientation="vertical">
        <FieldLabel>Vertical</FieldLabel>
        <Input placeholder="Vertical field" />
      </Field>
      <Field orientation="horizontal">
        <FieldLabel>Horizontal</FieldLabel>
        <Input placeholder="Horizontal field" />
      </Field>
    </FieldGroup>
  );
}

With Validation Error

'use client';

import {
  Field,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSet,
} from '@/registry/san-francisco/ui/field';
import { Input } from '@/registry/san-francisco/ui/input';

export default function FieldDemoValidation() {
  return (
    <Field className="max-w-xs">
      <FieldLabel>Username</FieldLabel>
      <Input aria-invalid />
      <FieldError errors={[{ message: 'Username is required' }]} />
    </Field>
  );
}

Field Groups

Use FieldGroup and FieldSet to organize multiple fields, and FieldSeparator to divide sections.

'use client';

import {
  Field,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSet,
} from '@/registry/san-francisco/ui/field';
import { Input } from '@/registry/san-francisco/ui/input';

export default function FieldDemoGroups() {
  return (
    <FieldSet className="w-full max-w-xs">
      <FieldLegend>Account Details</FieldLegend>
      <FieldGroup>
        <Field>
          <FieldLabel>First Name</FieldLabel>
          <Input />
        </Field>
        <Field>
          <FieldLabel>Last Name</FieldLabel>
          <Input />
        </Field>
      </FieldGroup>
    </FieldSet>
  );
}

API Reference

See the Base UI Field documentation for the API reference.