Error summary

The error summary lists the problems in a form after the user submits it, at the top of the page, with one link per problem. Activating a link moves focus to the field that has the problem, including DDS fields whose control sits inside shadow DOM.

It follows the GOV.UK error summary pattern. The app decides what is wrong: it builds the list from its own validation and passes it in. The error summary does not read the form.

When to Use

✅ Use the error summary when:

  • A form submit or a "Continue" step fails validation and the user has to fix one or more fields.
  • The page has more than a couple of fields, so the user may not see every inline error.

❌ Don't use the error summary when:

  • You validate a single field while the user types or leaves it; show the field's inline feedback instead.
  • The problem is not tied to a field, such as a failed request; use a callout or a banner.
  • Nothing is wrong. With an empty list the error summary renders nothing, so you can leave it in the page.
Examples Setting the items

The problems are data, set through the items property. items is a property only, not an attribute, so set it from JavaScript or through a framework property binding.

Each item is { target, message }:

FieldTypeDescription
targetstringThe id of the field to focus. The link points at #target.
messagestringThe link text. It must name its field (see below).

JS

<dap-ds-error-summary id="summary"></dap-ds-error-summary>

<dap-ds-input id="taxNumber" name="taxNumber" label="Tax number" required></dap-ds-input>
<dap-ds-datepicker id="birthDate" name="birthDate" label="Date of birth" required></dap-ds-datepicker>

<script>
  document.querySelector('#summary').items = [
    { target: 'taxNumber', message: 'Enter your tax number' },
    { target: 'birthDate', message: 'Enter your date of birth' },
  ]
</script>

React

import { DapDSErrorSummary } from 'dap-design-system/react'

<DapDSErrorSummary
  items={[
    { target: 'taxNumber', message: 'Enter your tax number' },
    { target: 'birthDate', message: 'Enter your date of birth' },
  ]}
/>
Writing the messages

Each message must name its field. The link text is the message, and a screen reader user who moves through the summary hears only the links. "Enter your date of birth" tells them what is wrong and where; "This field is required" does not.

  • Use the same text as the field's inline feedback, so the summary and the field say the same thing.
  • List the items in the order the fields appear on the page.
Showing the summary after a failed submit

On submit, build items from the invalid fields and call focus() on the error summary. Focus moves to the summary, and assistive technology announces it with its heading. You can set items and call focus() in the same task: the error summary waits for its render before it takes focus.

When the user fixes the fields, rebuild items. Once the list is empty, the summary disappears.

<form id="form" novalidate>
  <dap-ds-error-summary id="summary"></dap-ds-error-summary>
  <dap-ds-input id="taxNumber" name="taxNumber" label="Tax number" required></dap-ds-input>
  <dap-ds-select id="county" name="county" label="County" required>
    <dap-ds-option-item value="budapest">Budapest</dap-ds-option-item>
    <dap-ds-option-item value="pest">Pest</dap-ds-option-item>
  </dap-ds-select>
  <dap-ds-button type="submit">Submit</dap-ds-button>
</form>

<script>
  const MESSAGES = {
    taxNumber: 'Enter your tax number',
    county: 'Select your county',
  }
  const form = document.querySelector('#form')
  const summary = document.querySelector('#summary')

  form.addEventListener('submit', event => {
    event.preventDefault()
    summary.items = Object.entries(MESSAGES)
      .filter(([id]) => !document.getElementById(id).validity.valid)
      .map(([target, message]) => ({ target, message }))
    if (summary.items.length) {
      summary.focus()
    }
  })
</script>
Moving focus yourself

When a link is activated, the error summary fires a cancelable dds-item-select event with the item's target and index. If nothing cancels it, the error summary finds the element with that id in its own root node (the document, or the shadow root it sits in) and calls its focus(). DDS fields pass that focus on to their inner control, so the user lands in the text box, not on the field's outer element.

If your form library keeps track of focus, such as react-hook-form, call preventDefault() and move focus yourself:

import { DapDSErrorSummary } from 'dap-design-system/react'

<DapDSErrorSummary
  ref={summaryRef}
  items={errors}
  onDdsItemSelect={event => {
    event.preventDefault()
    // Here each field's id is also its react-hook-form name
    setFocus(event.detail.target)
  }}
/>

When no element has the target id, the event still fires and focus stays on the link.

Heading

The default heading is "There is a problem", translated into the active language. Set heading to use your own text, and headingLevel (1 to 6, default 2) to fit the heading into the page outline.

<dap-ds-error-summary heading="Check the highlighted fields" headingLevel="3"></dap-ds-error-summary>
Custom Styling

Change the border, spacing and text styles with the --dds-error-summary-* custom properties, or style the base, heading, list, item and link parts.

dap-ds-error-summary {
  --dds-error-summary-border-width: var(--dds-border-width-large);
  --dds-error-summary-padding: var(--dds-spacing-400);
}

