Docs
Components
Accordion

Accordion

Key Features

  1. Context API for State Management:
    • AccordionRoot uses React Context to manage the active accordion item's state.
  2. Accessibility:
    • Implements aria-expanded, aria-controls, aria-labelledby, and role="region" to ensure screen readers can navigate the accordion.
  3. Flexible Styling:
    • Accepts className props for customizing the appearance of each component.

Notes:

  • This implementation is highly modular, making it reusable across different parts of a project.
  • The headless design allows for maximum flexibility in styling and customization.

Example

Accordion

Props

AccordionRoot

PropTypeDescriptionRequired
classNamestringAdditional CSS class names for styling the root accordion container.No
childrenReact.ReactNodeThe child components, typically AccordionItem components.Yes

Functionality:

  • Manages the state of the active accordion item (activeId).
  • Provides a toggleActiveId function to open/close accordion items.

AccordionItem

PropTypeDescriptionRequired
classNamestringAdditional CSS class names for styling the accordion item container.No
childrenReact.ReactNodeThe child components, typically AccordionTrigger and AccordionContent.Yes

Functionality:

  • Wraps the AccordionTrigger and AccordionContent components for a single accordion item.
  • Provides contextual information about the item (IDs and state).

AccordionTrigger

PropTypeDescriptionRequired
classNamestringAdditional CSS class names for styling the trigger (button).No
childrenReact.ReactNodeThe trigger content, typically text or icons.Yes

Functionality:

  • Toggles the accordion item's state between "open" and "closed."
  • Uses aria-controls and aria-expanded for accessibility.
  • Automatically updates the active item in AccordionRoot.

AccordionContent

PropTypeDescriptionRequired
classNamestringAdditional CSS class names for styling the content container.No
childrenReact.ReactNodeThe content to display when the accordion item is open.Yes

Functionality:

  • Displays or hides content based on the current state (open or closed).
  • Uses role="region" and aria-labelledby for accessibility.