React Accessible Accordion

5.0.1 · abandoned · verified Sun Apr 19

react-accessible-accordion is a React component library providing a WAI-ARIA compliant accordion interface. The current stable version is 5.0.1. While it provides robust accessibility features for accordions, the project is officially no longer maintained, with the developers strongly recommending the use of native HTML `<details>` and `<summary>` elements for new implementations due to their superior performance, framework-agnostic nature, and built-in accessibility. Releases have been infrequent, primarily addressing bug fixes or adapting to new React versions, rather than active feature development. Key differentiators historically included its out-of-the-box WAI-ARIA compliance and a component-based API for building accordions within React applications, but these are now largely superseded by native browser capabilities. It ships with TypeScript types for improved developer experience.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic accessible accordion with two expandable items, using named imports for components and an optional demo stylesheet. It also explicitly shows `uuid` for consistent IDs, although often automatically generated.

import React from 'react';
import {
    Accordion,
    AccordionItem,
    AccordionItemHeading,
    AccordionItemButton,
    AccordionItemPanel,
} from 'react-accessible-accordion';

// Optional: Import demo styles, or create your own.
import 'react-accessible-accordion/dist/fancy-example.css';

export default function BasicAccordionExample() {
    // Configure accordion behavior with props like allowMultipleExpanded and allowZeroExpanded
    return (
        <Accordion allowZeroExpanded>
            <AccordionItem uuid="item-1">
                <AccordionItemHeading>
                    <AccordionItemButton>
                        What is React?
                    </AccordionItemButton>
                </AccordionItemHeading>
                <AccordionItemPanel>
                    <p>
                        React is a free and open-source front-end JavaScript library for building user interfaces based on UI components.
                    </p>
                </AccordionItemPanel>
            </AccordionItem>
            <AccordionItem uuid="item-2">
                <AccordionItemHeading>
                    <AccordionItemButton>
                        Why use an accessible accordion?
                    </AccordionItemButton>
                </AccordionItemHeading>
                <AccordionItemPanel>
                    <p>
                        Accessible accordions ensure that all users, including those using assistive technologies, can easily navigate and interact with collapsed and expanded content.
                    </p>
                </AccordionItemPanel>
            </AccordionItem>
        </Accordion>
    );
}

view raw JSON →