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 theAccordion. By default, it will render as aol. To use an unordered list, use theasprop. - In the Vanilla API, use a
oltag for the Accordion, andlitags for each Collapsible within it.
The preview has been updated.
Full bleed
fullBleed is deprecated in SWAN v3.37.0
Accordion displays the content full bleed by default.
Use fullBleed to remove the right padding of the content within every Collapsible component of the Accordion.
The preview has been updated.
Disabled
Use disabled when a Collapsible within the Accordion can not be interacted with, when the content of the Accordion is permanently unavailable, or irrelevant to the user’s current task.
The preview has been updated.
Color Swatches
Use skin="color-swatches" to wrap a large amount of Color Swatches in a more compact manner.
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.
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 theCollapsiblechanging its state.expanded: to indicate whether theCollapsibleseeks to be expanded or not.
The preview has been updated.