Accordion
Anatomy
Elements
- Accordion
- The container.
- Section
- I made a choice between "item" and "section". Because ever item has a header, I decided to go with "section".
- Header
- WAI-ARIA Authoring Practices call it "Accordion Header". Other options: "summary".
- Toggle button
- The clickable area inside the header.
- Panel
- WAI-ARIA Authoring Practices call it "Accordion Panel". I was also considering "panel", "body" and "content", "details".
States
Are things open/closed or expanded/collapsed or hidden? Which elements are open/expanded?
API
Considering:
focusFirst()for implementing Home keyfocusNext()for implementing ArrowDown keyfocusLast()for implementing End keyfocusPrevious()for implementing ArrowUp keyexpandAll()collapseAll()
Events
Considering:
togglelike the event fordetails/summary
States
Considering:
openboolean
Technology
-
The custom element should be stylable by CSS depending on the state. There should be an
openattribute that can be selected by CSS.
Accessibility
UX Design
Toggle button:
- Proximity of the toggle icon to the heading text: When the toggle button is aligned to the opposite side of the heading text, the space between the toggle button and the heading might be too large to see what button corresponds to what heading. Consider limiting the space by a) aligning the items on the same side, or b) limiting the width of the accordion so the space is limited.
- Arrow direction of the toggle icon: when using an arrow, which direction should the arrow point for the expanded state and for the collapsed state? Many implementations have expanded = up and collapsed = down. Adobe Spectrum uses expanded = down, collapsed = text direction.
Example Component
- Gemeente Amsterdam - Design System - Accordion
- GOV.UK - Components - Accordion
- USWDS - Components - Accordion
- DSO Toolkit - Componenten - Accordion
- ING / Lion - Components - Accordion
- Material UI - Components - Accordion
- Vlaanderen - JS Components - Accordion
- Nijmegen - Componenten - Accordion
- Salesforce / Lightning - Components - Accordion
- Rijkshuisstijl - Basiselementen - Accordeon
- Ant Design - Components - Collapse
Experiment
Just CSS class names
BEM identifiers:
nih-accordionnih-accordion__sectionnih-accordion__section--opennih-accordion__headernih-accordion__header--expandednih-accordion__header--collapsednih-accordion__button-togglenih-accordion__button-toggle--expandednih-accordion__button-toggle--collapsednih-accordion__panelnih-accordion__panel--hidden
What is an example of latin text?
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.
What is an another example?
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.
Custom element implementation
Custom elements:
nih-accordionnih-accordion-sectionnih-accordion-headernih-accordion-panel
nih-accordion,
nih-accordion-section,
nih-accordion-header,
nih-accordion-panel {
display: block;
}
nih-accordion-panel[hidden] {
display: none;
}
nih-accordion-header::after {
content: "🔽";
}
nih-accordion-header[open]::after {
content: "🔼";
}
What is an example of latin text?
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.
Custom element implementation
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.