This React Accordion component demonstrates a fully accessible, keyboard-navigable UI component that allows users to expand and collapse content sections dynamically.
- 🌟 Single accordion open at a time
- ♿ Full keyboard support
- 🔍 WCAG accessibility compliance
- 🎨 Responsive and smooth transitions
- 🧩 Modular component design
Many UI components misuse HTML elements, breaking accessibility standards.
- Used semantic
<button>for interactions instead of<div> - Implemented proper ARIA attributes to convey component state
- Ensured keyboard operability for all interactions
Dynamically showing/hiding content while maintaining proper screen reader context.
- Implemented
aria-expandedattribute to indicate current state - Used
aria-hiddento explicitly control content visibility - Added
aria-controlsto link trigger buttons with content regions
Ensuring full keyboard accessibility without mouse interaction.
- Added
tabIndex={0}to focusable elements - Implemented focus management with
useRefanduseEffect - Created keyboard-friendly toggle mechanism
Automatically focusing newly revealed content for screen reader users.
- Used
useEffectto focus content when expanded - Added
role="region"for proper screen reader announcement - Implemented
aria-labelledbyfor contextual linking
The accordion is composed of four key components:
-
Parent Wrapper (
App.js):- Manages global accordion state
- Controls which accordion is currently expanded
- Maps accordion data to individual components
-
Accordion Component (
Accordion.js):- Renders individual accordion sections
- Handles local interaction and accessibility attributes
- Receives expansion state from parent
-
Heading Button:
- Triggers content expansion
- Provides visual and semantic state indication
- Manages ARIA attributes for accessibility
-
Content Region:
- Dynamically shows/hides based on state
- Ensures proper focus and screen reader behavior
.app-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}- Smooth max-height transitions
- Opacity animations for content
- Rotational icon indicator
aria-expanded: Indicates current open/closed statearia-hidden: Controls element visibilityaria-controls: Links trigger and content elementsaria-labelledby: Provides contextual labelingrole="region": Defines content section for assistive technologies