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

accessible-menu-bootstrap-5

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accessible-menu-bootstrap-5

A JavaScript library to help you generate WAI-ARIA accessible menus with in the DOM using Bootstrap 5.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
95
decreased by-37.91%
Maintainers
1
Weekly downloads
 
Created
Source

accessible-menu-bootstrap-5

Latest release License Jest tests GitHub CodeQL

A JavaScript library to help you generate WAI-ARIA accessible menus with in the DOM using Bootstrap 5.

This project is an extension of accessible-menu to allow out-of-the-box for Bootstrap 5 compatibility.

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-bootstrap-5

CDN

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

<script src="https://cdn.jsdelivr.net/npm/accessible-menu-bootstrap-5/dist/accessible-menu-bs5.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-bootstrap-5@1.0.2/dist/accessible-menu-bs5.min.js"></script>

Usage

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

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

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

import AccessibleMenu from "accessible-menu-bootstrap-5";

or

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

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

menuElement is required for all menus. Unlike accessible-menu, accessible-menu-bootstrap-5 will automatically find dropdown menus since the classes .dropdown, .dropdown-menu, and .dropdown-item are included in the Bootstrap 5 framework.

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

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!

Bootstrap5DisclosureMenu usage
import { Bootstrap5DisclosureMenu } from "accessible-menu-bootstrap-5";

or

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

then

const menu = new Bootstrap5DisclosureMenu({
  menuElement: document.querySelector("#example-menu"),
});
Bootstrap5Menubar usage
import { Bootstrap5Menubar } from "accessible-menu-bootstrap-5";

or

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

then

const menu = new Bootstrap5Menubar({
  menuElement: document.querySelector("#example-menu"),
});
Bootstrap5Treeview usage
import { Bootstrap5Treeview } from "accessible-menu-bootstrap-5";

or

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

then

const menu = new Bootstrap5Treeview({
  menuElement: document.querySelector("#example-menu"),
});

Documentation

Conflict with Bootstrap's own navbar toggle

Bootstrap 5 has it's own implementation of expanding/collapsing menus using the data-bs-toggle attribute on navbar togglers and dropdown toggles which would cause both accessible-menu-bootstrap-5 and Bootstrap's own toggler to open/close menus at the same time. To resolve this issue, accessible-menu-bootstrap-5 removed the data-bs-toggle attributes from menu toggles that it controls.

Other versions of Bootstrap

This project isn't designed to work with other versions of Bootstrap other than v4, however you could probably get it to work with Bootstrap 3 by customizing the selectors and open/close classes when declaring the menu.

You also might be able to get this to work with Bootstrap 5, however v5 changed the data-bs-toggle value on dropdowns to data-bs-toggle which won't be handled by this project. A Bootstrap 5 specific project may be created if there is enough interest in it.

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 17 Feb 2023

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