Error Summary

A GOV.UK-style error summary that takes focus on submit, links each error to its field and ticks errors off as they are fixed.

StopsUsers miss errors on long forms

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/error-summary.json

The files land in your project. They're yours to edit.

Usage

error-summary-usage.tsx
import { ErrorSummary, useFormErrors } from "@/components/ui/error-summary"

<ErrorSummary {...form.summaryProps} prefixTitle={false} />

What it catches

  • Errors missed on long forms, listed in one place on submit
  • Finding the field, by linking each error to it
  • Progress, by ticking off fixed errors live

Props

ErrorSummary props
PropTypeDefault
items* (required)

Errors from the last failed submit, in field order. Renders nothing when empty.

SummaryItem[]—
focusSignal* (required)

Increment on every failed submit; each change moves focus to the summary.

number—
title

Heading while errors remain.

string"There is a problem"
fixedTitle

Heading once every error is fixed.

string"All fixed. You can submit again."
prefixTitle

Prefix `document.title` with "Error: " while errors remain, as GOV.UK recommends.

booleantrue

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Takes focus on submit (tabIndex=-1) and is labelled by its title
  • Each link moves focus to its field
  • Fixed items say "Fixed:" in text; progress changes are aria-live="polite"
  • Motion respects prefers-reduced-motion

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Lists the errors you pass; validation is up to you
  • Linking to a field needs the field's id to match the error item

What it stops

Users miss errors on long forms

Also known as

form validation · error summary · gov.uk · react hook form · zod · a11y · inline errors · useFormErrors

Dependencies

Pairs well with