Accordion
A vertically stacked set of interactive headings that reveal or hide content sections.
The accordion component vertically layers content sections to optimize vertical space. Keystone provides this component as partials (for template use) and as shortcodes (for content use).
The component leverages the partial decorators(Opens in a new tab)
construct introduced in Hugo v0.154.0.
In reality, the half-life of a pizza in a house with at least one human is approximately 14 minutes.
Reference
The component is composed of a parent ui/accordion and child ui/accordion-item partials.
Parent: ui/accordion
- multiple
"multiple" true— (boolean, optional)- Allows multiple accordion items to remain expanded simultaneously.
- Default:
false. - level
"level" 2— (integer, required)- Sets the
aria-levelfor the internal heading roles. - This must be chosen to match the semantic heading hierarchy of your page.
- Fallback:
2
Child: ui/accordion-item
- title
"title" "First Item"— (string, required)- The text displayed in the accordion trigger button.
- icon
"icon" "pizza"— (string, optional)- Name of a icon. Overrides the default
chevron-downicon. - The Icon component is required to override icons.
Installation
The Accordion component is disabled by default to save resources.
Uncomment the imports in the following files:
Javascript
Create the Alpine module:
Import and register it in main.js:
Hugo Partials
Create the parent ui/accordion and child ui/accordion-item partials.
Parent Partial
Child Partial
Hugo Shortcodes
Create the parent ui/accordion and child ui/accordion-item shortcodes.
Parent Shortcode
Child Shortcode
CSS Styling
Create the CSS component:
Import it in your main Tailwind file:
Usage
Using Partials (Templates)
Using Shortcodes (Markdown)
Accessibility
The component follows the WAI-ARIA Accordion Pattern(Opens in a new tab) and meets WCAG 2.2 standards:
- Semantic Hierarchy: Keystone allows you to pass a level prop, which is injected as
aria-levelwithin arole="heading". - Keyboard Traversal: Full support for arrow keys ( ) to move focus between triggers, and HOME / END to jump to the start/end of the list.
- State Disclosure: Uses
aria-expandedto communicate the toggle state andaria-controlsto link triggers to their respective panels. - Region Identification: Each panel uses
role="region"and is programmatically labelled by its trigger viaaria-labelledby.