# Accessibility & Inclusive Design Patterns Comprehensive accessibility patterns following WCAG 2.2 guidelines and ARIA best practices. ## WCAG 2.2 Principles (POUR) ### Perceivable Information and UI components must be presentable to users in ways they can perceive. ### Operable UI components and navigation must be operable. ### Understandable Information and operation of UI must be understandable. ### Robust Content must be robust enough to be interpreted by various user agents, including assistive technologies. ## Semantic HTML ```html
  • Home
  • About

Page Title

Content...

Related Articles

© 2024 Company Name

Home
``` ## ARIA Attributes ### Landmarks ```html
``` ### Live Regions ```html
Error: Please correct the form errors.
5 new messages
Item added to cart
``` ### Form Accessibility ```html We'll never share your email
Contact Preferences
Subscription Type
``` ## Keyboard Navigation ```typescript // React component with keyboard support function DropdownMenu({ items }) { const [isOpen, setIsOpen] = useState(false); const [focusedIndex, setFocusedIndex] = useState(0); const buttonRef = useRef(null); const menuRef = useRef(null); const handleKeyDown = (e: KeyboardEvent) => { switch (e.key) { case 'Enter': case ' ': e.preventDefault(); setIsOpen(!isOpen); break; case 'Escape': setIsOpen(false); buttonRef.current?.focus(); break; case 'ArrowDown': e.preventDefault(); if (!isOpen) { setIsOpen(true); } else { setFocusedIndex((prev) => (prev + 1) % items.length); } break; case 'ArrowUp': e.preventDefault(); if (isOpen) { setFocusedIndex((prev) => (prev - 1 + items.length) % items.length); } break; case 'Home': e.preventDefault(); setFocusedIndex(0); break; case 'End': e.preventDefault(); setFocusedIndex(items.length - 1); break; } }; return (
{isOpen && (
{items.map((item, index) => ( ))}
)}
); } ``` ## Focus Management ```typescript // Trap focus in modal function Modal({ isOpen, onClose, children }) { const modalRef = useRef(null); useEffect(() => { if (!isOpen) return; const modal = modalRef.current; if (!modal) return; const focusableElements = modal.querySelectorAll( 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])' ); const firstElement = focusableElements[0] as HTMLElement; const lastElement = focusableElements[focusableElements.length - 1] as HTMLElement; // Focus first element firstElement?.focus(); const handleTabKey = (e: KeyboardEvent) => { if (e.key !== 'Tab') return; if (e.shiftKey) { // Shift + Tab if (document.activeElement === firstElement) { e.preventDefault(); lastElement?.focus(); } } else { // Tab if (document.activeElement === lastElement) { e.preventDefault(); firstElement?.focus(); } } }; modal.addEventListener('keydown', handleTabKey); return () => { modal.removeEventListener('keydown', handleTabKey); }; }, [isOpen]); if (!isOpen) return null; return (

Modal Title

{children}
); } ``` ## Color Contrast ```css /* WCAG AA requires 4.5:1 for normal text, 3:1 for large text */ /* WCAG AAA requires 7:1 for normal text, 4.5:1 for large text */ .button-primary { /* Good contrast: 7.2:1 */ background: #0066cc; color: #ffffff; } .button-secondary { /* Good contrast: 4.6:1 */ background: #f0f0f0; color: #333333; } /* Don't rely on color alone */ .error { color: #cc0000; } .error::before { content: '⚠ '; /* Visual indicator */ } .error[aria-invalid="true"] { /* Also announced to screen readers */ } ``` ## Skip Links ```html Skip to main content ``` ## Images and Alt Text ```html Sales increased by 25% in Q4 2024
Detailed sales data
Chart description

Detailed text description of the chart data...

``` ## Screen Reader-Only Content ```css .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0; } .sr-only-focusable:focus { position: static; width: auto; height: auto; overflow: visible; clip: auto; white-space: normal; } ``` ```html ``` ## Responsive and Touch-Friendly ```css /* Minimum touch target size: 44x44px */ button, a { min-height: 44px; min-width: 44px; padding: 12px 24px; } /* Ensure adequate spacing */ .button-group button { margin: 4px; } ``` ## Headings Hierarchy ```html

Page Title

Section 1

Subsection 1.1

Subsection 1.2

Section 2

Page Title

Section

``` ## Tables ```html
Monthly Sales Report
Month Sales Growth
January $10,000 +5%
``` ## Loading States ```typescript function DataList() { const { data, isLoading } = useQuery('data'); if (isLoading) { return (
Loading data...
); } return (
{data.map(item => )}
); } ``` ## Testing Accessibility ### Automated Testing ```typescript import { axe, toHaveNoViolations } from 'jest-axe'; expect.extend(toHaveNoViolations); test('page has no accessibility violations', async () => { const { container } = render(); const results = await axe(container); expect(results).toHaveNoViolations(); }); ``` ### Manual Testing Checklist - [ ] Keyboard navigation works - [ ] Screen reader announces correctly - [ ] Color contrast meets WCAG AA - [ ] Forms have proper labels - [ ] Images have alt text - [ ] Headings are hierarchical - [ ] Focus indicators are visible - [ ] Touch targets are adequate - [ ] No color-only information - [ ] Text can be resized to 200% ## Reduced Motion ```css @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; } } ``` ```typescript function AnimatedComponent() { const prefersReducedMotion = useMediaQuery('(prefers-reduced-motion: reduce)'); return ( Content ); } ``` ## Best Practices 1. **Use semantic HTML** 2. **Provide text alternatives** 3. **Ensure keyboard accessibility** 4. **Maintain sufficient color contrast** 5. **Create logical heading structure** 6. **Label form inputs properly** 7. **Make focus indicators visible** 8. **Support screen readers** 9. **Test with real assistive technologies** 10. **Follow WCAG 2.2 guidelines**