permalink: /components/accordion/ filename: accordion title: Accordion alpha: false sources:
- title: HTML url: https://github.com/frend/frend.co/blob/gh-pages/_components/accordion/accordion.html
- title: CSS url: https://github.com/frend/frend.co/blob/gh-pages/_components/accordion/accordion.css
- title: JS url: https://github.com/frend/frend.co/blob/gh-pages/_components/accordion/accordion.js links:
- title: WAI ARIA Authoring Practices - Accordion url: https://www.w3.org/TR/wai-aria-practices/#accordion
- title: Open Ajax Alliance - Tab Panel Accordion url: http://www.oaa-accessibility.org/examplep/accordian1/
Accordions leverage a lot of similar conventions to tab interfaces, in that they progressively disclose portions of content to the user.
Accordion components themselves can be considered tablist
s, and declared so on their parent container. Depending on whether multiple or single panels can be expanded at one time, we can set the container's aria-multiselectable
attribute to true or false.
To effectively progressively enhance sections of content into an accordion widget, we can start out with pairs of headings and content containers. As headings themselves aren't interactive and can't receive focus, we have the option of programatically nesting a button element within them, or managing focus and roles ourselves. This component chooses to do the latter using tabindex
and aria-controls
attributes, with the help of common id
s on headers and panels. The script that supports the interactions, should also manage header aria-selected
and aria-expanded
states.
Panels that are inactive can be hidden using tabindex="-1"
and aria-hidden="true"
. This ensures only the active content is focusable at any given time.
Arrow keys can be used to navigate between header items, and Spacebar or Enter keypresses will toggle active tabpanel
s. If aria-multiselectable="false"
is set, then sibling panels should close and be hidden appropriately.
There is more work to do on this particular component to manage alternative keybindings (Home, End, PageUp/Down), as per the WAI-ARIA spec.
Install
Fraccordion is available to install with npm
. Run with the --save
flag to add the component your project dependencies.
npm install fr-accordion --save
The component will then be available to import
.
;
Functional styles for the accordion (accordion.css) that are required to display the component states correctly should be referenced via a <link>
in the <head>
of your document, or can be integrated into your existing stylesheet.
You can read more about installing Frend components on our About page, including details on the functional CSS and JavaScript structure.
Usage
Accordions rely on header and panel pairs, wrapped in a single container.
..................
Assign the function invocation to a variable.
var myAccordion = ;
Methods
// remove all bindings and attributes when no longer neededmyAccordion;// re-initialise as neededmyAccordion;
Options
var myAccordion =;