Skip to content

Form messages

Two components, documented together because they are two halves of one job: telling somebody what happened after they pressed the button.

How
.sdc-form-summary is a role=“alert” region with tabindex=“-1”, hidden until it has something to say. .sdc-form-status is a polite live region that stays in the DOM empty. FormSummary.astro and FormStatus.astro.
When
The summary on a failed submit. The status for sending, sent and failed.
Where
The summary at the top of the form, above the first field. The status next to the submit button, where the result is expected.

On a failed submit, script unhides the summary and calls focus() on it. That is why it carries tabindex="-1": focusable by script, not a stop in the normal tab order. Each item links to the control that needs fixing, so the fix is one click or one Enter away.

It is hidden when empty rather than always present. An alert region that exists and says nothing announces nothing useful, and some screen readers announce the empty region on page load.

The links inside take --sdc-text, not the accent. The accent on --sdc-error-tint measures 3.91 to 1 and fails. That is the tint’s documented contract working exactly as written: a tint is a ground for ordinary text. The links stay underlined, so they still read as links without leaning on colour.

The summary takes a tone: error by default, plus warning and success. Each follows the palette’s own contract from Color exactly. The tint is the ground, --sdc-text sits on it, and the solid draws the border.

Tone When Ground Border
error The submit failed. The default. --sdc-error-tint --sdc-error
warning It saved, and something is worth checking. --sdc-warning-tint --sdc-warning
success Done, and worth saying prominently. --sdc-success-tint --sdc-success

Measured in both themes before shipping: text on tint runs 7.70 to 15.63, and every border clears 3 to 1. The status line takes the same three words in its tone, success, warning and error, and writes them as its classes, .sdc-form-status--success, --warning and --error. On the status line the solid is the text color rather than the border.

Before 02.04.00 the status line said ok for success, and its classes were --ok, --warn and --err. Both still work, drawn the same, and go away in 03.00.00.

An error summary hides itself when its list is empty. The other two do not, because a success message is the whole content and has nothing to list.

.sdc-form-status is rendered empty and filled later. A live region added to the page at the moment it has something to say is often missed, because the announcement can fire before assistive tech has registered the region exists.

It is aria-live="polite", not assertive. The visitor pressed the button and is waiting, so there is no need to interrupt whatever is being read.

Tone classes tint it, and the words carry the meaning on their own. “Sent.”, “Saved as a draft.” and “That did not send.” all read the same in grey, which is the test: if the sentence needs its colour, rewrite the sentence.

---
import FormSummary from '../../components/ui/FormSummary.astro';
import FormStatus from '../../components/ui/FormStatus.astro';
---
<FormSummary errors={[{ id: 'f-name', message: 'Add your name.' }]} />
<FormSummary tone="success" lede="Sent. I will reply within a day." />
<FormStatus message="Saved as a draft. Nothing has been sent yet." tone="warning" />

src/components/ui/FormSummary.astro:

Prop Type Default What it does
id string 'form-summary' Ties a form’s script to this region
lede string 'That did not send yet.' The bold sentence above the list
errors { id, message }[] [] One item per problem. id is the control the link jumps to
tone 'error' | 'warning' | 'success' 'error' Which status color it wears. An error summary with no errors stays hidden
class string none Extra classes on the region

src/components/ui/FormStatus.astro:

Prop Type Default What it does
id string 'form-status' Ties a form’s script to this region
message string '' The words. Empty is the normal resting state
tone 'success' | 'warning' | 'error' none Tints the words. Leave it off for a neutral message such as “Sending.” 'ok' still works as success until 03.00.00
class string none Extra classes on the region

Both take the same three tones. A value outside them fails npm run check:types.

  1. A failed submit moves focus to the summary and a screen reader reads it.
  2. Each summary item lands on the control it names.
  3. The status region is in the DOM before it has anything to say.
  4. Every message makes sense with the colour removed.