Skip to content

ErrorSummary

Everything to fix in a form, at the top, after a failed try. Each line is a link to its field. A Form shows it by itself; use it on its own in forms that do their own sending.

import { ErrorSummary, Field } from '@sypnia/ui/react'

On this page
  1. Two fields to fix
  2. When to use it
  3. For everyone
  4. Props

Two fields to fix

Press a line of the summary: the focus goes to its field.

Write the server address, for example db.northwind.io.

Use a number between 1 and 65535.

Code
import { ErrorSummary, Field, FormGrid, Input } from '@sypnia/ui/react';

// On its own, for forms that do their own submitting. Each line moves the focus to its field.
const problems = [
  { name: 'host', label: 'Host', message: 'Write the server address, for example db.northwind.io.' },
  { name: 'port', label: 'Port', message: 'Use a number between 1 and 65535.' },
];

export default function Summary() {
  return (
    <form className="sy-form" noValidate aria-label="Connection">
      <ErrorSummary problems={problems} />
      <FormGrid>
        <Field label="Host" error={problems[0].message}><Input name="host" machine /></Field>
        <Field label="Port" error={problems[1].message}><Input name="port" machine defaultValue="99999" /></Field>
      </FormGrid>
    </form>
  );
}

When to use it

Use it when

  • Forms with more than one or two fields, where an error can be out of sight.
  • Write the same message as next to the field, with the field's name first.

Do not use it when

  • Errors that are not about a field, such as the server not answering: use an Alert.
  • Showing it before the person tries to send.

For everyone

  • It takes the focus when it appears and is named by its title, «Check these fields».
  • It is not a live region, so fixing a field does not read the list again.
  • Each link moves the focus to its field and scrolls it to the middle of the screen.

Props

ErrorSummaryTypeDefault
problemsrequired FormProblem[]
focusOn

Takes the focus each time this changes (a Form passes its count of failed tries). Without it, when the list changes.

number
form RefObject<HTMLFormElement | null>
title ReactNode
FieldTypeDefault
labelrequired ReactNode
className string
error

What is wrong and how to fix it. Its presence marks the control as invalid.

ReactNode
hint

Help that is always visible: what to write, in what format.

ReactNode
optional

Adds «optional» beside the label. Required is the default and is not marked.

boolean
wide

Spans both columns of a FormGrid.

boolean
  1. Two fields to fix
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms