Expand & Collapse
Expand/collapse allows users to toggle between displaying and hiding a section of content.
Inline Example
When to Use
- Use an expand/collapse treatment to progressively display content in order to streamline complex displays and reveal additional content only when the user needs or requests it.
Variations
- Inline (shown above)
- Panel
Variations
Panel Example
Expand/collapse panels are variations of the panel pattern and allow users to open and close entire panels of content.
Additional Guidelines
- Do not include actionable elements (buttons, links, etc.) within the heading/arrow area of the panel. This area should be reserved for expanding and collapsing
Developer Notes
Inline Content
The expand/collapse pattern is implemented using the .spark-expand class. Content that should be shown or hidden depending on the expand state should be wrapped inside an element with a class of .spark-expand__content. Showing/hiding the content is handled by adding a class of .spark-expand__toggle to an element inside of the .spark-expand container.
It is possible to show and hide additional content based on the expanded or collapsed state. To hide content when expanded, add a class of .spark-expand__hide--expanded. Conversely, adding a class of .spark-expand__show--expanded will show an element when expanded. This is best used to create two separate buttons for expanding and collapsing the content.
This component requires the use of the JavaScript component to handle toggling the .expanded class. It can be instantiated using new Spark.Expand(el).
Panel Accordion
A panel accordion component is a special instance of the expand/collapse pattern. It is created by adding a secondary class of .spark-panel--expand to an element with the .spark-panel class. By default, content contained in the .spark-panel__header will be the only thing visible. In order to function as a toggle to show/hide content, the header element must have a [role="heading"] or a class of .spark-expand__toggle. When the heading is clicked, and .expanded class will be added and the .spark-panel__body content will be shown.