There is a problem
Several errors
One link per error, in the same order as the fields.
Lists every error on the page after a submit fails, with a link to each field, so people can find and fix them.
Updated
Error summary
HTML
<div class="nds-error-summary" role="alert" tabindex="-1"> <div class="nds-error-summary__inner"> <div class="nds-error-summary__heading"> <span class="nds-error-summary__icon" aria-hidden="true"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="none" focusable="false" aria-hidden="true"> <path d="M10 5.5v5.5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/> <circle cx="10" cy="14.5" r="1" fill="currentColor"/> </svg> </span> <h2 class="nds-error-summary__title"> There is a problem </h2> </div> <ul class="nds-error-summary__list"> <li> <a class="nds-error-summary__link" href="#first-name"> Enter your first name </a> </li> <li> <a class="nds-error-summary__link" href="#last-name"> Enter your last name </a> </li> </ul> </div></div> WordPress
<!-- wp:nds/error-summary {} --><div class="nds-error-summary" role="alert" tabindex="-1"> <div class="nds-error-summary__inner"> <div class="nds-error-summary__heading"> <span class="nds-error-summary__icon" aria-hidden="true"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="none" focusable="false" aria-hidden="true"> <path d="M10 5.5v5.5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/> <circle cx="10" cy="14.5" r="1" fill="currentColor"/> </svg> </span> <h2 class="nds-error-summary__title"> There is a problem </h2> </div> <ul class="nds-error-summary__list"> <li> <a class="nds-error-summary__link" href="#first-name"> Enter your first name </a> </li> <li> <a class="nds-error-summary__link" href="#last-name"> Enter your last name </a> </li> </ul> </div></div><!-- /wp:nds/error-summary --> Usage
import { ErrorSummary } from "@nigerian-design-standards/react";<ErrorSummary title="There is a problem" errors={[{ href: "#first-name", text: "Enter your first name" }, { href: "#last-name", text: "Enter your last name" }]}/> Usage
use NDS\Components\ErrorSummary;echo ErrorSummary::render([ 'title' => 'There is a problem', 'errors' => [ [ 'href' => '#first-name', 'text' => 'Enter your first name', ], [ 'href' => '#last-name', 'text' => 'Enter your last name', ], ],]); Show the error summary just above the submit button when a submit fails and there is at least one error. It lists every error as a link to its field, in the same words as the error under the field.
It looks the same for one error or many. Only the number of links changes.
One link per error, in the same order as the fields.
Still shown for a single error, so people always find it.
The properties of the error summary. The same in HTML and React.
| Property | Type | Possible values | Description |
|---|---|---|---|
| title | string |
| Optional. Defaults to “There is a problem”. Keep it. |
| errors | array | text + href | Required. One link per error, going to its field, in the same order as the fields. |
The summary has role="alert" and tabindex="-1". After a failed submit,
move focus to it and start the page <title> with “Error: ”. Each link targets
the field’s id (for radios or checkboxes, the first option in the set).
| Part | Token | Contrast on the page |
|---|---|---|
| Container | surface/canvas · status/error/surface border, 2px (border/width/thick) | 4.9:1 |
| Icon | 20px (size/icon/md) status/error/surface disc · icon/exclamation (text/white) at 12px (spacing/150) | 4.9:1 · exclamation 4.9:1 |
| Title | Title/medium · text/primary | 17.6:1 |
| Links | Body/small-emphasized · status/error/surface, underlined | 4.9:1 |
| Padding | spacing/300 — 24px on every side | — |
| Gaps | spacing/200 16px (title block to links) · spacing/100 8px (icon to title) | — |
| Width | Fills the form column (560px in the component) | — |
List every error, in the same words as the error under the field.
Don’t give a vague message. Each link names the field and how to fix it.
Where the error summary goes and how it behaves.
How to write the title and error links.
Use the same words in the summary as under the field.
“Date of birth must be in the past”, not “You entered an invalid date”.
When there are errors, start the page title with “Error: ”, for example “Error: Contact us”.
| Write | Don’t write | Why |
|---|---|---|
| Enter your first name | This field is required | Names the field and the fix. |
| Enter an email address in the correct format, like name@example.com | Invalid email | Says how to fix it. |
| Select how you want to be contacted | Please select an option | Says what to do. |
| Business name must be 120 characters or fewer | Too many characters | Gives the limit. |
| There is a problem | Oops! Something went wrong | Calm and plain. |
After a failed submit, focus moves to the summary, so people hear the errors first.
| Key | What it does |
|---|---|
| Tab | Moves through the error links in order. |
| Shift + Tab | Moves back. |
| Enter | Follows the link and moves focus to the field. |
Copy the code for HTML, WordPress or React from the Code tab in Live example. The options are listed under Specifications.
Use nds-error-summary from 01 Library – Foundations. Keep the title and link each error to its field. Don’t detach it.
Is this page useful?