NOCTA UI

Form

A composable form component with field validation, labels, and actions for building accessible forms

Installation

Install the Form component component using the nocta-ui CLI:

npx nocta-ui add form

Import the component:

import {
  Form,
  FormField,
  FormLabel,
  FormControl,
  FormDescription,
  FormMessage,
  FormActions,
  FormInput,
  FormSubmit,
} from '@/components/ui/form';

Examples

The Form component follows a composable architecture where you build forms by combining smaller components together.

This will be displayed on your profile.

Form Architecture

The Form component is built with a composable architecture:

  • Form: The main form container (Ariakit Form)
  • FormField: Wraps individual form fields and provides context
  • FormLabel: Accessible labels with required field indicators (Ariakit Label)
  • FormControl: Wrapper that connects inputs to the field context
  • FormDescription: Helper text for additional guidance
  • FormMessage: Error, success, and warning messages (uses Ariakit FormError when no explicit message provided)
  • FormActions: Container for form action buttons
  • FormInput: Input bound to the current field name (Ariakit FormInput)
  • FormSubmit: Submit button integrated with Ariakit (Ariakit FormSubmit)

Error Handling

Handle validation in two ways:

  • Pass an error prop to FormField and place <FormMessage /> to display it.
  • Or use an Ariakit form store with validate/setError and place <FormMessage type="error" /> to read errors from the store.
Must be at least 8 characters long.

Complex Forms

Build complex forms with multiple field types, layouts, and validation.

We'll never share your email with anyone else.
Brief description for your profile. Maximum 500 characters.
Get notified about new features and updates.

Form Actions

The FormActions component supports different alignments for form buttons.

Message Types

Form messages support different types for various validation states.

Email is available!

Password strength is weak

Api Reference

Form

PropTypeDefaultDescription
childrenReact.ReactNodeForm content
classNamestring''Additional CSS classes
onSubmit(event: React.FormEvent) => voidForm submit handler
storeFormStoreuseFormStore({})Optional Ariakit form store

FormField

PropTypeDefaultDescription
childrenReact.ReactNodeField content
namestringField name identifier
errorstringError message to display
descriptionstringDescription text
classNamestring''Additional CSS classes

FormLabel

PropTypeDefaultDescription
childrenReact.ReactNodeLabel content
classNamestring''Additional CSS classes
requiredbooleanfalseShow required indicator

FormMessage

PropTypeDefaultDescription
childrenReact.ReactNodeMessage content
classNamestring''Additional CSS classes
type'error' | 'success' | 'warning''error'Message type

FormActions

PropTypeDefaultDescription
childrenReact.ReactNodeAction buttons
classNamestring''Additional CSS classes
align'left' | 'center' | 'right''right'Button alignment

FormInput

PropTypeDefaultDescription
classNamestring''Additional CSS classes
...inputPropsInputHTMLAttributes<HTMLInputElement>Native input props forwarded to Ariakit FormInput

FormSubmit

PropTypeDefaultDescription
childrenReact.ReactNodeButton content
classNamestring''Additional CSS classes
...buttonPropsButtonHTMLAttributes<HTMLButtonElement>Native button props forwarded to Ariakit FormSubmit

The Form components also accept all standard HTML attributes for their respective elements.