Accordion
The Accordion is a toggle control for displaying content or form elements within a closely related set.
- Standard Accordion
- Examples
- Usage and Behaviors
- Examples
- Developer Notes
- Right-to-Left Support
- Accessibility Notes
Standard Accordion
By default, the Accordion allows multiple sections to expand at a time.
Panel Heading 1
Subheading
Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Panel Heading 2
Subheading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Panel Heading 3
Subheading
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
When to Use
- When users are likely to need to compare content between categories.
- When secondary or supplemental content needs to display in a limited amount of space.
When Not to Use
- When content is important or critical. Keep this content exposed for quick and easy access.
- If selections are used for navigation purposes, use the Panel Menu instead.
Examples
- Standard Accordion (shown above)
- Single-Expand Accordion
- Accordion in Panel
Usage and Behaviors
- Always include either chevrons or radio buttons to indicate that Accordion headers are selectable.
- When using an Accordion for forms, content sections with form elements that have returned errors should be expanded automatically. This keeps critical content exposed and allows users to resolve errors more quickly.
Examples
Single-Expand Accordion
The Accordion may be configured to limit the number of expanded sections to one.
Panel Heading 1
Subheading
Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Panel Heading 2
Subheading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Panel Heading 3
Subheading
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
When to Use
- When users are likely to need to focus on a subset of content.
Accordion in Panel
When nesting an Accordion in a Panel you may replace the box-shadow with a single stroke to denote the content area, while also preserving the visual hierarchy.
Panel Heading 1
Subheading
Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Panel Heading 2
Subheading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Panel Heading 3
Subheading
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Additional Guidelines
When Accordion headers are mutually exclusive and expand a subset of related form elements, such as a Multiple Payment Options Accordion, use only radio buttons alongside the Accordion header labels. Chevrons should not be used in addition to radio buttons in this case, since radio buttons provide sufficient affordance. Radio buttons should only be used with forms.
Developer Notes
An Accordion is created using the class spark-accordion
. It is then instantiated using new Spark.Accordion(el)
. If the Accordion component is nested within a Panel component, you may add the class spark-nested
to the spark-accordion
element to replace the box-shadow with a border.
Each Accordion drawer is represented by a section
with a class of spark-accordion__drawer
, and consists of two primary parts: the content container, and header that controls the drawer. The content container can be identified by the spark-accordion__content
class while the drawer headers are identified by a header
tag with a class of spark-accordion__header
.
The following options may be passed when using new Spark.Accordion(el, {});
:
You may programmatically control Accordions with a series of methods that return a Promise. This enables you to better synchronize any callback actions to the appropriate point in an animation. For example, if you have a hidden message in your Accordion drawer content that you’d like to animate in once the drawer is open, you could utilize the returned Promise and chain your call to the open()
method. The Promise will resolve at the exact point the Accordion’s animation has completed and hand off execution to your show message logic.
Accordions with chevrons may be controlled using open()
, close()
, and toggle()
methods and passing the id
of the spark-accordion__content
as an argument. The Radio Accordions may be controlled using the select()
method and passing the value
for the radio input inside of the spark-accordion__header
you want checked. Note that the value passed may be different from your spark-accordion__content
id
.
For all available methods and full API, refer to the component code on Bitbucket.
Standard Accordion
Panel Heading 1
Subheading
Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Panel Heading 2
Subheading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Panel Heading 3
Subheading
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Single-Expand Accordion
Panel Heading 1
Subheading
Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Panel Heading 2
Subheading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Panel Heading 3
Subheading
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
No-Collapse Accordion
Panel Heading 1
Subheading
Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Panel Heading 2
Subheading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Panel Heading 3
Subheading
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Single-Expand and No-Collapse Accordion
Panel Heading 1
Subheading
Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Panel Heading 2
Subheading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Panel Heading 3
Subheading
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Cras mattis consectetur purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Radio Accordion
A Radio Accordion is created using the class spark-accordion--radio
. It is then instantiated using new Spark.Accordion(el)
. Alternatively, you may use the generic spark-accordion
class but you would need to instantiate the component with the radio
option: new Spark.Accordion(el, {radio: true});
.
Sign In to pay with a card on file.
Phasellus cursus purus eu varius finibus. Praesent pretium nisi est, nec aliquet nulla sollicitudin eget. Maecenas lacinia mi in neque scelerisque.
Right-to-Left Support
لوحة العنوان
عنوان فرعي
هذا هو النص المثال لأغراض العرض فقط. شرارة إلى الأبد
لوحة العنوان
عنوان فرعي
هذا هو النص المثال لأغراض العرض فقط. شرارة إلى الأبد هذا هو النص المثال لأغراض العرض فقط. شرارة إلى الأبد
لوحة العنوان
عنوان فرعي
هذا هو النص المثال لأغراض العرض فقط. شرارة إلى الأبد
Accessibility Notes
To ensure that the Accordion component is fully functional and accessible to assistive technologies, it is important to provide additional attributes as discussed below.
Accordion Header
The spark-accordion__header
element requires a tabindex
attribute with the value set to 0
when using an Accordion with chevrons to allow the header to receive focus when navigating by keyboard. This element also requires an aria-controls
attribute to indicate which Accordion drawer it controls, and an aria-expanded
attribute with the value set to true
or false
depending on the desired starting state of the drawer controlled.
The h4
heading element used within the header can be adjusted to the desired heading element i.e. h1
- h6
. This will be dependent on the hierarchy of your content headings.
Accordion Content
The spark-accordion__content
element requires an id
attribute whose value should be the same as the value of the aria-controls
attribute set on the Accordion header (and discussed) that is intended to control the drawer.