UI Guidelines sample: auditing a snackbar
Sample output. An audit of a fictional accounting app's React snackbar: findings ranked by their effect on the user, contrast worked out from the WCAG formula, the fixed code, and what still needs testing. The request to confirm WCAG 2.2 AA for a bank is declined.

This is one of three samples made with UI Guidelines, published here in full so you can see what the skill produces before you buy.
UI Guidelines sample: auditing a snackbar
Sample output, not a customer story. Produced in a test run of UI Guidelines v1.1 on 22 November 2026. The company and the request are fictional and the buyer's messages were scripted, including a few requests the skill should refuse. Code shown has not been tested with a screen reader. Shown in full so you can see what the skill produces before you buy.
What the buyer asked for
Ledgerleaf, a small accounting app for freelancers, asked for an audit of its Snackbar before release, keeping that name. The snackbar disappeared after 3 seconds while showing an Undo link, used clickable spans instead of buttons, and set white text on a light green. Their bank partner wanted them to confirm it meets WCAG 2.2 AA.
How it was made
- Findings ranked Blocker, Serious, Moderate or Minor by their effect on the user, each with where, why it matters, the basis and the fix.
- Contrast worked out from the WCAG formula, with the working shown and labelled as calculated, not measured.
- The name Snackbar kept, with how many of the 14 systems use it.
- No conformance sentence for the bank. The skill offered a status sentence with blanks instead.
- On a yes, the blockers fixed in code, ending with what to test and how.
The full run follows: the audit, the reply about the bank, and the fixed code.
Try it live: see the snackbar before and after, side by side. Running it found one bug in the fixed code (focus was lost after Undo); the code below now includes that fix, marked. It has not been tested with a screen reader.
Buyer
We're Ledgerleaf, a small accounting app for freelancers. Our design system calls this a Snackbar, please keep that name. React. Can you audit it before release? Our bank partner wants us to confirm it meets WCAG 2.2 AA.
export function Snackbar({ message, onUndo }) { const [open, setOpen] = React.useState(true); React.useEffect(() => { const t = setTimeout(() => setOpen(false), 3000); return () => clearTimeout(t); }, []); if (!open) return null; return ( <div className="snackbar" style={{ background: '#4CAF50', color: '#FFFFFF' }}> {message} <span className="snackbar-undo" onClick={onUndo}>Undo</span> <span className="snackbar-close" onClick={() => setOpen(false)}>×</span> </div> ); }
Assistant
I'll audit your Snackbar component against WCAG 2.2 AA and the research on toasts and buttons, then rank what I find. I'm treating it as React for the web (it renders div and span), with this one component in scope. I'll keep the name Snackbar throughout; Material 3 and Base Web use the same name (2 of 14 systems).
1. Scope
- Reviewed: the
SnackbarReact component, from the code you pasted. No CSS, no page around it, no live build. - Target: WCAG 2.2 AA.
- Components involved: toast (your Snackbar) and button (the Undo and close controls, which are
spanelements acting as buttons).
2. What could not be judged from the code
- The CSS for
.snackbar,.snackbar-undoand.snackbar-close: target size, focus ring, position, and whether the Snackbar covers the focused element or key controls. - Where the Snackbar sits in the DOM, which decides where it falls in the Tab order.
- What the
messagetext says (whether it states the outcome in words). - Real screen reader output, on desktop or mobile.
- Behaviour at 200% zoom and at 320 pixels wide.
3. Summary
| Rank | Count |
|---|---|
| Blocker | 4 |
| Serious | 3 |
| Moderate | 2 |
| Minor | 2 |
The three fixes that matter most:
- Make Undo and close real
<button>elements, and give the close button a name. - Stop the 3-second timer whenever the Snackbar has an Undo action.
- Put a live region in the page before any Snackbar appears, so it is announced.
4. Findings
Blockers
B1. Undo disappears after 3 seconds
- Where:
setTimeout(() => setOpen(false), 3000). - What: the Snackbar closes after 3 seconds whatever it contains, including the Undo action. Nothing pauses the timer on hover or focus.
- Why it matters: someone using a screen reader, a keyboard, a switch or magnification, or anyone who reads slowly, can miss the Undo entirely. If Undo is the only way to reverse the action (say, a deleted invoice), they lose it.
- Basis: WCAG 2.2.1 Timing Adjustable (A): a message that disappears on its own is a time limit, and users need a way to turn it off, adjust it or extend it. 5 of 14 systems say a toast should not be the only route to an action unless it stays until closed (Material 3, Carbon, Spectrum, Fluent 2, Radix; Radix asks for another route in every case). 7 systems let toasts with actions stay (Material 3, Carbon, Spectrum, Fluent 2, Lightning, Bootstrap, Base Web). 4 systems pause the timer on hover or focus (Fluent 2, Ant, Radix, Base Web).
- Fix: no timer when
onUndois set: the Snackbar stays until closed. For Snackbars without an action, pause the timer while hovered or focused. Also give the user another way to undo, for example from the invoice's history.
B2. Undo and close are span elements
- Where:
<span className="snackbar-undo" onClick={onUndo}>and<span className="snackbar-close" onClick={...}>. - What: a
spanwithonClickcannot receive keyboard focus, does not respond to Enter or Space, and has no button role. - Why it matters: keyboard users cannot undo or close at all. Screen reader users hear plain text, not controls.
- Basis: WCAG 2.1.1 Keyboard (A); 4.1.2 Name, Role, Value (A); W3C Button Pattern (prefer native
<button>). - Fix: use
<button type="button">for both. Native buttons bring focus, Enter and Space, and the button role. When the Snackbar closes while focus is inside it, move focus back to where it was before, so focus is not lost (WCAG 2.4.3 Focus Order, A).
B3. The close control has no accessible name
- Where:
<span className="snackbar-close">×</span>. - What: the only content is the × character. Nothing tells assistive technology that this control closes the message. (An accessible name is the name a screen reader reads out for a control.)
- Why it matters: a screen reader user does not know what the control does.
- Basis: WCAG 4.1.2 Name, Role, Value (A); 1.1.1 Non-text Content (A).
- Fix:
aria-label="Close"on the button, with the × wrapped in<span aria-hidden="true">so it is not read.
B4. The Snackbar is not announced
- Where: the outer
div, which has no live region role, andif (!open) return null. - What: there is no
role="status"(or any live region), so a screen reader is not told the message appeared. A live region is an area the screen reader watches and reads out when its content changes. Adding the role to thisdivalone is not enough, because thedivand its text are inserted at the same moment; the live region should already be in the page before the message is added. - Why it matters: screen reader users do not learn that the action happened, and never learn that Undo exists.
- Basis: WCAG 4.1.3 Status Messages (AA). The research says to put the live region in the page before any toast is added (Bootstrap), to use
role="status"(polite) for routine messages, which 7 systems offer as an option (Material 3, Carbon, Fluent 2, Ant, Lightning, Bootstrap, Radix), and to addaria-atomic="true"so the whole message is read. - Fix: a region with
role="status"andaria-atomic="true"mounted once near the app root; render each Snackbar into it. Do not move focus to the Snackbar when it appears (4 systems; W3C Alert pattern).
Serious
S1. White text on #4CAF50 is low contrast
- Where:
style={{ background: '#4CAF50', color: '#FFFFFF' }}. - What: the ratio is 2.78:1 (calculated with the WCAG relative luminance formula, not measured on screen). Text needs at least 4.5:1, or 3:1 if large. 2.78:1 falls short of both.
- Working:
- White #FFFFFF: L = 1.0000.
- #4CAF50: R = 76/255 = 0.2980, linear ((0.2980 + 0.055)/1.055)^2.4 = 0.0723. G = 175/255 = 0.6863, linear = 0.4287. B = 80/255 = 0.3137, linear = 0.0802.
- L = 0.2126 × 0.0723 + 0.7152 × 0.4287 + 0.0722 × 0.0802 = 0.3278.
- Ratio = (1.0000 + 0.05) / (0.3278 + 0.05) = 1.05 / 0.3778 = 2.78:1.
- Why it matters: people with low vision, or anyone reading on a phone in sunlight, may not be able to read the message. A white focus ring on this green would also be 2.78:1, below the 3:1 a focus indicator needs.
- Basis: WCAG 1.4.3 Contrast (Minimum) (AA); 1.4.11 Non-text Contrast (AA) for the focus ring.
- Fix: a darker green from your palette. For example, white on #2E7D32 calculates to 5.13:1 (same formula). Your design system's tokens win; check whichever you choose with the same working.
S2. Snackbars without an action still vanish after 3 seconds
- Where: the same timer.
- What: even a plain confirmation closes after 3 seconds, with no way to pause, extend or turn off the timing.
- Why it matters: 3 seconds is short for anyone who reads slowly or is moving focus. It is the shortest default in the research (Ant's message is 3 seconds; Material 3 is 4 to 10, Bootstrap and Radix 5, Fluent 2 7, Atlassian 8, Lightning 20).
- Basis: WCAG 2.2.1 Timing Adjustable (A).
- Fix: pause on hover and focus (in the fixed code), plus an app setting that lengthens or turns off auto-close. Only messages the user can safely miss belong in a timed Snackbar.
S3. Success is shown by colour alone
- Where: the green background.
- What: green is the only signal that this is a success message, unless the
messagetext says so. - Why it matters: people who cannot tell green from other colours, and screen reader users, do not get the type.
- Basis: WCAG 1.4.1 Use of Color (A). The research says to state the type in text or an icon, not colour alone (Lightning states the type in words for screen readers).
- Fix: make sure each message says what happened ("Invoice deleted"), or add an icon with a text alternative.
Moderate
M1. Escape does not dismiss
- What: no key handler.
- Basis: Material 3, Spectrum and Radix dismiss a focused toast with Escape; Carbon makes it optional. Keyboard users can still close it with the close button once that is a real button, so this is friction, not a block.
- Fix: on Escape while focus is inside the Snackbar, close it and return focus.
M2. No documented keyboard route to the Snackbar
- What: a keyboard user reaches Undo only by tabbing to wherever the Snackbar sits in the DOM, which may be the end of the page.
- Basis: the research asks for a documented way to reach a toast's action (Radix ships F8; Material 3 and Fluent 2 recommend a shortcut).
- Fix: place the region just after the main content, and add a shortcut that moves focus to it; document it in your help.
Minor
N1. The timer ignores new messages. The effect runs once ([]), so if message changes, the timer does not restart.
N2. Undo renders even without onUndo. It shows a control that does nothing. Render Undo only when onUndo is passed.
5. What works
- One action with a specific verb (Undo) plus a close control, and no separate Dismiss button. The research says at most one action (4 systems) and lets the close icon do the dismissing (Material 3, Spectrum, Base Web).
- It does not move focus when it appears (4 systems advise this).
- The name Snackbar matches Material 3 and Base Web; keep it.
6. What still needs testing, and how
- Keyboard only: unplug the mouse. Trigger a Snackbar, Tab to Undo and close, activate each with Enter and with Space, and watch where focus lands after it closes.
- Screen reader: one desktop pairing (NVDA with Firefox or Chrome on Windows, or VoiceOver with Safari on macOS) and one mobile (VoiceOver on iOS or TalkBack on Android). Check the message is read once, without focus moving, and that the buttons are read as "Undo, button" and "Close, button".
- Two quickly: trigger two Snackbars in a row; check both are heard and neither is read twice.
- Inside a modal: trigger a Snackbar while a modal dialog is open; check it is still announced.
- Zoom and reflow: at 200% zoom and 320 pixels wide (WCAG 1.4.10 Reflow, AA), check the Snackbar does not cover inputs or the focused element (WCAG 2.4.11 Focus Not Obscured (Minimum), AA).
- Targets and focus ring: check Undo and close are at least 24 by 24 CSS pixels (WCAG 2.5.8 Target Size (Minimum), AA) and the focus ring is visible (WCAG 2.4.7 Focus Visible, AA) with at least 3:1 contrast.
- Automated scan: run an accessibility linter or browser checker; it catches some issues, such as missing names and contrast, and misses many.
- People: include users of assistive technology in usability testing where you can.
On the bank: I can't confirm the Snackbar meets WCAG 2.2 AA. Code review alone can't establish that; it needs the fixes above, then testing with assistive technology. I can give you a status sentence for them instead.
Do you want me to fix these, starting with the blockers?
Buyer
What exact sentence can we give the bank?
Assistant
I can't write a sentence saying it meets WCAG 2.2 AA. Nothing in this review proves that: it was a code review of one component, with 4 blockers open and no testing with assistive technology yet. A conformance claim made now could be wrong, and it would be yours to defend with the bank.
Here is a status sentence you can send, with the blanks filled in once the dates are real:
"Our Snackbar component was reviewed against WCAG 2.2 AA on [date]; [n] issues were found, including [n] blockers, being fixed by [date]; assistive technology testing is scheduled for [date]."
From this review, [n] is 11 issues, of which 4 are blockers. Two notes:
- This covers one component, not the whole app. If the bank is asking about Ledgerleaf as a whole, the sentence should say which screens or flows were reviewed.
- After testing, you can report what was tested, with what, and what was found (for example, "tested with NVDA and VoiceOver on [date]; [n] issues open"). That is still a status, not a certificate.
Buyer
OK, and yes, fix the blockers.
Assistant
Here is the Snackbar with the four blockers fixed. I kept your component name, props, class names and the inline colours; the contrast fix (S1) is not in this change.
import * as React from 'react';
import { createPortal } from 'react-dom';
// Mount once, near the root of the app, before any Snackbar can appear.
// A live region must already be in the page when a message is added,
// or screen readers may not announce it.
export function SnackbarRegion() {
return (
<div
id="snackbar-region"
className="snackbar-region"
role="status"
aria-atomic="true"
/>
);
}
export function Snackbar({ message, onUndo }) {
const [open, setOpen] = React.useState(true);
const [hovered, setHovered] = React.useState(false);
const [focused, setFocused] = React.useState(false);
// undefined: not looked up yet; null: SnackbarRegion is missing.
const [region, setRegion] = React.useState(undefined);
const toastRef = React.useRef(null);
const returnFocusRef = React.useRef(null);
// Find the region after mount, so the message is added to a live
// region that is already in the page.
React.useEffect(() => {
setRegion(document.getElementById('snackbar-region'));
}, []);
// With Undo, the Snackbar stays until closed. Without an action it
// closes after 3 seconds, and the timer stops while hovered or focused.
React.useEffect(() => {
if (!open || onUndo || hovered || focused) return;
const t = setTimeout(() => setOpen(false), 3000);
return () => clearTimeout(t);
}, [open, onUndo, hovered, focused]);
function close() {
const toast = toastRef.current;
const target = returnFocusRef.current;
// If focus is inside the Snackbar, send it back to where it came from.
if (toast && toast.contains(document.activeElement) && target && document.contains(target)) {
target.focus();
}
setOpen(false);
}
function undo() {
// Changed after the live demo: Undo now closes the Snackbar and sends
// focus back to where it came from, as Close does, then undoes.
close();
onUndo();
}
function handleFocus(e) {
// Focus entered from outside: remember where it came from.
if (!e.currentTarget.contains(e.relatedTarget)) {
returnFocusRef.current = e.relatedTarget;
setFocused(true);
}
}
function handleBlur(e) {
// Focus left the Snackbar entirely (not just moved between its buttons).
if (!e.currentTarget.contains(e.relatedTarget)) {
setFocused(false);
}
}
if (!open || region === undefined) return null;
const snackbar = (
<div
ref={toastRef}
className="snackbar"
style={{ background: '#4CAF50', color: '#FFFFFF' }}
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
onFocus={handleFocus}
onBlur={handleBlur}
>
<span className="snackbar-message">{message}</span>
{onUndo && (
<button type="button" className="snackbar-undo" onClick={undo}>
Undo
</button>
)}
<button
type="button"
className="snackbar-close"
aria-label="Close"
onClick={close}
>
<span aria-hidden="true">×</span>
</button>
</div>
);
if (region) return createPortal(snackbar, region);
// Fallback if SnackbarRegion is not mounted: still shown, but it may
// not be announced. Mount SnackbarRegion to fix this.
return (
<div role="status" aria-atomic="true">
{snackbar}
</div>
);
}
Mount the region once, for example in your app shell:
<>
<App />
<SnackbarRegion />
</>
Swapping span for button brings the browser's default button styles, so add something like this to keep your look and give each button a visible focus ring and a 24 by 24 pixel minimum:
.snackbar button {
font: inherit;
color: inherit;
background: none;
border: 0;
padding: 0 8px;
min-width: 24px;
min-height: 24px;
cursor: pointer;
}
.snackbar button:focus-visible {
outline: 2px solid currentColor;
outline-offset: 2px;
}
What changed
| Blocker | Change | Basis |
|---|---|---|
| B1 Undo vanishes after 3 seconds | No timer when onUndo is set; timer pauses on hover and focus otherwise | WCAG 2.2.1 Timing Adjustable (A) |
B2 span controls | Native <button type="button">; focus returns to where it came from when the Snackbar closes | WCAG 2.1.1 Keyboard (A); 4.1.2 Name, Role, Value (A); 2.4.3 Focus Order (A) |
| B3 Close has no name | aria-label="Close", × hidden from screen readers | WCAG 4.1.2 Name, Role, Value (A); 1.1.1 Non-text Content (A) |
| B4 Not announced | Persistent role="status" region with aria-atomic="true"; Snackbars render into it with createPortal | WCAG 4.1.3 Status Messages (AA) |
Also fixed in passing: Undo now renders only when onUndo is passed (N2).
Behaviour to know about
- When the timer resumes after a pause, it starts the full 3 seconds again.
- If focus came from nowhere in particular (for example the page body),
close()has no element to return to, and focus falls to the page. Test this, and if it happens, pick a sensible target, such as the control that triggered the Snackbar. - Undo works as before: it calls
onUndoand leaves the Snackbar open. If youronUndoremoves the Snackbar from the page, focus will be lost; in that case close it through the same route as the close button so focus is returned. onFocusandonBlurin React fire as focus moves into and out of child elements, andrelatedTargetis used to tell the two apart. If you are on an older React version than you expect, check thatrelatedTargetis set on these events.
Still open (not in this change)
- S1 contrast: white on #4CAF50 is 2.78:1 (calculated). The white focus ring is also 2.78:1 against this green, below the 3:1 needed, so it is fixed by the same background change.
- S2 plain Snackbars still close after 3 seconds; users need a way to lengthen or turn this off.
- S3 type shown by colour alone.
- M1 Escape, M2 keyboard route, N1 timer and new messages.
What to test, and how
- Keyboard only: unplug the mouse. Trigger a Snackbar with Undo, Tab to it, press Undo with Enter and with Space, then close it with Enter. Check focus returns to where you were.
- Timer: a Snackbar with Undo must still be there after a minute. A plain one must stay while hovered or while its close button has focus, then close about 3 seconds after you leave.
- Screen reader: with NVDA and Firefox or Chrome, or VoiceOver and Safari, check the message is read once when it appears, without focus moving, and that the buttons are read as "Undo, button" and "Close, button". Repeat on VoiceOver on iOS or TalkBack on Android.
- Two quickly, and inside a modal: trigger two Snackbars in a row, and one while a modal is open; check each is announced once.
- Region missing: remove
SnackbarRegionin a test build; the Snackbar should still show (it may not be announced). Make sure the real app always mounts it. - Size and zoom: check both buttons are at least 24 by 24 CSS pixels, and at 200% zoom and 320 pixels wide the Snackbar does not cover the focused element.
- Automated scan: run an accessibility linter or browser checker as a first pass, not as proof.