<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

Accordion

A group of Collapsible components that open and close when pressed, showing or hiding content.
styleKeys: accordionscriptKeys: accordion

Use Accordion...

  • To present a large amount of content in a compact form.
  • To break down information into manageable sections, especially if the content is categorized.
  • To prevent information overload by allowing users to expand only the sections they are interested in.
  • For FAQs sections.

Don't use Accordion...

  • To display critical information. Use a Modal Dialog instead.
  • To present a small amount of content where the benefit of collapsing/expanding is minimal. Use a Card instead.
  • To navigate through the page. Use Tabs instead.

Multiple

In the React API, by default multiple Collapsibles can be expanded simultaneously.

In the Vanilla API, add the swan-accordion-multiple class to the element that has the swan-accordion class to enable this functionality.

The preview has been updated.

Single

In the React API, use single to ensure that only one Collapsible is expanded at any given time.

In the Vanilla API, by default only one Collapsible can be expanded at any given time.

The preview has been updated.

Accordions as List

Use the following HTML tags for when the Accordion is semantically a list:

  • In the React API, use purpose="list" on the Accordion.
  • In the Vanilla API, use a ul tag for the Accordion, and li tags for each Collapsible within it.

The preview has been updated.

Full bleed

Use fullBleed to remove the right padding of the content within every Collapsible component of the Accordion.

The preview has been updated.

Color Swatches

Use skin="color-swatches" to wrap a large set of Color Swatches to avoid making the content excessively tall.

The CollapsibleSummaryButton shows the total number of available swatches.

The preview has been updated.

Default expanded collapsibles

Use defaultExpandedCollapsibles to present certain Collapsibles as expanded by default.

The preview has been updated.

Managing state

Controlling the state of an Accordion is only necessary if there's a need to read or write its state from another component. This requirement is rather uncommon.

In the React API, use expandedCollapsibles on the Accordion to map the collapsibleIds to a boolean, indicating whether each Collapsible should be expanded or not.

Info:

If provided, expandedCollapsibles is treated as the source of truth, and overrides the single prop.

Use the onRequestExpandedChange prop on the Accordion to be notified when a Collapsible wants to expand or collapse. This handler is invoked with two arguments:

  • collapsibleId: to identify the Collapsible changing its state.
  • expanded: to indicate whether the Collapsible seeks to be expanded or not.

The preview has been updated.

Accessibility

Refer to Collapsible usage.

Content

Refer to Collapsible guidelines.

SEO

  • Ensure accordion content is part of the page's source HTML for effective crawling by Googlebot.
  • Coordinate with the Organic Search team for Googlebot crawling validation if the content is dynamically added through JavaScript.
  • Avoid important content in collapsed accordions: search engines, including Googlebot, can't see information that requires user interaction to view. For lengthy accordions, make sure at least one accordion is expanded by default.

Props

Accordion
This component is implemented using the <div /> as the root element. You can utilize the native attributes supported by <div /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
skinstring | nullfalse
The visual style of the Accordion. Available options: "standard", "color-swatches"
null
fullBleedboolean | nullfalse
Specifies if the Accordion should have full bleed
null
singleboolean | nullfalse
Specifies if only a single collapsible can be expanded at a time or not
null
purpose"list" | nullfalse
The semantic purpose of the Accordion If you want to render a list you can set the purpose to 'list' and the Accordion will render an <ol> element
null
expandedCollapsibles{ [x: string]: boolean; } | nullfalse
The map of collapsible IDs and their expanded state.
null
onRequestExpandedChange((collapsibleId: string, expanded: boolean) => void) | nullfalse
The callback function for handling expanded change events.
null
defaultExpandedCollapsibles{ [x: string]: boolean; } | nullfalse
The default map of collapsible IDs and their expanded state. \n This is ignored if expandedCollapsibles is provided
null

Related

Was this page useful?

Thanks for your feedback!

Feel free to include your name if you wish to have a follow up conversation.


accordioncollapsiblesqueeze-box
Published: Jan 3, 2022Last updated: Sep 3, 2024