Core Accessibility Features
Lexical includes:- ARIA Support: Proper ARIA roles and attributes
- Keyboard Navigation: Full keyboard control
- Screen Reader Support: Compatible with major screen readers
- Focus Management: Proper focus handling
- Semantic HTML: Uses semantic elements when possible
ContentEditable Setup
TheContentEditable component handles basic accessibility:
Required Attributes
aria-label: Describes the editor’s purposerole="textbox": Identifies the editor’s rolearia-multiline="true": Indicates multi-line input (automatically set)
ARIA Labels
<div>
<label id="editor-label" htmlFor="editor">
Article Content
</label>
<p id="editor-description">
Write your article content here. Use Markdown syntax for formatting.
</p>
<ContentEditable
id="editor"
aria-labelledby="editor-label"
aria-describedby="editor-description"
className="editor-input"
/>
</div>
function Editor() {
const [characterCount, setCharacterCount] = useState(0);
const maxCharacters = 500;
return (
<div>
<ContentEditable
aria-label="Comment"
aria-describedby="char-count"
aria-invalid={characterCount > maxCharacters}
className="editor-input"
/>
<div id="char-count" role="status" aria-live="polite">
{characterCount} / {maxCharacters} characters
</div>
</div>
);
}
Keyboard Navigation
Lexical supports all standard keyboard shortcuts:Text Editing
- Arrow Keys: Navigate through text
- Home/End: Move to start/end of line
- Ctrl/Cmd + Home/End: Move to start/end of document
- Shift + Arrows: Select text
- Ctrl/Cmd + A: Select all
- Backspace/Delete: Delete characters
- Ctrl/Cmd + Backspace/Delete: Delete words
Formatting (Rich Text)
- Ctrl/Cmd + B: Bold
- Ctrl/Cmd + I: Italic
- Ctrl/Cmd + U: Underline
- Ctrl/Cmd + K: Insert link
History
- Ctrl/Cmd + Z: Undo
- Ctrl/Cmd + Shift + Z: Redo (or Ctrl + Y on Windows)
Lists
- Tab: Indent list item
- Shift + Tab: Outdent list item
- Enter: New list item
- Backspace (at start): Exit list
Custom Keyboard Shortcuts
Add accessible keyboard shortcuts:Screen Reader Support
Live Regions
Use live regions for dynamic content:Screen Reader Only Content
Announce Actions
Focus Management
Auto Focus
Programmatic Focus
Focus Trap
For modal editors:Toolbar Accessibility
Button Labels
Toolbar Navigation
Form Integration
Label Association
Validation Messages
Color Contrast
Ensure sufficient contrast:Error Handling
Accessible error messages:Testing Accessibility
Automated Testing
Manual Testing
- Keyboard Only: Navigate without a mouse
- Screen Reader: Test with NVDA, JAWS, or VoiceOver
- Zoom: Test at 200% zoom level
- High Contrast: Test with high contrast mode enabled
- Color Blindness: Verify color is not the only indicator
Best Practices
- Always provide
aria-labeloraria-labelledbyfor ContentEditable - Use semantic HTML when possible (headings, lists, etc.)
- Ensure keyboard navigation works for all functionality
- Test with screen readers regularly during development
- Provide text alternatives for images and decorative content
- Use
role="status"for non-critical announcements - Use
role="alert"for important/error messages - Maintain focus visibility with clear focus indicators
- Support high contrast mode and respects user preferences
- Document keyboard shortcuts in help documentation
WCAG Compliance
Follow WCAG 2.1 Level AA guidelines:- Perceivable: Provide text alternatives, sufficient contrast
- Operable: Keyboard accessible, enough time to read
- Understandable: Predictable, clear error messages
- Robust: Compatible with assistive technologies
Resources
See Also
- API Reference: ContentEditable
- API Reference: React Plugins
- Examples:
packages/lexical-playground/src/