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.
✅ 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.
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 }:
| Field | Type | Description |
|---|---|---|
target | string | The id of the field to focus. The link points at #target. |
message | string | The 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' },
]}
/>
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.
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>
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.
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>
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);
}
- Announced on focus: the summary is a focusable container (
tabindex="-1") withrole="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.
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 the whole library at once — convenient, but pulls every component into your bundle:
import 'dap-design-system'
import { DapDSErrorSummaryReact } from 'dap-design-system/react'
| Property | Type | Default | Description |
|---|---|---|---|
items | DapDSErrorSummaryItem[] | [] | 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. | |||
heading | string | The heading text. Defaults to the localized "There is a problem". | |
headingLevel | 1, 2 , 3 , 4 , 5 , 6 | 2 | The level of the heading, from 1 to 6. |
ariaLabel | string, null | null | Accessible label for the element. Use this to provide a text alternative |
| for elements that don't have visible text content. | |||
ariaExpanded | 'true', 'false' | null | Indicates whether the element is expanded or collapsed. |
ariaControls | string, null | null | Identifies the element that is controlled by this element. |
ariaHasPopup | string, null | null | Indicates the availability and type of interactive popup element. |
ariaDescribedBy | string, null | null | Identifies the element that describes the current element. |
ariaPressed | 'true', 'false' , 'mixed' | null | Indicates the current "pressed" state of toggle buttons. |
ariaHidden | 'true', 'false' | null | Indicates whether the element is hidden from accessibility APIs. |
customStyles | string, undefined | Custom 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. |
No slots available.
| Event Name | Description | Type |
|---|---|---|
dds-item-select | Fired 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 } |
| Part Name | Description |
|---|---|
base | The focusable alert container. |
heading | The heading. |
list | The list of problems. |
item | A list item. |
link | The link of an item. |
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.
| Property Name | Description |
|---|---|
--dds-error-summary-padding | Padding of the summary. (default: var(--dds-spacing-600)) |
--dds-error-summary-gap | Gap between the heading and the list. (default: var(--dds-spacing-300)) |
--dds-error-summary-list-gap | Gap between the list items. (default: var(--dds-spacing-200)) |
--dds-error-summary-background | Background color of the summary. (default: var(--dds-background-neutral-base)) |
--dds-error-summary-border-width | Width of the border around the summary. (default: var(--dds-border-width-2xlarge)) |
--dds-error-summary-border-color | Color of the border around the summary. (default: var(--dds-border-negative-base)) |
--dds-error-summary-border-radius | Border radius of the summary. (default: var(--dds-radius-base)) |
--dds-error-summary-heading-color | Color of the heading. (default: var(--dds-text-neutral-strong)) |
--dds-error-summary-heading-font-size | Font size of the heading. (default: var(--dds-font-xl)) |
--dds-error-summary-heading-font-weight | Font weight of the heading. (default: var(--dds-font-weight-bold)) |
--dds-error-summary-link-color | Color of the links. (default: var(--dds-text-negative-base)) |
--dds-error-summary-link-font-size | Font size of the links. (default: var(--dds-font-base)) |
--dds-error-summary-link-font-weight | Font weight of the links. (default: var(--dds-font-weight-bold)) |
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.