Accordion

React Accordion components let users show and hide sections of related content on a page. They are often used for FAQs, menus and submenus, settings panels, and other layouts where content needs to stay organized.

This Accordion component is styled using Tailwind CSS, giving developers control over structure, layout, and styling.

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli@latest add accordion

Anatomy

Import the component parts and combine them.

import {
  Accordion,
  AccordionItem,
  AccordionTrigger,
  AccordionContent
} from "@/components/tailgrids/accordion";

export const AccordionExample = () => (
  <Accordion>
    <AccordionItem>
      <AccordionTrigger />
      <AccordionContent />
    </AccordionItem>
  </Accordion>
);

Examples

Style One (Default)

This is the default style for the accordion. No variant prop is required.

Style Two

Set variant="style_two" on Accordion for this visual style.

Style Three

Set variant="style_three" on Accordion for this variation.

Style Four

Set variant="style_four" on Accordion for this layout.

Style Five

Set variant="style_five" on Accordion for this design.

Custom

Use className to give a custom look to the component.

API Reference

Accordion

Wraps all accordion items and controls the overall layout and style. Extends React Aria's DisclosureGroup props.

PropTypeDefaultDescription
variant'style_one' | 'style_two' | 'style_three' | 'style_four' | 'style_five''style_one'Tailgrids-only visual style for the accordion
allowsMultipleExpandedbooleanfalseAllow more than one item to be expanded at once
defaultExpandedKeysIterable<Key>-Item ids expanded initially (uncontrolled)
expandedKeysIterable<Key>-Controlled set of expanded item ids
onExpandedChange(keys: Set<Key>) => void-Called when the expanded items change
classNamestring-Additional CSS classes
childrenReact.ReactNode-Accordion items

AccordionItem

A single accordion item that groups a trigger and its content. Extends React Aria's Disclosure props; give each item an id when using defaultExpandedKeys or expandedKeys.

PropTypeDescription
idKeyUnique item identifier
classNamestringAdditional CSS classes
childrenReact.ReactNodeTrigger and content components
Data AttributeValuesDescription
data-expandedbooleanIndicates whether the item is expanded or collapsed.

AccordionTrigger

Toggles the visibility of the accordion content. Renders a semantic heading wrapping a React Aria button with slot="trigger". Extends React Aria's Button props.

PropTypeDefaultDescription
level1 | 2 | 3 | 4 | 5 | 63Heading level rendered around the trigger
classNamestring-Additional CSS classes
childrenReact.ReactNode-Trigger content (typically text)
Data AttributeValuesDescription
data-expandedbooleanIndicates whether the item is expanded or collapsed.

AccordionContent

Holds the collapsible content for an accordion item. Maps to React Aria's DisclosurePanel.

PropTypeDescription
classNamestringAdditional CSS classes
childrenReact.ReactNodeContent to display when expanded
Data AttributeValuesDescription
data-expandedbooleanIndicates whether the item is expanded or collapsed.

Accessibility

  • Built on React Aria's DisclosureGroup, Disclosure and DisclosurePanel, which manage aria-expanded, aria-controls and aria-labelledby
  • Uses a semantic heading structure (h3 by default) around each trigger
  • Supports keyboard interaction with visible focus rings
  • Associates each trigger with its content using React Aria's disclosure relationships
  • data-expanded on items, triggers and panels can be used for styling