Feedback
ErrorSummary
Free16.2 KB gzippedThe list of a form's errors, shown above it after a failed submit: a danger Alert whose items link to their fields (activating one moves focus to the field). It's focusable (tabIndex={-1}): give useFormValidation's summaryRef as ref and a failed submit moves focus here, so screen readers announce the heading and the list. The title is a real heading (h2 by default; set headingLevel to fit the page outline).
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter · Full report
Import
import { ErrorSummary } from "@vjdesigns/vjdesigns-ui";
Importing only ErrorSummary adds about 16.2 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Each error links to its field: activating a link moves focus there. Give each Field the id the item points to (from useId, so two copies of the form never share ids). headingLevel fits the title into the page outline (here, under an h3).
Error: There are 2 problems
Enter an email address, like name@example.com.
Use at least 8 characters.
import { useId } from "react";
import { ErrorSummary, Field, Input, Stack } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const id = useId();
const errors = [
{ name: "email", id: `${id}-email`, message: "Enter an email address, like name@example.com." },
{ name: "password", id: `${id}-password`, message: "Use at least 8 characters." },
];
return (
<Stack gap={4} style={{ width: "100%", maxWidth: "28rem" }}>
<ErrorSummary errors={errors} headingLevel={4} />
<Field id={errors[0].id} label="Email" error={errors[0].message}>
<Input name="email" type="email" autoComplete="email" defaultValue="dan@" />
</Field>
<Field id={errors[1].id} label="Password" error={errors[1].message}>
<Input name="password" type="password" autoComplete="new-password" defaultValue="short" />
</Field>
</Stack>
);
}
With validation
With useFormValidation: pass errorList as errors and summaryRef as ref. Submit the empty form: focus moves to the summary, so screen readers announce its heading and list. Errors come from the browser's own checks (required, type="email", minLength) plus rules, in the current language, and clear as each field is fixed.
import { useState } from "react";
import {
Button,
ErrorSummary,
Field,
Input,
Stack,
Text,
rules,
useFormValidation,
} from "@vjdesigns/vjdesigns-ui";
export function WithValidation() {
const [sent, setSent] = useState(false);
const form = useFormValidation({
rules: { confirm: rules.matches("password") },
onValid: () => setSent(true),
});
return (
<form {...form.formProps} style={{ width: "100%", maxWidth: "28rem" }}>
<Stack gap={4}>
<ErrorSummary ref={form.summaryRef} errors={form.errorList} headingLevel={4} />
<Field label="Email" required error={form.errors.email}>
<Input name="email" type="email" autoComplete="email" />
</Field>
<Field label="Password" required hint="At least 8 characters." error={form.errors.password}>
<Input name="password" type="password" minLength={8} autoComplete="new-password" />
</Field>
<Field label="Confirm password" required error={form.errors.confirm}>
<Input name="confirm" type="password" autoComplete="new-password" />
</Field>
<Button type="submit">Create account</Button>
<Text role="status">{sent ? "Account created." : ""}</Text>
</Stack>
</form>
);
}
Server errors
Errors from the server: return them from onValid and they show on their fields and in the summary, and stay until the field is edited. Try any email ending in @example.com.
import {
Button,
ErrorSummary,
Field,
Input,
Stack,
useFormValidation,
} from "@vjdesigns/vjdesigns-ui";
export function ServerErrors() {
const form = useFormValidation({
onValid: async (values) => {
await new Promise((resolve) => setTimeout(resolve, 600));
if (String(values.email).endsWith("@example.com")) {
return { email: "That email is already registered. Sign in instead, or use another one." };
}
},
});
return (
<form {...form.formProps} style={{ width: "100%", maxWidth: "28rem" }}>
<Stack gap={4}>
<ErrorSummary ref={form.summaryRef} errors={form.errorList} headingLevel={4} />
<Field label="Email" required error={form.errors.email}>
<Input name="email" type="email" autoComplete="email" defaultValue="dan@example.com" />
</Field>
<Button type="submit" loading={form.isSubmitting}>
Join the waitlist
</Button>
</Stack>
</form>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
Enter an email address, like name@example.com.
Use at least 8 characters.
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
Usage notes
<ErrorSummary ref={form.summaryRef} errors={form.errorList} />
API reference
ErrorSummary
New in 1.4.10| Prop | Type | Default |
|---|---|---|
errorsRequiredThe errors, in page order: | readonly ErrorSummaryItem[] | — |
titleHeading. | ReactNode | "There is 1 problem" / "There are 3 problems", in the current language |
variantSurface style. | "soft""solid""outline" | "soft" |
sizePadding, type size, and icon size. | "sm""md""lg" | "md" |
radiusCorner rounding. | "none""xs""sm""md""lg""xl""2xl""pill" | "lg" |
asRoot element. | "div""section""aside" | "div" |
iconIcon in the tinted circle. Defaults to a distinct shape per tone (info, success check, warning triangle, error). Pass | ReactNode | false | — |
headingLevelRenders the title as a real heading ( | 123456 | — |
actionsAction row under the description, usually | ReactNode | — |
toneLabelVisually hidden prefix read before the title (or the description, when there is no title), e.g. "Error: ". | string | boolean | on for `danger` ("Error: ") and `warning` ("Warning: "), off otherwise |
dismissLabelAccessible name of the dismiss button. Localize it here. | string | "Dismiss" |
returnFocusRefElement to focus after dismissal, so keyboard focus isn't lost when the alert (and its dismiss button) disappears. Pick the control that triggered the alert, or the next logical element. If unset and focus was inside the alert, handle focus yourself in | RefObject<HTMLElement | null> | — |
openWhether the alert is shown (controlled). Set with | boolean | — |
defaultOpenWhether the alert is shown initially (uncontrolled). | boolean | true |
onOpenChangeCalled with | (open: boolean) => void | — |
liveLive-region behavior. See | "off""polite""assertive" | "off" |
Also accepts standard HTML attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
ErrorSummary targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves through the error links, in the order of the fields. |
| Enter | On an error link: moves focus to that field (not just scrolling to it). |
With useFormValidation's summaryRef, a failed submit moves focus to the summary (tabindex="-1"), so screen readers read its heading and list. Without it, focus goes to the first invalid field.
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Summary | none (generic) | tabindex="-1", so it can take focus; not a live region (focus moving to it announces it) |
| Title | heading | Level from headingLevel (default 2); "There are 2 problems", in the current language |
| Errors | list | One item per error |
| Error | link | href="#id" of the field's control; the text is the field's error message |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |