Skip to main content

Overview

The Form component provides a complete form solution built on top of React Hook Form. It includes accessible form controls, automatic error handling, field state management, and seamless integration with validation libraries like Zod.

Use Cases

  • Login and registration forms
  • Multi-step forms and wizards
  • Settings and configuration panels
  • Survey and feedback forms
  • Data entry and CRUD operations
  • Complex forms with dynamic fields

Installation

The Form component is included with the UI package:
For validation, install Zod and the resolver:

Basic Usage

Component Parts

Form.Root

The root form element that provides context to all form components.
Props:
  • form - React Hook Form instance (required)
  • withEyeIcon - Show password visibility toggle (default: true)
  • All standard form HTML attributes

Form.Field

Field wrapper that provides context for labels, inputs, and error messages.
Props:
  • name - Field name (required)
  • control - Form control (optional, inferred from context)
  • withWrapper - Wrap in div container (default: true)
  • className - Custom classes for wrapper
Data Attributes:
  • data-disabled - Present when field is disabled
  • data-invalid - Present when field has errors

Form.Label

Accessible label for form inputs.
Automatically associates with the field’s input via htmlFor.

Form.Input

Standard input element with built-in registration.
Props:
  • All standard input HTML attributes
  • type - Input type (text, email, password, etc.)
  • rules - Validation rules (React Hook Form format)
  • classNames - Custom classes for input, error, eye icon, input group
  • withEyeIcon - Override root password toggle setting

Form.TextArea

Multi-line text input.

Form.Select

Dropdown select element.

Form.InputGroup

Groups input with left/right decorations.

Form.ErrorMessage

Displays validation errors with animations.
Props:
  • errorField - Override which field’s errors to show
  • type - "regular" (default) or "root" for root-level errors
  • disableErrorAnimation - Disable shake animation
  • disableScrollToErrorField - Disable auto-scroll to errors

Form.Description

Helper text for form fields.

Form.Submit

Submit button with proper type attribute.

Examples

Registration Form with Validation

Form with Input Groups

Controlled Field with Custom Component

Form with Watch

React to field value changes:

Form State Subscribe

Subscribe to form state changes:

Password Visibility Toggle

Password inputs automatically include an eye icon to toggle visibility:
Disable for specific fields:
Customize eye icon styling:

Validation

The Form component works seamlessly with React Hook Form validation:

Error Handling

Error messages are automatically displayed and animated:
Customize error display:
Root-level errors:

Styling

All form parts include data attributes:

Accessibility

  • Labels are properly associated with inputs via htmlFor
  • Error messages are linked via aria-describedby
  • Invalid fields have aria-invalid="true"
  • Disabled fields have proper disabled and aria-disabled attributes
  • Error messages auto-scroll into view
  • Password visibility toggles are keyboard accessible
The Form component automatically handles field registration, error display, and accessibility attributes.
Use Form.Watch and Form.StateSubscribe to create dynamic forms that respond to user input in real-time.

API Reference

For detailed prop types and advanced usage, see the Form API Reference.