Patterns · Forms
Error Summary
Since v1.7.0
Lists a form’s errors after a failed submit, with a link to each field. useFormErrors wires the fields to their messages.
import { ErrorSummary } from '@nexub/patterns';Usage
Use it for
Forms validated on submit, especially long ones where some errors are off screen.
Alongside inline messages, never instead of them.
Use something else for
Live validation while typing: pass a new array per submit, not per keystroke, or the summary steals focus.
A single field: the inline message is enough.
Examples
Validate on submit
Submit empty to see the summary. A new map per submit moves focus to the summary; links jump to each field.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| errorsrequired | { id: string; message: string }[] | — | One entry per invalid field; id is the field’s DOM id. Renders nothing when empty. |
| title | ReactNode | 'There is a problem' | Heading; it also labels the summary. |
| onFocusField | (id: string) => void | — | Called after a link moves focus to its field. |
| useFormErrors(map)required | Record<string, string | null | undefined | false> | — | Takes { fieldId: message }. Falsy messages are skipped. |
| → errors | ErrorSummaryItem[] | — | The list for ErrorSummary. Stable for the same map object. |
| → fieldProps(id) | function | — | Spread on the input: id, plus aria-invalid and aria-describedby="${id}-error" when it has an error. |
| → errorProps(id) | function | — | Spread on the inline message: id="${id}-error", the same id FormField.Error uses. |
On iOS & Android
Web only
Error Summary has no @nexub/react-native twin. On phones, follow the platform pattern instead, or compose it from the native components listed on the React Native page.