Skip to main content

Components

ErrorSummary

ErrorSummary is a summary of errors. It provides the user with an overview of errors or issues that need to be addressed on a page or step in order to proceed.

asChild
Type
ReactNode
NameTypeDefaultDescription
asChildReactNode-

-

ErrorSummaryHeading

level
Description

Heading level. This will translate into any h1-6 level unless `asChild` is `true`

Type
1 | 2 | 3 | 4 | 5 | 6
Default
2
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
level1 | 2 | 3 | 4 | 5 | 62

Heading level. This will translate into any h1-6 level unless `asChild` is `true`

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

ErrorSummaryItem

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

ErrorSummaryLink

children
Description

The content to display inside the link.

Type
ReactNode
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
childrenReactNode-

The content to display inside the link.

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

ErrorSummaryList

asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
NameTypeDefaultDescription
asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

Usage

ErrorSummary consists of several subcomponents:

  • ErrorSummary.Heading defines the heading.
  • ErrorSummary.List defines the list of errors.
  • Each error is represented as an ErrorSummary.Item containing an ErrorSummary.Link.
  • Each ErrorSummary.Link must have an href to the unique identifier for a form field, so that the user can navigate to the correct place in the form.

Examples

Use with text fields

In order for ErrorSummary.Link to navigate to the fields with errors, the fields must have a unique id that matches the href in the link.

Moving focus

Below is an example where we move focus to ErrorSummary when it becomes visible.

HTML

The class name ds-error-summary is used on a container, the default for React is <div>.

As a child, you must have a heading (preferably <h2>) that has an id that can be referenced with aria-labelledby on the container.

We add a ds-list after the heading that contains a list of errors. Each error is a <li> with a link (<a>) that has the class ds-link and an href to the relevant field with errors.

CSS variables and data attributes

CSS Variables
NameValue
--dsc-errorsummary-backgroundvar(--ds-color-danger-surface-tinted)
--dsc-errorsummary-border-radiusvar(--ds-border-radius-md)
--dsc-errorsummary-paddingvar(--ds-size-6) var(--ds-size-8)
--dsc-errorsummary-link-colorvar(--ds-color-neutral-text-default)
--dsc-errorsummary-heading-colorvar(--ds-color-danger-text-default)

No relevant data attributes found.

Edit this page on github.com (opens in a new tab)