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

a11ydrops

v1.0.6

Published

a11ydrops provides accessibility support for dropdown menus.

Downloads

62

Readme

a11ydrops

a11ydrops is a small (5kb) JavaScript library that ensures your dropdown menus are accessible via keyboard controls and screen readers - view the examples.

What Does a11ydrops Do?

  1. Creates a button to toggle the state (open/closed) of the drop menu.
  2. Adds required aria attributes to link the toggle button and drop menu together.
  3. Enables keyboard controls to tab seemlessly though drop menus and escape when needed.

Note: a11ydrops does not provide any CSS styling. It simply injects required functionality to make the dropdown menus accessibile for every user.

Styling

With regards to CSS styling, a11ydrops is an unopinionated library and does not provide any out-of-the-box CSS. It will be up to you to provide the necessary CSS for styling the dropdown menu's and buttons.

When a dropdown menu becomes active (or visible) an .active class is added to the menu and button.

Note: The .active classname is configurable via a11ydrops options.

Install

a11ydrops can be installed via NPM:

$ npm install a11ydrops --save

or by direct script include:

<script src="{path_to_scripts}/a11ydrops.js">

Initialization

At minimum, a11ydrops requires a target HTML element to be defined and passed into the a11ydrops function call. The target element should be the parent container element that wraps your menu.

There are optional configuration options object that can modify default plugin parameters.

ES6 Module

import * as a11ydrops from "a11ydrops";

let nav = document.querySelector("#main-nav");
a11ydrops.init(nav, {
	// options
	selector: "li"
});

Vanilla JS

<script src="{PATH_TO_SCRIPT}/a11ydrops.min.js" />
;
var nav = document.querySelector("#main-nav");
a11ydrops.init(nav, {
	// options
	selector: "li",
	menu: ".sub-menu",
	buttonText: '<span class="sr-only">Toggle Menu</span>',
	buttonClass: "button button-blue"
});

Example HTML

<ul id="main-nav">
	<li>
		<a href="#">About Us</a>
		<ul class="sub-menu">
			<li><a href="#">Our Team</a></li>
			<li><a href="#">History</a></li>
			<li><a href="#">Contact Us</a></li>
			<!-- ... more menu items -->
		</ul>
	</li>
	<li>
		<a href="#">Our Work</a>
		<ul class="sub-menu">
			<li><a href="#">Print</a></li>
			<li><a href="#">Websites</a></li>
			<li><a href="#">App Development</a></li>
			<!-- ... more menu items -->
		</ul>
	</li>
	<!-- ... more menu items -->
</ul>

Config Options

Use following configuration options to modify a11ydrops functionality.

| Option | Description | Default | Type | | ------------- | --------------------------------------------------- | --------------- | ------- | | selector | Element that contains the menu. | 'li' | String | | menu | The ID or class for the menu. | '.sub-menu' | String | | activeClass | The active/open class for the menu. | 'active' | String | | hover | Toggle the activeClass on mouse hover. | false | Boolean | | hover_width | The minimum window width to trigger a hover effect. | 0 | String | | buttonText | Text for the dropdown menu button. | 'Toggle Menu' | String | | buttonClasses | Add additional classes to the dropdown menu button. | null | String |

License

a11ydrops is released under the MIT license.