Accordion for Bricks
An accessible accordion with a smooth open and close. Each item is a native details element, so it works without JavaScript; the script only adds the animation. Put any Bricks elements inside an item. The same script also animates any button and panel pair, so you can use it for menu sections.
The element
- Add the Accordion element. Each item has a heading and a content area. Add items with the plus in the structure panel, and put any elements in the content area, even another accordion.
- Items start: all closed, first open or all open.
- Only one open at a time: opening an item closes the others.
- Animate opening and closing with a time you choose. Visitors who prefer reduced motion get no animation.
- Style it as lines or cards, with a chevron, plus and minus or no marker. Colours, sizes, line, corner radius and spacing all have controls.
- Each item can have an icon next to its heading: add an icon element inside the heading and give it the class
acdn-icon.
Using it for menus and other panels
Any button that controls a hidden panel can have the same animation.
- Wrap the buttons and panels in an element with the attribute
data-acdn-group. Adddata-acdn-single="1"if only one should stay open. - Give each button the attribute
data-acdn-trigger,aria-expanded="false"andaria-controlswith the ID of its panel. - Give the panel that ID and the
hiddenattribute. - Optional:
data-acdn-duron the group sets the time in milliseconds.
For developers
- An
acdn:toggleevent fires on the button when a panel opens or closes, withdetail.openanddetail.panel. ACDN.set(button, true or false)opens or closes one from your own script.ACDN.refresh()picks up groups added after the page loaded.
Good to know
- Without JavaScript the items still open and close, but button and panel groups need the script.
- Clicking again during the animation reverses it from where it is.