Skip to content

Forms

Collects structured input with clear labels, inline validation and a form-level summary when the server says no.

A form turns what a person knows into something the system can act on. The pattern decides how fields are grouped, when errors appear, where focus goes when something is wrong and how the person knows the form was saved. Validation uses React Aria's form validation, so the browser, the keyboard and assistive technology all see the same state.

Anatomy

  • A Field per control: FieldLabel, the control, an optional hint and a message. FieldSet and FieldLegend group related fields, FieldSeparator draws the hairline between groups.
  • Text controls: Input and Textarea, wrapped in a React Aria TextField so required, pattern and custom rules are validated and reported.
  • Choices: Select for many options, Radio Group for a few exclusive ones, Checkbox for several or one confirmation, Switch for a setting that is on or off.
  • Alert for the form-level summary, Button and Spinner for the submit state, and Progress for steps.

Single-section form

One page, grouped sections, every common field type. Submit it empty to see inline errors and the focus move to the first invalid field. Submit the supplier name Cavenzo Metalli to see a server-style error summary.

Open in a new tab

Choose it when the person needs to see everything at once: creating a record, editing a profile, a short request. Up to about ten fields in three or four groups works well.

Multi-step form

A request split into four steps with a progress bar, Back and Next, a review step with a Change link for every answer, and a confirmation. Each step validates before Next moves on, and answers are kept when the person goes back.

Open in a new tab

Choose it when the form is long, when later questions depend on earlier ones, or when the person needs to gather information between steps. Do not split a form of six fields into steps.

Behaviour

  • Validation timing. Errors appear when the person submits, then update as they fix each field. Never show an error on a field the person has not reached.
  • Required and optional. Mark the exception: optional fields say Optional beside the label. Do not use asterisks.
  • After an invalid submit. Focus moves to the first invalid field, which is described by its message.
  • After a server error. The summary at the top takes focus and is announced. Each item is a button that moves focus to its field. The same messages show beside the fields.
  • Submitting. The button shows a spinner and a verb in the present tense, and ignores further presses. Other actions are disabled.
  • After success. The form is replaced by a confirmation whose heading takes focus, with a next step. A success Badge with a check icon and the word Saved sits above the heading, as in forms-01: the colour is never the only signal.
  • Responsive. Fields are one column from 320px upwards. The form is capped at a reading width and centred.
KeyAction
TabMoves focus to the next control.
ShiftTabMoves focus to the previous control.
EnterSubmits the form from a text field, or opens a select.
SpaceToggles a checkbox, a radio or a switch.
Arrow UpMoves between radios in a group, or between select options.

On a phone

Both blocks put pointer-coarse:touch-controls on the page, and on the list of the shared select field, which opens outside the page. Every field, choice row and action reaches 44px on a touch screen, and fields keep 16px text. See Sizing.

Accessibility

  • Every control has a visible label tied to it. A placeholder is never the label.
  • Messages are tied to their fields with aria-describedby, which React Aria sets for the hint and the error.
  • Invalid fields carry aria-invalid, and the border changes, so colour is not the only signal.
  • Groups of choices have a group label that is announced with each option.
  • Autocomplete tokens are set on name, email and phone fields.

Content

  • Say what happened and what to do: "Use IT followed by 11 digits. This number has 7."
  • Hints say what is expected before the person types. Messages say what to change after.
  • Buttons start with a verb: Save supplier, Send request.

IT followed by 11 digits.

Do

Say what is wrong and how to fix it.

Don’t

Don’t write messages that could belong to any field.

Install

Each block is a registry item named after its folder.

pnpm dlx shadcn@latest add @silkware/forms-01
pnpm dlx shadcn@latest add @silkware/forms-02