Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

accessible-menu

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accessible-menu

A JavaScript library to help you generate WCAG accessible menus in the DOM.

  • 3.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1K
increased by32.16%
Maintainers
1
Weekly downloads
 
Created
Source

accessible-menu

Latest release License Jest tests GitHub CodeQL

A JavaScript library to help you generate WCAG accessible menus in the DOM.

The supported menu types are:

Browser Support


Chrome

Firefox

Safari

Edge

Chromium

Webkit
last 2 versionslast 2 versionslast 2 versionslast 2 versionslast 2 versionslast 2 versions

Found something that doesn't work the way it should in one of the listed browsers above? Open an issue!

Installation

NPM

NPM is recommended for large-scale development, since it works well with bundlers like Webpack or Rollup.

# latest stable
npm install accessible-menu

CDN

For learning/prototyping purposes you can use the latest version with:

<script src="https://cdn.jsdelivr.net/npm/accessible-menu/dist/accessible-menu.js"></script>

For production environments, it is recommend to use a specific version to avoid unforseen breaking changes:

<script src="https://cdn.jsdelivr.net/npm/accessible-menu@3.0.9/dist/accessible-menu.min.js"></script>

Upgrading from version 2 to version 3?

Check out the upgrade guide!

Usage

To use accessible-menu, you first need to make sure your menu matches the following structure:

<ul id="example-menu">
  <li><a href="/about">About</a></li>
  <li class="dropdown">
    <a href="#">Projects ▼</a>
    <ul>
      <li><a href="/projects/awesome">Awesome project</a></li>
      <li><a href="/projects/not-so-awesome">Not-so-awesome project</a></li>
    </ul>
  </li>
  <li><a href="/contact">Contact me</a></li>
</ul>

Include accessible-menu through import or bundled library in your project:

import AccessibleMenu from "accessible-menu";

or

<script src="https://cdn.jsdelivr.net/npm/accessible-menu@3.0.9/dist/accessible-menu.min.js"></script>

Once you have accessible-menu loaded, declare a new menu object.

menuElement is required for all menus, while submenuItemSelector is only required if you have submenus/dropdowns.

const menu = new AccessibleMenu.DisclosureMenu({
  menuElement: document.querySelector("#example-menu"),
  submenuItemSelector: "li.dropdown",
});

Only need one type of menu class?

Bundled versions of each menu are provided in the dist and individual exports are provided in the index.

There are also compiled ES Module versions if you don't want to use an iife!

DisclosureMenu usage
import { DisclosureMenu } from "accessible-menu";

or

<script src="https://cdn.jsdelivr.net/npm/accessible-menu@3.0.9/dist/disclosure-menu.min.js"></script>

then

const menu = new DisclosureMenu({
  menuElement: document.querySelector("#example-menu"),
  submenuItemSelector: "li.dropdown",
});
Menubar usage
import { Menubar } from "accessible-menu";

or

<script src="https://cdn.jsdelivr.net/npm/accessible-menu@3.0.9/dist/menubar.min.js"></script>

then

const menu = new Menubar({
  menuElement: document.querySelector("#example-menu"),
  submenuItemSelector: "li.dropdown",
});
Treeview usage
import { Treeview } from "accessible-menu";

or

<script src="https://cdn.jsdelivr.net/npm/accessible-menu@3.0.9/dist/treeview.min.js"></script>

then

const menu = new Treeview({
  menuElement: document.querySelector("#example-menu"),
  submenuItemSelector: "li.dropdown",
});

Documentation

Examples

Looking for a working example of accessible-menu? Check out these codepens:

Bootstrap support

Looking to use this with Bootstrap? Because Bootstrap adds classes to the menu's containing element to show/hide the menu, you'll need custom open/close functions for your menu. Check out the accessible-menu-bootstrap-4 or accessible-menu-bootstrap-5 projects where all that is done for you!

Versioning

This project uses Semantic Versioning 2.0.0 to keep track of releases.

For more detailed information about SemVer, please see the official documentation.

Contributing

If you're interested in contributing to the project, please read the Contribution Guidelines. Any and all contributions must follow these guidelines or they will not be accepted.

Sponsors

Coldfront Labs Inc.

Keywords

FAQs

Package last updated on 01 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc