Skip to content

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

Updated 2026-11-12

Playground

Change the props. The controls come from the documented props.
tsx
<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

Do
  • 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
  • Don't validate by hand in the screen; the controls already show their errors.

Anatomy

The parts of the component and what each one does, as in the playground above.
  1. summaryAfter an invalid submit; announced with role=alert.
  2. input-fieldInput, Select, Textarea, Checkbox, RadioGroup with required, type, pattern.
  3. actionsThe submit Button.

Examples

Type-checked, and the same code goes into the AI manifest. Import: import { Form } from "@/ds";

Validated on submit

Props

Checked against the component's TypeScript type on every build.
Form props
NameTypeDefaultDescription
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.
invalidMessagestring–Summary above the fields after a submit with errors.
successMessagestring–Shown after a valid submit without an action (prototypes).
children (required)ReactNode–Fields and the submit Button (type="submit").

Tokens used

Derived from the utility classes in the component's source. Copy a class with one click.
Tokens used by Form
TokenTierValueUtility
input.radiuscomponent8px
accent.defaultsemantic#C6492E
layout.narrowsemantic720px
spacing.3semantic12px
spacing.4semantic16px
spacing.6semantic24px
text.primarysemantic#0A0A0B
type.small.sizesemantic14px
weight.mediumsemantic500

Accessibility

What is checked automatically on every build, and what a person has tested. Nothing is marked as tested unless it was.
Testing status by check
CheckHowStatus
axe-core rulesAutomated on every npm run check, at desktop and mobile widthRuns on every build
KeyboardAutomated Playwright test (scripts/keyboard.mjs)Tested
Screen readerManualNot tested yet

Keyboard

Form keyboard interactions
KeyAction
EnterSubmits 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.