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

aria-collapsible

v6.0.0

Published

A lightweight, dependency-free JavaScript module for generating progressively-enhanced collapsible regions using ARIA States and Properties.

Downloads

43

Readme

aria-collapsible

A lightweight, dependency-free JavaScript module for generating progressively-enhanced collapsible regions using ARIA States and Properties.

npm Downloads Build

Key Features

  • Uses ARIA States and Properties
  • Dependency-free
  • JavaScript module (ESM), CommonJS, and browser global (window.Collapsible) support

Getting aria-collapsible

You've got a couple options for adding aria-collapsible to your project:

  • Download a release from GitHub and do it yourself (old school).
  • Install using npm: npm install aria-collapsible --save
  • Install using Yarn: yarn add aria-collapsible

Usage

HTML

To use aria-collapsible, your markup needs two elements: a control and a region. The control, typically a <button> or an <a> element, is what your user will interact with and is the element that controls the display of the collapsible region. The region is an element elsewhere on the page whose display is handled by the control.

The two elements are associated by adding an aria-controls="region" attribute to the control. The value of the aria-controls attribute corresponds to the value of the region's id attribute.

<button aria-controls="region" aria-expanded="true" id="control" hidden>Menu</button>

<nav id="region">
  <ul>
    <li><a href="#">Chapter 1</a></li>
    <li><a href="#">Chapter 2</a></li>
    <li><a href="#">Chapter 3</a></li>
    <li><a href="#">Chapter 4</a></li>
    <li><a href="#">Chapter 5</a></li>
  </ul>
</nav>

JavaScript

Initialize aria-collapsible by creating a new Collapsible, passing in a DOM reference to the control, and calling the setup() method.

const collapsible = new Collapsible(document.querySelector('#control'));

collapsible.setup();

You can see the above in action in the included example file.

Collapsible regions can be shown and hidden programatically using the toggle() method:

collapsible.toggle();

You can also tear down a collapsible region, resetting the DOM to its initial state and removing event handlers:

collapsible.teardown();

Browser Support

aria-collapsible works in modern browsers. The library makes use of several new(ish) JavaScript features and, in an effort to remain as lightweight and dependency-free as possible, leaves it up to you to choose whether or not to polyfill features for older browsers.

Acknowledgments

aria-collapsible is inspired by the following works:

aria-collapsible is written and maintained by Jason Garber with the help of some great contributors.

License

aria-collapsible is freely available under The MIT License. Go forth and make the Web a more accessible place.