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 🙏

© 2026 – Pkg Stats / Ryan Hefner

c2-accordion

v2.8.4

Published

Accessible accordion using CSS transition to expand and contract.

Readme

accordion

Accessible accordion using CSS transition to expand and contract. Aria states are automatically added.

To get Started

CommonJS

$ npm install c2-accordion
var Accordion = require('c2-accordion');

Browser Global

<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script src="iife/accordion.js"></script>

Basic Example

<div class="Accordion">
    <div class="item" data-status="disabled">
        <div class="target">...</div>
        <div class="panel">...</div>
    </div>
    <div class="item" data-status="disabled">
        <div class="target">...</div>
        <div class="panel">...</div>
    </div>
    <div class="item" data-status="disabled">
        <div class="target">...</div>
        <div class="panel">...</div>
    </div>
</div>
// This wouldn't be necessary since all these options are the defaults
var options = {
    item: '.item',
    target: '.target',
    control: '.target', // in this case the target is also acting as the control
    panel: '.panel',
    allowMultiple: true,
    attribute: 'data-status',
    expanded: 'expanded',
    contracted: 'contracted',
    prefix: 'Accordion-',
    transition: 'height .3s',
    transitionSupport: true,
    setFocus: 'none', // options: none, item, panel, target, control, first
    hashEnabled: false // use hash in URL to open accordion item
};

new Accordion('.Accordion', options);

Since the height of the "control" and the height of the "panel" make up the height of the item. It is sometimes not the case that the "target" is the same as the "control". Below is an example of this:

<div class="Accordion">
    <div class="item" data-status="disabled">
        <div class="control">
            <a class="target" href="#">...</a>
        </div>
        <div class="panel">...</div>
    </div>
    <div class="item" data-status="disabled">
        <div class="control">
            <a class="target" href="#">...</a>
        </div>
        <div class="panel">...</div>
    </div>
    <div class="item" data-status="disabled">
        <div class="control">
            <a class="target" href="#">...</a>
        </div>
        <div class="panel">...</div>
    </div>
</div>
new Accordion('.Accordion', {
    control: '.control'
});

Example with Hashes

Add the attribute "data-hash" to each item on the accordion.

<div class="Accordion">
    <div class="item" data-status="disabled" data-hash="Accordion1">
        <div class="target">...</div>
        <div class="panel">...</div>
    </div>
    <div class="item" data-status="disabled" data-hash="Accordion2">
        <div class="target">...</div>
        <div class="panel">...</div>
    </div>
    <div class="item" data-status="disabled" data-hash="Accordion3">
        <div class="target">...</div>
        <div class="panel">...</div>
    </div>
</div>
new Accordion('.Accordion', {
    hashEnabled: true
});

API

var accordion = new Accordion('.Accordion');

accordion.activate(0);    // toggles accordion to the index
accordion.expand(0);      // expands accordion to the index
accordion.contract(0);    // contracts accordion to the index
accordion.contractAll(0); // contracts all the accordions, the optional parameter is an index that gets ignored
accordion.destroy()       // removes event listeners and aria properties

Accessibility

http://www.w3.org/TR/wai-aria-practices/#accordion

Here is what the markup looks like after accessibility is added with JavaScript. It may be beneficial to add the aria attributes before JavaScript runs.

<div class="Accordion" role="tablist" aria-multiselectable="true">
    <div class="item" data-status="expanded">
        <div class="target" role="tab" aria-expanded="true" tabindex="0" id="Accordion-1-1">...</div>
        <div class="panel" role="tabpanel" aria-hidden="false" aria-labelledby="Accordion-1-1">...</div>
    </div>
    <div class="item" data-status="contracted">
        <div class="target" role="tab" aria-expanded="false" tabindex="0" id="Accordion-1-2">...</div>
        <div class="panel" role="tabpanel" aria-hidden="true" aria-labelledby="Accordion-1-2">...</div>
    </div>
    <div class="item" data-status="contracted">
        <div class="target" role="tab" aria-expanded="false" tabindex="0" id="Accordion-1-3">...</div>
        <div class="panel" role="tabpanel" aria-hidden="true" aria-labelledby="Accordion-1-3">...</div>
    </div>
</div>

Or if allowMultiple is set to false.

<div class="Accordion" role="tablist">
    <div class="item" data-status="expanded">
        <div class="target" role="tab" aria-expanded="true" aria-selected="true" tabindex="0" id="Accordion-2-1">...</div>
        <div class="panel" role="tabpanel" aria-hidden="false" aria-labelledby="Accordion-2-1">...</div>
    </div>
    <div class="item" data-status="contracted">
        <div class="target" role="tab" aria-expanded="false" aria-selected="false" tabindex="0" id="Accordion-2-2">...</div>
        <div class="panel" role="tabpanel" aria-hidden="true" aria-labelledby="Accordion-2-2">...</div>
    </div>
    <div class="item" data-status="contracted">
        <div class="target" role="tab" aria-expanded="false" aria-selected="false" tabindex="0" id="Accordion-2-3">...</div>
        <div class="panel" role="tabpanel" aria-hidden="true" aria-labelledby="Accordion-2-3">...</div>
    </div>
</div>

License

MIT © The C2 Group