Review status announcements and contrast
Communicate updates without stealing focus
A status message tells the user the outcome of an action without requiring a focus change. A persistent role="status" region is appropriate for nonurgent updates; role="alert" is for important, time-sensitive messages and can interrupt current speech. Insert the changing text into an already mounted region rather than expecting every newly mounted live region to announce reliably. Avoid sending a message for every keystroke or combining multiple competing announcements. For form errors, show text next to fields and consider a focusable summary when submission fails. Do not convey error or success only with color. Screen reader announcements require manual testing.
import React,{useEffect,useId,useRef,useState} from 'react';export default function TrailRequest(){ const id=useId(),summary=useRef(null),[name,setName]=useState(''),[error,setError]=useState(''),[status,setStatus]=useState(''),[invalidAttempt,setInvalidAttempt]=useState(0); useEffect(()=>{if(invalidAttempt>0)summary.current?.focus();},[invalidAttempt]); function submit(e){e.preventDefault();if(!name.trim()){setError('Enter a trail name.');setStatus('');setInvalidAttempt(n=>n+1);return;}setError('');setStatus('Trail request saved locally.');} return <form noValidate onSubmit={submit}> <div ref={summary} tabIndex={-1} aria-label="Submission result">{error&&<p>Request not saved: enter a trail name below.</p>}</div> <label htmlFor={id}>Trail name</label><input id={id} required value={name} onChange={e=>{setName(e.target.value);setError('');setStatus('');}} aria-invalid={Boolean(error)} aria-describedby={error?id+'-error':undefined}/> {error&&<p id={id+'-error'}>{error}</p>} <button type="submit">Save request</button><p role="status">{status}</p> </form>;}On invalid submission the field gets an associated error and a new invalidAttempt token. The Effect focuses the summary after React commits the updated text; repeated invalid submits also trigger the policy. The summary remains mounted and receives no normal Tab stop. On valid submission, the persistent status region receives a success message without stealing focus. The example uses a local message, not a server confirmation. In production also validate and authorize on the server. Test repeated failures and success with a real screen reader: updating the DOM is not proof of an announcement.
Calculate text contrast with the correct color space
export function luminance(hex){ if(!/^#[0-9a-f]{6}$/i.test(hex))throw new TypeError('Expected #RRGGBB'); const channels=[1,3,5].map(i=>parseInt(hex.slice(i,i+2),16)/255).map(v=>v<=0.04045?v/12.92:((v+0.055)/1.055)**2.4); return channels[0]*0.2126+channels[1]*0.7152+channels[2]*0.0722;}export function contrast(a,b){const x=luminance(a),y=luminance(b);return (Math.max(x,y)+0.05)/(Math.min(x,y)+0.05);}White against black is 21:1; identical colors are 1:1. WCAG 2.2 AA sets a minimum 4.5:1 for ordinary text and 3:1 for large text (at least 18 point regular or 14 point bold, or equivalent). Non-text contrast has separate requirements, generally 3:1 for necessary control/state visuals against adjacent colors, with exceptions. Do not round a failing value up to the threshold. This helper covers opaque sRGB only, not opacity, gradients, images or composited backgrounds. Measure the actual colors for default, focus, hover and error states. Decorative elements and inactive controls have specific exceptions; do not assume muted placeholder text is exempt.
Review layout, target size and motion together
import React,{useState} from 'react';import './trail.css';export default function TrailActions(){const [chosen,setChosen]=useState(false);return <section className="trail-actions"><h2>Plan a walk</h2><p>Choose an accessible route and review terrain notes.</p><div className="trail-buttons"><button type="button" aria-pressed={chosen} onClick={()=>setChosen(v=>!v)}>Choose route</button><a href="#terrain">Read terrain notes</a></div><p id="terrain">Gravel surface; check conditions before leaving.</p></section>;}The companion trail.css sets a visible focus outline, a 44 CSS pixel minimum control size, flexible wrapping, logical spacing and a reduced-motion override. WCAG 2.2 AA target size criterion 2.5.8 generally calls for at least 24 by 24 CSS pixels or qualifying exceptions including spacing; 44 is a chosen usability target, not a universal AA requirement. Test reflow at a 320 CSS pixel viewport and text resizing to 200% without losing content; some essential two-dimensional content has exceptions. Check focus is not fully obscured by sticky UI. Respect reduced motion as a usability practice; avoid claiming all animation-related criteria are AA. Automated tools such as axe can find certain violations but cannot prove accessibility. Manually inspect reading order, visible focus, error recovery, screen reader names and live messages in actual supported environments. Keep an issue log with reproduction steps, expected behavior, criterion and observed evidence.