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:Basic Usage
Component Parts
Form.Root
The root form element that provides context to all form components.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.name- Field name (required)control- Form control (optional, inferred from context)withWrapper- Wrap in div container (default:true)className- Custom classes for wrapper
data-disabled- Present when field is disableddata-invalid- Present when field has errors
Form.Label
Accessible label for form inputs.htmlFor.
Form.Input
Standard input element with built-in registration.- 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 groupwithEyeIcon- 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.errorField- Override which field’s errors to showtype-"regular"(default) or"root"for root-level errorsdisableErrorAnimation- Disable shake animationdisableScrollToErrorField- 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:Validation
The Form component works seamlessly with React Hook Form validation:- Inline Rules
- Zod Schema
- Custom Validator
Error Handling
Error messages are automatically displayed and animated: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
disabledandaria-disabledattributes - Error messages auto-scroll into view
- Password visibility toggles are keyboard accessible
The Form component automatically handles field registration, error display, and accessibility attributes.