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

metismenujs

v1.4.0

Published

MetisMenu: Collapsible menu plugin with Vanilla-JS

Downloads

69,165

Readme

npm version install size npm bundle size npm downloads Packagist

Table of Contents

Browser Support

This plugin does not support any version of IE browser.

Chrome | Firefox | Safari | Opera | Edge | IE | --- | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | ❌ |

Install

Package Managers

Using npm:

npm install metismenujs

Using yarn:

yarn add metismenujs

Using pnpm:

pnpm add metismenujs

Once the package is installed, you can import the library using import or require approach:

// recommended approach
import { MetisMenu } from 'metismenujs';
// You can also use the default export
import MetisMenu from 'metismenujs';

If you use require for importing, only default export is available:

const MetisMenu = require('metismenujs');

Note CommonJS usage In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require(), add the following to your tsconfig.json:

{
  "compilerOptions": {
    "moduleResolution": "NodeNext"
  }
}

CDN

ES6 UMD browser module

Using jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/metismenujs"></script>

Using unpkg CDN:

<script src="https://unpkg.com/metismenujs"></script>

ES6 ES module

Using jsDelivr CDN:

<script type="module">
  import { MetisMenu } from 'https://cdn.jsdelivr.net/npm/metismenujs/dist/metismenujs.esm.min.js';
</script>

Using unpkg CDN:

<script type="module">
  import { MetisMenu } from 'https://unpkg.com/metismenujs/dist/metismenujs.esm.min.js';
</script>

Install with composer

composer require onokumus/metismenujs:dev-master

Download

download

Ready to use files are located in the dist directory.

Usage

  1. Include metismenujs StyleSheet

    Using CDN

    jsDelivr :

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/metismenujs/dist/metismenujs.min.css">

    unpkg :

    <link rel="stylesheet" href="https://unpkg.com/metismenujs/dist/metismenujs.min.css">

    Using Vite, Astro etc.

    import 'metismenujs/style';

    or sass source file

    import 'metismenujs/sass';
  2. Add class metismenu to unordered list

<ul class="metismenu" id="menu">

</ul>
  1. Make expand/collapse controls accessible

Be sure to add aria-expanded to the element a. This attribute explicitly defines the current state of the collapsible element to screen readers and similar assistive technologies. If the collapsible element is closed by default, it should have a value of aria-expanded="false". If you've set the collapsible element's parent li element to be open by default using the active class, set aria-expanded="true" on the control instead. The plugin will automatically toggle this attribute based on whether or not the collapsible element has been opened or closed.

<ul class="metismenu" id="menu">
  <li class="mm-active">
    <a href="#" aria-expanded="true">Menu 1</a>
    <ul>
    ...
    </ul>
  </li>
  <li>
    <a href="#" aria-expanded="false">Menu 2</a>
    <ul>
    ...
    </ul>
  </li>
  ...
  </ul>
  1. Arrow Options

add has-arrow class to a element

<ul class="metismenu" id="menu">
<li class="mm-active">
  <a class="has-arrow" href="#" aria-expanded="true">Menu 1</a>
  <ul>
  ...
  </ul>
</li>
<li>
  <a class="has-arrow" href="#" aria-expanded="false">Menu 2</a>
  <ul>
  ...
  </ul>
</li>
...
</ul>
  1. Call the plugin:
  new MetisMenu("#menu");
  // or
  MetisMenu.attach('#menu');

Stopping list opening on certain elements

Setting aria-disabled="true" in the <a> element as shown will stop metisMenu opening the menu for that particular list. This can be changed dynamically and will be obeyed correctly:

<a href="#" aria-expanded="false" aria-disabled="true">List 1</a>

Options

| Option | Type | Default | Description | Example | | --- | --- | --- | --- | --- | | toggle | Boolean | true | For auto collapse support. | new MetisMenu("#menu", { toggle: false }); | | triggerElement | css selector | a | | new MetisMenu("#menu", { triggerElement: '.nav-link' }); | | parentTrigger | css selector | li | | new MetisMenu("#menu", { parentTrigger: '.nav-item' }); | | subMenu | css selector | ul | | new MetisMenu("#menu", { subMenu: '.nav.flex-column' }); |

API

dispose

For stop and destroy metisMenu.

 const mm = new MetisMenu("#menu");
 mm.dispose();

update

Re-init metisMenu.

const mm = new MetisMenu("#menu");
mm.dispose();
// ajax ...
mm.update();

Events

|Event Type |Description| |--------------|--------------| |show.metisMenu |This event fires immediately when the show instance method is called.| |shown.metisMenu |This event is fired when a collapse ul element has been made visible to the user (will wait for CSS transitions to complete).| |hide.metisMenu |This event is fired immediately when the hide method has been called. | |hidden.metisMenu |This event is fired when a collapse ul element has been hidden from the user (will wait for CSS transitions to complete).|

CSS custom properties (variables)

|Property | Default |Description | |--------------|--------------|--------------| |--mm-transition-timing-function | ease |This property sets how intermediate values are calculated for CSS properties being affected by a transition effect. | |--mm-trantisition-duration | 0.35s |This property sets the length of time a transition animation should take to complete. |

Migrating to v1.0.3 from v1.4.0

  • Update metisMenu.js & metisMenu.css files
  • Change active class to mm-active

Examples

https://github.com/metismenu/examples

Demo

https://onokumus.github.io/metismenujs

Contains a simple HTML file to demonstrate metisMenu plugin.

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Osman Nuri Okumus

License

Copyright © 2023, Osman Nuri Okumuş. Released under the MIT License.