Accessibility Features in Action
The dnd-kit Accessibility plugin automatically enhances drag and drop interfaces with comprehensive keyboard support, screen reader announcements, and ARIA attributes. This guide demonstrates how to leverage these features.The Accessibility Plugin
The Accessibility plugin provides:- Automatic ARIA attributes for draggable elements
- Live region announcements for screen readers
- Hidden text instructions for keyboard users
- Proper focus management
- Debounced updates to prevent announcement spam
Basic Setup
packages/dom/src/core/plugins/accessibility/Accessibility.ts
Default Screen Reader Instructions
The plugin provides default instructions that are read to screen reader users:packages/dom/src/core/plugins/accessibility/defaults.ts
Custom Screen Reader Instructions
Provide custom instructions tailored to your interface:Custom Announcements
The plugin announces key events to screen readers. Customize these announcements:packages/dom/src/core/plugins/accessibility/defaults.ts
Automatic ARIA Attributes
The Accessibility plugin automatically adds and manages these attributes:packages/dom/src/core/plugins/accessibility/defaults.ts
Example: Accessible Sortable List
Debouncing Announcements
By default,dragover and dragmove events are debounced to prevent overwhelming screen readers:
packages/dom/src/core/plugins/accessibility/Accessibility.ts
Example: Accessible Kanban Board
Custom ID Prefixes
Customize the IDs used for accessibility elements:packages/dom/src/core/plugins/accessibility/Accessibility.ts
Best Practices
-
Provide meaningful labels: Use
aria-labelon draggable elements to give them descriptive names. - Include context in announcements: Tell users where items are and where they’re going, not just what’s happening.
- Test with real screen readers: Test with NVDA, JAWS, or VoiceOver to ensure announcements are clear.
- Keep announcements concise: Screen reader users appreciate brevity.
- Use the KeyboardSensor: Always include the KeyboardSensor for keyboard-only users.
- Test keyboard navigation: Ensure all functionality works with keyboard alone.
- Provide visual focus indicators: CSS focus styles are critical for keyboard users.
- Consider announcement frequency: Use the debounce option to prevent overwhelming users during rapid movements.
Safari Compatibility
The plugin automatically handles Safari’s unique requirements, ensuring elements are properly focusable even in Safari.Live Region Implementation
The plugin creates a visually hidden live region for announcements:packages/dom/src/core/plugins/accessibility/Accessibility.ts