FormField

A compound form field component with Label, Error, and Hint subcomponents for consistent form layouts.

Preview

This will be your public display name.

Installation

npx shadcn@latest add @shadszn/form-field

Usage

import { FormField } from "@/components/ui/form-field"
import { Input } from "@/components/ui/input"

export default function Example() {
  return (
    <FormField>
      <FormField.Label htmlFor="email" required>
        Email Address
      </FormField.Label>
      <Input id="email" type="email" placeholder="you@example.com" />
      <FormField.Hint>We will never share your email.</FormField.Hint>
    </FormField>
  )
}

With Error

<FormField>
  <FormField.Label htmlFor="password" required>
    Password
  </FormField.Label>
  <Input id="password" type="password" error />
  <FormField.Error message="Password must be at least 8 characters." />
</FormField>

Subcomponents

FormField

PropTypeDefaultDescription
children*ReactNode---Form field contents (label, input, error, hint).
classNamestring---Additional CSS classes.

FormField.Label

PropTypeDefaultDescription
requiredbooleanfalseShows a red asterisk after the label text.
htmlForstring---Associates the label with an input by id.

FormField.Error

PropTypeDefaultDescription
messagestring---Error message to display. Renders nothing when undefined.

FormField.Hint

PropTypeDefaultDescription
children*ReactNode---Hint text content.