--- name: a11y description: Accessibility audit and patterns - WCAG 2.1 AA compliance for React apps. triggers: - a11y - accessibility - wcag - screen reader allowed-tools: Bash, Read, Grep, Glob model: opus user-invocable: true --- # Accessibility (WCAG 2.1 AA) ## Quick Audit ```bash # Automated checks (catches ~30% of issues) npx axe-core-cli http://localhost:3000 # Or in browser console # Install axe DevTools extension → run scan ``` **Automated tools catch 30%. Manual testing catches the rest.** ## Critical Checklist ### 1. Keyboard Navigation (Most Common Failure) ```tsx // ❌ Bad - click-only interaction
Click me
// ✅ Good - keyboard accessible // ✅ Good - custom element with keyboard support
{ if (e.key === 'Enter' || e.key === ' ') handleClick() }} > Click me
``` **Test:** Tab through entire page. Can you reach and activate everything? ### 2. Focus Management ```tsx // Dialog: trap focus inside, return on close { if (!open) triggerRef.current?.focus() }}> // Page navigation: focus main content useEffect(() => { document.getElementById('main-content')?.focus() }, [pathname]) // Skip link (first element in body) Skip to main content ``` ### 3. Color Contrast | Element | Minimum Ratio | Enhanced | |---------|---------------|----------| | Normal text | 4.5:1 | 7:1 | | Large text (18px+) | 3:1 | 4.5:1 | | UI components | 3:1 | - | ```tsx // ❌ Bad - low contrast

Light text on white

// ✅ Good - use semantic tokens with proper contrast

Accessible muted text

``` ### 4. Images and Media ```tsx // ❌ Bad // ✅ Good - descriptive alt Artist profile photo of Luna performing on stage // ✅ Good - decorative (skip by screen reader) // Audio/Video: always provide captions