npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fr-accordion

v1.0.6

Published

Frend's accessible, modern accordion component.

Downloads

122

Readme


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 tablists, 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 ids 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 tabpanels. 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.

import Fraccordion from 'fr-accordion';

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.

<div class="fr-accordion js-fr-accordion">
	<h2 id="accordion-header-1" class="fr-accordion__header js-fr-accordion__header">...</h2>
	<div id="accordion-panel-1" class="fr-accordion__panel js-fr-accordion__panel">
		...
	</div>
	<h2 id="accordion-header-2" class="fr-accordion__header js-fr-accordion__header">...</h2>
	<div id="accordion-panel-2" class="fr-accordion__panel js-fr-accordion__panel">
		...
	</div>
	<h2 id="accordion-header-3" class="fr-accordion__header js-fr-accordion__header">...</h2>
	<div id="accordion-panel-3" class="fr-accordion__panel js-fr-accordion__panel">
		...
	</div>
</div>

Assign the function invocation to a variable.

var myAccordion = Fraccordion();

Methods

// remove all bindings and attributes when no longer needed
myAccordion.destroy();

// re-initialise as needed
myAccordion.init();

Options

var myAccordion = Fraccordion({
	// String - Outer container selector, hook for JS init() method
	selector: '.js-fr-accordion',

	// String - Accordion header elements converted to focusable, togglable elements
	headerSelector: '.js-fr-accordion__header',

	// String - Use header id on element to tie each accordion panel to its header - see panelIdPrefix
	headerIdPrefix: 'accordion-header',

	// String - Accordion panel elements to expand/collapse
	panelSelector: '.js-fr-accordion__panel',

	// String - Use panel id on element to tie each accordion header to its panel - see headerIdPrefix
	panelIdPrefix: 'accordion-panel',

	// Boolean - If set to false, all accordion panels will be closed on init()
	firstPanelsOpenByDefault: true,

	// Boolean - If set to false, each accordion instance will only allow a single panel to be open at a time
	multiselectable: true,

	// String - Class name that will be added to the selector when the component has been initialised
	readyClass: 'fr-accordion--is-ready',
	
	// Integer - Duration (in milliseconds) of CSS transition when opening/closing accordion panels
	transitionLength: 250
});