dap-ds-error-summary::part(link) {
  font-weight: var(--dds-font-weight-medium);
}
Accessibility Features
  • Announced on focus: the summary is a focusable container (tabindex="-1") with role="alert", labelled by its heading. focus() moves focus there, so screen readers announce it.
  • Real heading: the heading is a native <h1>–<h6> element, so users can find the summary from the page's heading list.
  • Real links: each item is a native <a href="#target"> inside a list item, so it is announced as a link and screen readers report how many problems there are.
  • Focus into shadow DOM: a link calls the target field's focus(), which DDS fields pass on to their inner control. A plain fragment jump would scroll to the field but not focus it.
  • Nothing to announce when empty: with no items the summary renders no alert, heading or list.
Importing Per-component import (Recommended)

Import the component by its own subpath. This registers <dap-ds-error-summary> (and the components it renders internally) and lets your bundler include only what you use:

import 'dap-design-system/components/error-summary'

Need a reference to the class (e.g. to register it manually or extend it)? The same subpath default-exports it:

import DapDSErrorSummary from 'dap-design-system/components/error-summary'
Register everything

Register the whole library at once — convenient, but pulls every component into your bundle:

import 'dap-design-system'
Importing React
import { DapDSErrorSummaryReact } from 'dap-design-system/react'
Attributes
PropertyTypeDefaultDescription
itemsDapDSErrorSummaryItem[][]The problems, as { target: string, message: string } objects, in the order of the fields on the page.
Set as a property only, not as an attribute. Each item renders a link to #target whose text is
message, so each message must name its field. With an empty list the summary renders nothing.
headingstringThe heading text. Defaults to the localized "There is a problem".
headingLevel1, 2 , 3 , 4 , 5 , 62The level of the heading, from 1 to 6.
ariaLabelstring, nullnullAccessible label for the element. Use this to provide a text alternative
for elements that don't have visible text content.
ariaExpanded'true', 'false'nullIndicates whether the element is expanded or collapsed.
ariaControlsstring, nullnullIdentifies the element that is controlled by this element.
ariaHasPopupstring, nullnullIndicates the availability and type of interactive popup element.
ariaDescribedBystring, nullnullIdentifies the element that describes the current element.
ariaPressed'true', 'false' , 'mixed'nullIndicates the current "pressed" state of toggle buttons.
ariaHidden'true', 'false'nullIndicates whether the element is hidden from accessibility APIs.
customStylesstring, undefinedCustom CSS text to be merged with the component's styles.
This CSS will be injected into the shadow DOM and merged with the component's static styles.
Slots

No slots available.

Events
Event NameDescriptionType
dds-item-selectFired when an item's link is activated, with the item's target id and index. Cancelable: call `preventDefault()` to move focus yourself (for example with react-hook-form's `setFocus`).{target: string, index: number }
CSS Parts
Part NameDescription
baseThe focusable alert container.
headingThe heading.
listThe list of problems.
itemA list item.
linkThe link of an item.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-error-summary::part(base) {
  /* Your custom styles */
}

/* Target multiple parts */
.my-custom-dap-ds-error-summary::part(base),
.my-custom-dap-ds-error-summary::part(heading) {
  /* Shared styles */
}

Example usage:

<dap-ds-error-summary class="my-custom-dap-ds-error-summary">
  Error summary
</dap-ds-error-summary>
.my-custom-dap-ds-error-summary::part(base) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-error-summary-paddingPadding of the summary. (default: var(--dds-spacing-600))
--dds-error-summary-gapGap between the heading and the list. (default: var(--dds-spacing-300))
--dds-error-summary-list-gapGap between the list items. (default: var(--dds-spacing-200))
--dds-error-summary-backgroundBackground color of the summary. (default: var(--dds-background-neutral-base))
--dds-error-summary-border-widthWidth of the border around the summary. (default: var(--dds-border-width-2xlarge))
--dds-error-summary-border-colorColor of the border around the summary. (default: var(--dds-border-negative-base))
--dds-error-summary-border-radiusBorder radius of the summary. (default: var(--dds-radius-base))
--dds-error-summary-heading-colorColor of the heading. (default: var(--dds-text-neutral-strong))
--dds-error-summary-heading-font-sizeFont size of the heading. (default: var(--dds-font-xl))
--dds-error-summary-heading-font-weightFont weight of the heading. (default: var(--dds-font-weight-bold))
--dds-error-summary-link-colorColor of the links. (default: var(--dds-text-negative-base))
--dds-error-summary-link-font-sizeFont size of the links. (default: var(--dds-font-base))
--dds-error-summary-link-font-weightFont weight of the links. (default: var(--dds-font-weight-bold))
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-error-summary
  style="--dds-error-summary-padding: value; --dds-error-summary-gap: value;">
  Error summary
</dap-ds-error-summary>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-error-summary {
  --dds-error-summary-padding: value;
  --dds-error-summary-gap: value;
  --dds-error-summary-list-gap: value;
}
<dap-ds-error-summary class="my-custom-dap-ds-error-summary">
  Error summary
</dap-ds-error-summary>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-error-summary {
  --dds-error-summary-padding: value;
  --dds-error-summary-gap: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.