Skip to content
nexubDesign System
v11.9.0

Components · Form & Input

Form

BetaAdded v6.1.0

Validates on submit with the browser’s own checks plus yours, shows each message on its FormField and focuses the first invalid field.

import { Form } from '@nexub/react';
View as Markdown

Examples

Native validation plus a custom rule

Props

Props
PropTypeDefaultDescription
onSubmit((data: FormData, event: React.FormEvent<HTMLFormElement>) => void | Promise<unknown>)—Runs only when every field is valid. Return a promise to mark the form busy (aria-busy, useForm().submitting) until it settles.
validate((data: FormData) => Record<string, string | false> | void)—Checks the browser can’t do (cross-field rules, a zod schema, a server answer). Keys are field names; empty values mean valid.
onInvalidSubmit((errors: FormErrorItem[]) => void)—Errors in field order after a failed submit, ready for ErrorSummary.
useForm(){ errors, submitting } | null—Reads the closest Form’s state, for a submit button or a custom field.

Accessibility

Keyboard

  • Enter

    Submits from any text field; the first invalid field takes focus.

Notes

  • Messages come from the browser’s constraint validation (`required`, `type="email"`, `pattern`, `min`…), so they are already in the reader’s language.

  • FormField.Root with the same `name` picks the message up: the control gets `aria-invalid` and `aria-describedby`, and FormField.Error shows the text.

  • A field’s error clears as soon as it is edited; the rest stay until the next submit.

  • For long forms, render ErrorSummary (@nexub/patterns) from `onInvalidSubmit`.

On iOS & Android