Use Collapsible...
- To present a large amount of content in a compact form.
- To prevent information overload by allowing users to expand only the section they are interested in.
- Use as part of an Accordion for showing multiple Collapsibles
Don't use Collapsible...
- 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.
Basic Collapsible
Use the BasicCollapsible
Convenience Component for the most common use-cases.
Collapsible
Use Collapsible
with different properties to build your own when the Convenience Component doesn’t match your needs.
Text Closed / Text Open summary
Use CollapsibleSummaryTextClosed
and CollapsibleSummaryTextOpen
inside CollapsibleSummary
to enable a different summary text depending on whether the Collapsible is collapsed or expanded.
Default expanded
Use defaultExpanded
to present the Collapsible
as expanded by default.
Disabled
Use disabled
to prevent the Collapsible from expanding.
Full Bleed
Use fullBleed
to remove the right padding of the content within the Collapsible.
Managing state
Controlling the state of a Collapsible
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 expanded
to indicating whether the Collapsible
should be expanded or not.
Use the onRequestExpandedChange
prop on the Collapsible
to be notified when it wants to expand or collapse. This handler is invoked with the following argument:
expanded
: to indicate whether theCollapsible
seeks to be expanded or not.
The preview has been updated.
Accessibility
In the Vanilla API, for each swan-collapsible-summary-button
, add the following attributes:
aria-expanded
: set this attribute totrue
orfalse
to indicate whether the accordion is expanded or collapsed.aria-controls
: assign to this attribute the same ID value as theswan-collapsible-content
section it controls.
In the React API, those attributes are handled for you.