Installation
npx sdaia-ui@latest add error-summary
Usage
import { ErrorSummary } from '@/components/ui/ErrorSummary';<ErrorSummary
autoFocus
title="There is a problem"
intro="Fix the following to continue:"
errors={[
{ id: "full-name", message: "Enter your full name" },
{ id: "email", message: "Enter a valid email address" },
]}
/>RTL
The list, bullets and links mirror for Arabic.
Loading demo: error-summary-rtl
Examples
Two errors
Two required fields were left empty. Each link focuses its field.
Loading demo: error-summary-default
Three errors
Three fields need attention, including a select.
Loading demo: error-summary-three-items
Four errors
The longest version. Consider grouping fields when the list gets long.
Loading demo: error-summary-four-items
Without intro
The intro line is optional.
Loading demo: error-summary-without-intro
After a failed submit
Submit the empty form: the summary appears and takes focus. Fix the fields and submit again.
Loading demo: error-summary-on-submit
When to use
- Long forms with several fields to validate
- After a failed submit
- Server-side errors that cannot sit next to a field
- Forms where an error may be out of view
When not to use
- Single-field forms — use the inline error
- Messages that are not about validation
- Success or info messages — use an Alert
- Replacing the inline error under each field
Props
Prop | Type | Default | Required |
|---|---|---|---|
title | ReactNode | — | optional |
intro | ReactNode | — | optional |
errors | { id?: string; href?: string; message: ReactNode }[] | — | optional |
autoFocus | boolean | false | optional |
headingLevel | 2 | 3 | 4 | 5 | 6 | 2 | optional |
onErrorClick | (error, event) => void | — | optional |
dir | "ltr" | "rtl" | inherited | optional |
Accessibility
- The summary is role="alert", named by its title (aria-labelledby), and focusable with tabIndex=-1.
- Move focus to it after a failed submit: render it with autoFocus, or call ref.current.focus() when it stays mounted between submits.
- Each item is a link to #<field id>. Activating it focuses the field (or the first focusable element inside the target) and scrolls its label into view, without changing the URL.
- Errors are shown by an icon and text, not by colour alone. Keep the inline error on each field and set aria-invalid there.
Responsive behavior
- The summary fills its container and wraps long messages; nothing has a fixed width.
- Spacing and type use the responsive tokens.