Accordion

Details about our Accordion component and how to use it.

  • Makes use of react-aria-components under the hood, see here. It specifically uses the <DisclosureGroup />, <DisclosureStateContext /> and <Disclosure /> components.
  • Meets accessibility standards.
  • Supports expanding one item at a time by default.
  • Supports allowing multiple expanded items at the same time.
  • Supports being fully controlled by the parent component.

One expanded item at a time

That's a really great question! We offer a 30-day return policy for all products.

Go to our FAQ-Section.

Yes, we provide comprehensive customer support through multiple channels including email, live chat, and phone support during business hours (9 AM - 6 PM EST, Monday through Friday). Our support team is trained to help with product questions, technical issues, and order inquiries.

<AccordionGroup>
  <Accordion>
    <AccordionHeader>What is the return policy</AccordionHeader>
    <AccordionPanel>
      <p>...</p>
    </AccordionPanel>
  </Accordion>
  <Accordion>
    <AccordionHeader>Do you offer customer support?</AccordionHeader>
    <AccordionPanel>
      <p>...</p>
    </AccordionPanel>
  </Accordion>
</AccordionGroup>

Multiple expanded items at a time

  • You can allow multiple accordion items to be expanded at the same time by setting the allowsMultipleExpanded prop on the AccordionGroup component.

We offer a 30-day return policy for all products.

Yes, we provide comprehensive customer support through multiple channels including email, live chat, and phone support during business hours (9 AM - 6 PM EST, Monday through Friday). Our support team is trained to help with product questions, technical issues, and order inquiries.

<AccordionGroup allowsMultipleExpanded>...</AccordionGroup>

Controlled accordion

  • You can control the expanded state of the accordion items by using the expandedItems and onExpandedItemsChange props on the AccordionGroup component.
  • By adding an id prop to each Accordion component, you can specify which items are expanded by default and control the expanded state programmatically.

We offer a 30-day return policy for all products.

Yes, we provide comprehensive customer support through multiple channels including email, live chat, and phone support during business hours (9 AM - 6 PM EST, Monday through Friday). Our support team is trained to help with product questions, technical issues, and order inquiries.

Standard shipping typically takes 3-5 business days within the continental United States. Express shipping options are available for 1-2 day delivery. International shipping times vary by destination but generally take 7-14 business days. You will receive a tracking number via email once your order has been processed and shipped.

const [expandedKeys, setExpandedKeys] = useState(
    () => new Set<AccordionKey>(['accordion-1']),
  );
 
  return (
    <AccordionGroup
      expandedKeys={expandedKeys}
      onExpandedChange={setExpandedKeys}
    >
      <Accordion id="accordion-1">
        <AccordionHeader>What is the return policy</AccordionHeader>
        <AccordionPanel>
          <p>...</p>
        </AccordionPanel>
      </Accordion>
      <Accordion id="accordion-2">
        <AccordionHeader>Do you offer customer support?</AccordionHeader>
        <AccordionPanel>
          <p>...</p>
        </AccordionPanel>
      </Accordion>
      <Accordion id="accordion-3">
        <AccordionHeader>How long does shipping take</AccordionHeader>
        <AccordionPanel>
          <p>...</p>
        </AccordionPanel>
      </Accordion>
    </AccordionGroup>
  );

Requirements

The following libraries need to be installed:

3rd Party Librariesversion
react-aria-components^1.14.0

The following folder need to be copied to your project:

Copy to projectReason
ui/components/accordion/Accordion components and hooks
ui/primatives/disclosure/The accordion uses the disclosure primitive
ui/hooks/use-resize-observer.tsUses to track the height of the accordion panel for animation

Components

<AccordionGroup />

The <AccordionGroup /> component is the parent component that wraps around all Accordion components. It is based on the <AriaDisclosureGroup /> component from react-aria-components.

Props
PropTypeDescription
allowsMultipleExpandedbooleanAllows multiple accordion items to be expanded at the same time
expandedKeysSet<AccordionKey>A set of accordion item keys that are currently expanded. This is used to control the expanded state of the accordion items.
onExpandedChangefunctionA callback function that is called when the expanded state of the accordion items changes. It receives the new set of expanded item keys as an argument.

<Accordion />

The <Accordion /> component represents a single accordion item.

  • It should be wrapped inside an AccordionGroup component.
  • It is based on the <AriaDisclosure /> component from react-aria-components.
Props
PropTypeDescription
idstringA unique identifier for the accordion item. This is used to control the expanded state of the accordion item when using a controlled accordion.

<AccordionHeader />

The <AccordionHeader /> component represents the header of the accordion item.

  • It should be wrapped inside an Accordion component.
  • It is the element that the user clicks on to expand or collapse the accordion item.
  • It makes use of a custom <DisclosureHeader /> component, which gives it an id to link it to the corresponding AccordionPanel for accessibility purposes.
  • It also uses the <DisclosureTrigger /> component, which uses the <Button /> component from react-aria-components to toggle the expanded state of the accordion item.
  • Here you can change the icon of the accordion.
Props
PropTypeDescription
@extendsComponentProps<'h3'>All props from the <h3> element are accepted.

<AccordionPanel />

The <AccordionPanel /> component represents the content panel of the accordion item.

  • It should be wrapped inside an Accordion component.
  • It is shown or hidden based on the expanded state of the accordion item.
  • It makes use of a custom <DisclosurePanel /> component, which gives it an aria-labelledby attribute to link it to the corresponding AccordionHeader for accessibility purposes.
Props
PropTypeDescription
@extendsComponentProps<'section'>All props from the <section> element are accepted.
Data attributes
Data attributeTypeDescription
data-state'open' | 'closed'The state of the accordion panel.