Form

Constructing forms in React with React Hook Form and Zod.

@react-hook-form @lucide/react

Forms are an essential part of nearly every web application — yet they can often be the most challenging to get right.

A great HTML form should be:

  • Semantically structured and easy to understand.

  • User-friendly, with smooth keyboard navigation.

  • Accessible, leveraging ARIA attributes and clear labels.

  • Validated both on the client and server for reliability.

  • Visually consistent with the rest of your design system.

In this guide, we’ll explore how to build robust, accessible forms using React Hook Form and Zod, and how to compose them with a <FormField> component built on Radix UI primitives.

Features

The <Form /> component acts as a convenient wrapper around react-hook-form, designed to make building forms simpler and more consistent.

It offers:
  • Composable building blocks for creating flexible form layouts.

  • A <FormField /> component for managing controlled inputs effortlessly.

  • Schema-based validation powered by zod (or any validation library you prefer).

  • Accessibility handled out of the box, including labels, ARIA attributes, and error messaging.

  • Automatic unique ID generation using React.useId().

  • Correct ARIA attributes applied based on form and field state.

  • Seamless compatibility with all Radix UI components.

  • You can easily swap out zod for any other schema validation library that fits your needs.

  • Full control over structure and styling — the components don’t enforce layout or design decisions.

Installation


1

Install the following dependencies:

npx shadcn@latest add https://sbthemes-storev2.vercel.app/r/form.json

Examples


Contact Form

Account Settings Form

You can also create forms that seamlessly integrate components like DropdownMenu, RadioGroup, and Input fields — allowing for flexible and interactive form experiences.


API Reference

FormField

PropTypeDefault
namestring-
controlControl-
render({ field, fieldState }) => ReactNode-