Notice
A short message in its own coloured box with an icon: a draft page, a legal page awaiting review, a site-wide message or a form's result.
Show code
---
import Notice from '@somnia/core/components/Notice.astro';
---
<Notice tone="warning" title="Draft.">For review by a solicitor before the site goes live.</Notice> When to use it
- Something the reader should know before they go on: this page is a draft, these listings are samples.
- The result of something they did, shown in the page where they did it.
Use something else when:
- It is only a confirmation they can carry on without reading: a toast.
- It is a problem with one field: say it under the field (form field).
- It is an offer or something to make a fuss of: a callout.
- It needs an answer before anything else: a modal.
How it works
- info (the default): something useful to know.
- warning: something to check before relying on the page.
- success and error: the result of something the visitor did.
Each has its own colours from the color.feedback.* tokens (surface, border and text, AA in light and dark) and its own icon. The words carry the meaning on their own; colour and icon only reinforce it, and a hidden "Note:", "Warning:", "Done:" or "Error:" prefix tells screen readers which it is. Errors are announced (role="alert"); the others are notes.
Where it's used
- Drafts (
DraftNotice) on case studies and articles markeddraft: true - Legal pages, from
notice:in their frontmatter (a string is shown as a warning, or{ tone, text }) - The site message under the header, from
messagein a site's config ({ tone, text, on: 'all' | 'staging' | 'live' })
Do and don't
Do
- Keep it to a sentence or two, with a bold lead-in
- Put it where the reader will see it before acting
Don't
- Stack several on one page
- Use it for marketing; that's the callout
Accessibility
What it does for you
- The words carry the meaning. Colour and icon repeat it, and a hidden first word says which kind it is to a screen reader: "Note:", "Warning:", "Done:" or "Error:".
- An error is an alert, read out as it appears. The others are notes, read when a reader comes to them.
- Each tone’s text, edge and background are checked against each other when the tokens are built, in light and dark.
- A notice that can be closed has a real button, named "Dismiss this message". Closing it moves the focus to the next notice’s button, or to where the notice was.
- The icon is decoration.
What you need to do
- Words that make sense with the colour taken away.
- A notice that appears because of something the person did needs announcing or the focus: it isn’t read out by itself unless it is an error.
- Never a close button on a warning or an error that still needs doing.
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves to a notice’s close button, when it has one. |
| Enter or Space | Closes it. |
What a screen reader is told
- "Note" (or "alert" for an error), then the hidden first word, then the notice’s words.
This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.
WCAG 2.2
| Criterion | Level | How this meets it |
|---|---|---|
| 1.4.1 Use of Color | A | The kind of notice is in its words, not only its colour. |
| 1.4.3 Contrast (Minimum) | AA | Each tone’s text against its background. |
| 2.4.3 Focus Order | A | Closing one hands the focus on. |
| 4.1.2 Name, Role, Value | A | A named close button. |
| 4.1.3 Status Messages | AA | An error is announced without taking the focus. |
The criteria this component has a part in. A page that uses it still has to meet the rest.
Checked
| Check | How | Result |
|---|---|---|
| Automated (axe-core) | WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in dark | Passed Nothing found, light or dark |
| Narrow screen | No sideways scrolling at 320px wide (WCAG 1.4.10) | Passed No sideways scrolling |
| Keyboard and what the browser reports | Real key presses on the live example, and the role, name and state given to assistive technology | Passed 7 of 7 checks pass |
| On paper | Somnia’s print check: no overlaps, stranded headings or controls on the page | Passed No faults on 5 sheets |
| Screen reader | Listened to by a person, in VoiceOver and NVDA | Not yet Not yet checked by a person |
The 7 checks made with the keyboard, on the example at the top of this page:
- Passed An error is an alert; the other tones are notes
- Passed Each starts with a word, for screen readers only, that says its kind
- Passed The icon is not reported to a screen reader
- Passed Each tone’s words have at least 4.5:1 against its background, in light and dark
- Passed A notice that can be closed has a button named "Dismiss this message", and only that one is a stop
- Passed Enter on it closes the notice, and the focus stays where the notice was
- Passed The close button is at least 24px square
Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.
Not yet checked
- How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
- Windows high contrast (forced colours) has not been looked at by a person.
- Whether "note" is said at all varies between screen readers: some pass over the role. The hidden first word is there so the kind is said either way.
Evidence
Where it's used
| Where | For |
|---|---|
| Every Somnia site | Draft pages on staging, legal pages awaiting review, the site message under the header. |
| Somnia CMS | Every message in the editor, in the page or as a toast. |
What we saw, and what changed
| When | What we saw | What changed |
|---|---|---|
| A notice could not be closed. | A notice can have a close button, and can stay closed in that browser (1.56.0). | |
| A notice from the component, one written into a page’s text and a toast were three sets of styles. | Styled once, so they look the same (1.64.0). |
From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.
What we don't know yet
- Nothing is known about whether notices are read.