DocsForms

Forms

Forms are essential to web applications—they’re the primary way to collect user input. By providing a consistent structure for capturing and validating data, we ensure a reliable user experience across different applications.

Form Components

The UI Kit includes a set of form components designed to offer a consistent API and integrate smoothly with native HTML forms, React forms, and form libraries.

All form components are built on top of HvFormElement, which provides a shared API to handle events, manage status, and expose a value prop to support controlled components.

⚠️

Not all UI Kit form components support native form data serialization or validation.

For a complete list of available components, check out HvFormElement’s related components.

Building Forms

There are several ways to build forms in React, each with its own trade-offs. Below are the most common approaches when using the UI Kit.

Native Form

The simplest method is using an uncontrolled native form, taking advantage of built-in browser validation and accessing form values via FormData.

This approach is ideal for basic forms using native-compatible components (e.g., input), where custom validation is not needed.

React form

Whenever you need to manage internal form values or apply custom validation, using controlled components with React state is a good approach. In this setup, each form input is tied to a state variable, and changes are handled via the onChange event.

Form libraries

Working with forms in React can be challenging—handling validation, verbosity, and state management often adds complexity.

Libraries like React Hook Form and Formik help simplify form handling. Both address similar problems, and the UI Kit does not enforce the use of either.

Our Form Components are compatible with these libraries. However, we recommend using each library’s imperative set value functions when handling the onChange events of our components. While the APIs are not fully aligned, this approach provides the most consistent and predictable experience.

React Hook Form