Skip to main content

What are you looking for?

Try searching for…

Components

Error summary

Error summary 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.

HTML

Press Enter to start editing
Unable to parse html
const PreviewEn = () => {
  return (
    <ErrorSummary>
      <ErrorSummary.Heading>
        To proceed, you must correct the following errors:
      </ErrorSummary.Heading>
      <ErrorSummary.List>
        <ErrorSummary.Item>
          <ErrorSummary.Link href='#'>
            Birthdate cannot be after the year 2005
          </ErrorSummary.Link>
        </ErrorSummary.Item>
        <ErrorSummary.Item>
          <ErrorSummary.Link href='#'>
            Phone number can only contain digits
          </ErrorSummary.Link>
        </ErrorSummary.Item>
        <ErrorSummary.Item>
          <ErrorSummary.Link href='#'>Email must be valid</ErrorSummary.Link>
        </ErrorSummary.Item>
      </ErrorSummary.List>
    </ErrorSummary>
  );
};

render(<PreviewEn />)

Usage

The class name ds-error-summary is used on the <ds-error-summary> element. The web component handles focus when it becomes visible and aria-labelledby automatically.

We add a <ul class="ds-list"> after the heading which 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 the error.

CSS variables and data attributes

Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.

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.

Example

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 of how focus is automatically moved to error summary when it becomes visible.

React

Error summary 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.
asChild
Description

@deprecated This is not supported anymore, as the element needs to be `ds-error-summary`

Type
ReactNode
NameTypeDefaultDescription
asChildReactNode-

@deprecated This is not supported anymore, as the element needs to be `ds-error-summary`

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.

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