Accordions
The accordion consists of a number of collapsed sections, each with a button to expand that section's content
- Version:
- 0.1.0
- Status:
- Published
Introduction
Accordions serves a similar purpose to Tabs: they collapse content into an interactive overview of itself.
Arguably, the interaction paradigm of the accordion is simpler than a standard tab interface[1] since it does not rely on either programmatic focus management or arrow key navigation. Instead, each button precedes each closed 'drawer' in the source. Keyboard and screen reader browsing is a case of simply pressing the button (or 'handle') and moving directly into the revealed content (the open 'drawer').
Accordions are also a better solution in terms of responsive design: their visual structure is not dependent on elements ('tabs') appearing in a horizontal line. Some tab interfaces are designed to collapse into an accordion-like visual structure, with one tab per line. This is problematic since it makes the tab interface appear, but not behave, like an accordion.
Recommended markup
The Reference implementation is designed to accept different types of content and enhance it into an accordion. Depending on the context and quantity of your content, the semantics of the markup should differ.
For example, content that represents the major sections of a page's content might be marked up with <section>
s and headings:
<h1>Main heading of page</h1>
<section>
<h2>Section 1</h2>
<p>Some text...</p>
<img src="http://www.example.com/path/to/image" alt="description">
<p>Some more text...</p>
</section>
<section>
<h2>Section 2</h2>
<p>Some text here...</p>
<p>Additional text...</p>
</section>
<section>
<h2>Section 3</h2>
<img src="http://www.example.com/path/to/image" alt="another description">
<blockquote>A quotation from somewhere</blockquote>
</section>
Wrapping this set of <section>
s in a class="gel-accordion"
element produces the following enhanced markup when the JavaScript runs:
<h1>Main heading of page</h1>
<div class="gel-accordion">
<section>
<h2 class="gel-accordion__handle">
<button aria-expanded="false" type="button">
<span>Section 1</span>
<svg viewBox="0 0 32 32" class="gel-icon gel-icon--text" focusable="false" aria-hidden="true">
<path d="M16 29L32 3h-7.2L16 18.3 7.2 3H0"></path></svg>
</button>
</h2>
<div class="gel-accordion__drawer" hidden>
<p>Some text...</p><img src="http://www.example.com/path/to/image" alt="description">
<p>Some more text...</p>
</div>
</section>
<section>
<h2 class="gel-accordion__handle">
<button aria-expanded="false" type="button">
<span>Section 2</span>
<svg viewBox="0 0 32 32" class="gel-icon gel-icon--text" focusable="false" aria-hidden="true">
<path d="M16 29L32 3h-7.2L16 18.3 7.2 3H0"></path></svg>
</button>
</h2>
<div class="gel-accordion__drawer" hidden>
<p>Some text here...</p>
<p>Additional text...</p>
</div>
</section>
<section>
<h2 class="gel-accordion__handle">
<button aria-expanded="false" type="button">
<span>Section 3</span>
<svg viewBox="0 0 32 32" class="gel-icon gel-icon--text" focusable="false" aria-hidden="true">
<path d="M16 29L32 3h-7.2L16 18.3 7.2 3H0"></path></svg>
</button>
</h2>
<div class="gel-accordion__drawer" hidden>
<img src="http://www.example.com/path/to/image" alt="another description">
<blockquote>A quotation from somewhere</blockquote>
</div>
</section>
</div>
class="gel-accordion__drawer"
andhidden
: All the content except the 'handle' is grouped inside this element so its visibility can be toggled easily. The drawer is hidden by default.<button>
andaria-expanded
: The visibility of the drawer (see above) is affected by the toggle button. Thearia-expanded
state is set to eitherfalse
(drawer closed; default on page load) ortrue
(drawer open)SVG
: An SVG based on the GEL Iconographygel-icon-down
. This hasfocusable="false"
to remove it from focus order, andaria-hidden="true"
to hide it from browsers/assistive technologies that erroneously expose it.