Components

Form

react-hook-form bindings for the field primitives.

Used in the deployment URL.

Installation

npx shadcn@latest add @blank/form

Usage

import {
  Form,
  FormControl,
  FormDescription,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
} from "@/components/ui/form"
<Form {...form}>
  <form onSubmit={form.handleSubmit(onSubmit)}>
    <FormField
      control={form.control}
      name="username"
      render={({ field }) => (
        <FormItem>
          <FormLabel>Username</FormLabel>
          <FormControl>
            <Input {...field} />
          </FormControl>
          <FormMessage />
        </FormItem>
      )}
    />
  </form>
</Form>

Form wires React Hook Form into the ids and aria-* attributes a field needs. For new forms, Field with your form library's own hooks does the same with less indirection; Form stays for code that already uses it.

Examples

Switches

Any control works inside FormControl as long as you map its value and change handler onto the field.

Build every pull request.
Let reviewers comment on previews.