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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@muktarkabir/dropdown-menu

v3.0.3

Published

A light-weight javascript library for dynamically creating dropdown menus

Readme

dropdown-menu

drop-down-menu

A lightweight, dependency-free JavaScript module to create and attach a customizable dropdown menu to any element or container on the page. It supports vertical or horizontal "dots" toggles, automatic positioning, and easy item click handling.


🚀 Installation

Install from npm:

npm install @muktarkabir/dropdown-menu

Import the module you want to use in your project:

import { dotsDropDownMenu,anchorDropDownMenu } from "@muktarkabir/dropdown-menu";

🎨 CSS

A default stylesheet is provided. You can override any styles by including your own CSS rules after importing dropdown.css.

/* Example override */
.menu{
    min-width: 12ch;
    font-size:2rem;
} 

.item:hover {
  background-color: #f0f8ff;
}

.dots{
    color: orange;
}

📦 API

There are two modules available for use: anchorDropDownMenu which is attached to an existing anchor element. dotsDropDownMenu which generates a dots button that toggles the visibility of the menu.

anchorDropDownMenu(options)

Creates and attaches a dropdown menu to an existing element.

Options

| Property | Type | Required | Default | Description | | -------- | ----------| -------- | ------- | ---------- |
| anchor | Element | yes | — | An existing element the rendered dropdown will be associated with, Clicking this will toggle the menu visibility. | | items | string[]| yes | — | An array of text labels for menu items. |

Returns

An object with:

  • menuButton (Element): The toggle element (your anchor).
  • menuItemsContainer() (() => Element): A function returning the dropdown menu.
  • addClickListenerToMenuItem({ itemIndex, action }) (Function): Attach a custom callback to a specific item by index.

dotsDropDownMenu(options)

Creates and attaches a dropdown menu to a generated dots button.

Options

| Property | Type | Required | Default | Description | | ---------- | ---------- | -------- | ------- | ----------- | | parent | Element | yes | — | A parent element where the menu button will be rendered in. | | vertical | boolean | optional | false | When true, uses vertical dots () instead of horizontal (). | | items | string[] | yes | — | An array of text labels for menu items. |

Returns

An object with:

  • menuButton (Element): The toggle element (dots).
  • menuItemsContainer() (() => Element): A function returning the dropdown menu.
  • addClickListenerToMenuItem({ itemIndex, action }) (Function): Attach a custom callback to a specific item by index.

🎉 Usage Examples

1. Attach to a Container

<div id="parent"></div>
import { anchorDropDownMenu,dotsDropDownMenu } from "@muktarkabir/dropdown-menu";

const container = document.getElementById("parent");

const menu1 = dotsDropDownMenu({
  parent: container,
  vertical: false,
  items: ["Edit", "Delete", "Move", "Copy"],
});
menu1.addClickListenerToMenuItem({
  itemIndex: 1,
  action: (e) => {
    console.log(e.target);
    doSomething();
    window.location.reload();
  },
});

2. Use an Existing Anchor Element

<button id="more-btn">More</button>
const anchor = document.getElementById("more-btn");

const menu2 = anchorDropDownMenu({
  anchor: anchor,
  items: ["Edit", "Rename"],
});

//Alternatively add an event listener to the dropdowwn itself and use event delegation to register clicks on items.
menu2.menuItemsContainer().addEventListener("click", (e) => {
  console.log('Clicked on item:', e.target.textContent);
});


// The provided anchor will automatically toggle the dropdown on click.

⚙️ Customization & Styling

  • Dots: default size 1.6rem, you can override via:

    .dots {
      font-size: 2rem;
    }
  • Menu: default padding, border, and background, override via:

    .menu {
      background-color: #222;
      color: #fff;
    }
    .menu .item:hover {
      background-color: #333;
    }

🧹 Cleanup

Currently, the module does not expose a destroy method. To remove the dropdown and listeners, manually remove the elements and event listeners:

// Assuming you stored references:
document.body.removeChild(menuElement);
dotsElement.remove();
window.removeEventListener("click", /* your handler */);

(Feature request: future versions may add destroy().)


🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to open a GitHub issue or pull request.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/foo).
  3. Commit your changes (git commit -m "feat: add bar").
  4. Push to the branch (git push origin feature/foo).
  5. Open a pull request.

📄 License

MIT © 2025 Muktar Muhammad Kabir