---
name: accessibility-compliance
description: Implement WCAG 2.1 AA accessibility compliance with ARIA labels, keyboard navigation, screen reader support, and color contrast. Use when ensuring accessibility or fixing a11y issues.
allowed-tools: Read, Write, Edit, Bash, Glob
---
You implement WCAG 2.1 AA accessibility compliance for the QA Team Portal.
## Requirements from PROJECT_PLAN.md
- **Standard:** WCAG 2.1 AA compliance
- Keyboard navigation support
- Screen reader compatibility
- Color contrast standards (4.5:1 for text)
- ARIA labels on interactive elements
- Focus indicators visible
- Accessible forms and error messages
## WCAG 2.1 AA Requirements
### Perceivable
1. Text alternatives for non-text content
2. Captions for audio/video
3. Content can be presented in different ways
4. Color contrast minimum 4.5:1 (text), 3:1 (large text, UI components)
### Operable
1. Keyboard accessible (all functionality)
2. Enough time to read/use content
3. No content that causes seizures (flashing < 3 times per second)
4. Navigation and finding content
### Understandable
1. Readable and understandable text
2. Predictable operation
3. Input assistance (labels, error messages)
### Robust
1. Compatible with assistive technologies
2. Valid HTML
3. Name, role, value for UI components
## Implementation
### 1. Semantic HTML
**Use proper HTML5 elements:**
```typescript
// ❌ Wrong: Divs for everything
Click me
Home
About
// ✅ Correct: Semantic elements
// ✅ Proper document structure
)
}
```
### 10. Screen Reader Only Text
```css
/* frontend/src/index.css */
/* Screen reader only class */
.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;
}
/* Show on focus (for skip links) */
.sr-only:focus {
position: static;
width: auto;
height: auto;
padding: initial;
margin: initial;
overflow: visible;
clip: auto;
white-space: normal;
}
```
```typescript
// Usage
Current page
```
## Accessibility Testing
### 1. Automated Testing with axe-core
```bash
cd frontend
npm install -D @axe-core/playwright
```
```python
# tests/e2e/test_accessibility.py
from axe_playwright_python import Axe
def test_homepage_accessibility(page):
"""Test homepage accessibility."""
page.goto('http://localhost:5173')
# Run axe accessibility scan
axe = Axe()
results = axe.run(page)
violations = results['violations']
if violations:
print(f"\nFound {len(violations)} accessibility violations:\n")
for violation in violations:
print(f"❌ {violation['id']}: {violation['description']}")
print(f" Impact: {violation['impact']}")
print(f" Help: {violation['helpUrl']}")
print(f" Affected nodes: {len(violation['nodes'])}\n")
# Assert no violations
assert len(violations) == 0, f"Found {len(violations)} accessibility violations"
def test_admin_login_accessibility(page):
"""Test login form accessibility."""
page.goto('http://localhost:5173/admin/login')
axe = Axe()
results = axe.run(page)
assert len(results['violations']) == 0
```
### 2. Keyboard Navigation Testing
```python
# tests/e2e/test_keyboard_navigation.py
def test_keyboard_navigation(page):
"""Test keyboard navigation through the page."""
page.goto('http://localhost:5173')
# Start from top
page.keyboard.press('Tab')
# Should focus skip link first
expect(page.locator('.skip-to-content')).to_be_focused()
# Tab through navigation
page.keyboard.press('Tab')
expect(page.locator('nav a:nth-child(1)')).to_be_focused()
# Test Enter key activation
page.keyboard.press('Enter')
# Should navigate
def test_modal_focus_trap(page):
"""Test focus is trapped inside modal."""
page.goto('http://localhost:5173/admin/team-members')
# Open modal
page.click('button:has-text("Add Team Member")')
# Tab through all focusable elements
# Last Tab should cycle back to first element
for _ in range(10):
page.keyboard.press('Tab')
# Focus should still be inside modal
assert page.locator('[role="dialog"]').evaluate('el => el.contains(document.activeElement)')
# Escape should close modal
page.keyboard.press('Escape')
expect(page.locator('[role="dialog"]')).not_to_be_visible()
```
### 3. Screen Reader Testing
**Test with actual screen readers:**
- **macOS:** VoiceOver (Cmd+F5)
- **Windows:** NVDA (free), JAWS (paid)
- **Linux:** Orca
**Test checklist:**
- [ ] All images have appropriate alt text
- [ ] All form inputs have labels
- [ ] Error messages are announced
- [ ] Dynamic content changes are announced (aria-live)
- [ ] Headings structure is logical
- [ ] Landmarks are properly identified (header, nav, main, footer)
- [ ] Lists are properly marked up
### 4. Color Contrast Testing
```bash
# Install contrast checker
npm install -D axe-core
# Run contrast check
npx axe http://localhost:5173 --rules=color-contrast
```
## WCAG 2.1 AA Checklist
### Perceivable
- [ ] All images have alt text
- [ ] Videos have captions (if applicable)
- [ ] Color is not the only means of conveying information
- [ ] Text contrast >= 4.5:1 (normal), >= 3:1 (large text 18pt+)
- [ ] Text can be resized to 200% without loss of content
- [ ] Images of text avoided (use real text)
### Operable
- [ ] All functionality available via keyboard
- [ ] No keyboard trap
- [ ] Skip to main content link present
- [ ] Page titles are descriptive
- [ ] Link purpose clear from link text or context
- [ ] Multiple ways to find pages (navigation, search, sitemap)
- [ ] Headings and labels are descriptive
- [ ] Focus indicator visible
- [ ] No time limits (or user can extend)
- [ ] No content flashing more than 3 times per second
### Understandable
- [ ] Language of page declared (html lang="en")
- [ ] Language of parts declared if different
- [ ] Navigation is consistent across pages
- [ ] Labels or instructions provided for user input
- [ ] Error messages are clear and helpful
- [ ] Error prevention for important actions (confirmation)
- [ ] Form fields have visible labels
- [ ] Required fields are indicated
### Robust
- [ ] HTML validates (use W3C validator)
- [ ] Name, role, value available for all UI components
- [ ] Status messages programmatically determinable (aria-live)
- [ ] Works with assistive technologies
## Accessibility Resources
**Tools:**
- **axe DevTools:** Browser extension for accessibility testing
- **Lighthouse:** Built into Chrome DevTools
- **WAVE:** Web accessibility evaluation tool
- **Color Contrast Analyzer:** Check color combinations
- **Screen readers:** NVDA (Windows), VoiceOver (macOS), JAWS (Windows)
**Documentation:**
- WCAG 2.1: https://www.w3.org/WAI/WCAG21/quickref/
- ARIA Authoring Practices: https://www.w3.org/WAI/ARIA/apg/
- MDN Accessibility: https://developer.mozilla.org/en-US/docs/Web/Accessibility
## Report
✅ WCAG 2.1 AA compliance achieved
✅ All images have descriptive alt text
✅ Semantic HTML used throughout
✅ ARIA labels added to interactive elements
✅ Keyboard navigation fully functional
✅ Focus indicators visible and clear
✅ Color contrast meets 4.5:1 minimum
✅ Forms fully accessible with proper labels
✅ Screen reader tested (VoiceOver/NVDA)
✅ Skip to content link implemented
✅ No accessibility violations found (axe-core)
✅ Automated tests passing