Forms
Form
Validates its fields with the browser's rules and shows errors in the system's own treatment.
- Experimental
- Keyboard tested
- Screen reader not tested yet
Playground
<Form label="Playground form" successMessage="Thanks, the request was sent.">
<Input label="Email" name="playground-form-email" type="email" required />
<div><Button type="submit">Send request</Button></div>
</Form>Usage
When to use
Use Form around every set of fields that is submitted together. It turns the browser's validation into the system's own error treatment, so screens never write validation code.
When not to use
- For a single search field that filters as you type: use the field on its own.
- For dialogs with one to three fields: use Dialog in form mode, which validates the same way.
How it works
Rules are attributes on the controls: required, type="email", minLength, pattern. On submit, Form checks them all, marks every invalid field, announces a summary and moves focus to the first error. When everything is valid it calls action with the form data, or shows successMessage as a positive message for prototypes without a backend.
Content guidelines
Mark optional fields with optional; don't mark required ones. The summary (invalidMessage) says that something needs attention, the field errors say what. Keep the success message to what happened and what comes next.
Do and don’t
- Express rules as attributes (required, type="email", minLength); the Form turns them into messages.
- Mark optional fields with optional, not the required ones.
- Don't validate by hand in the screen; the controls already show their errors.
Anatomy
- summaryAfter an invalid submit; announced with role=alert.
- input-fieldInput, Select, Textarea, Checkbox, RadioGroup with required, type, pattern.
- actionsThe submit Button.
Examples
Validated on submit
Props
| Name | Type | Default | Description |
|---|---|---|---|
| label (required) | string | – | Accessible name of the form. |
| action | (formData: FormData) => void | Promise<void> | – | Server action or function, called only when every field is valid. |
| invalidMessage | string | – | Summary above the fields after a submit with errors. |
| successMessage | string | – | Shown after a valid submit without an action (prototypes). |
| children (required) | ReactNode | – | Fields and the submit Button (type="submit"). |
Tokens used
| Token | Tier | Value | Utility |
|---|---|---|---|
| input.radius | component | 8px | |
| accent.default | semantic | #C6492E | |
| layout.narrow | semantic | 720px | |
| spacing.3 | semantic | 12px | |
| spacing.4 | semantic | 16px | |
| spacing.6 | semantic | 24px | |
| text.primary | semantic | #0A0A0B | |
| type.small.size | semantic | 14px | |
| weight.medium | semantic | 500 |
Accessibility
| Check | How | Status |
|---|---|---|
| axe-core rules | Automated on every npm run check, at desktop and mobile width | Runs on every build |
| Keyboard | Automated Playwright test (scripts/keyboard.mjs) | Tested |
| Screen reader | Manual | Not tested yet |
Keyboard
| Key | Action |
|---|---|
| Enter | Submits from a single-line field. |
Semantics and focus
- On an invalid submit, focus moves to the first invalid field.
- The summary is announced; each field links its own error with aria-describedby.