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

dropdown-toggle

v1.0.0

Published

setDropdown is a utility function to easily manage dropdown visibility with customizable event listeners (click or hover) and support for custom hidden class names.

Downloads

5

Readme

Dropdown Toggle Package

This simple JavaScript utility allows you to toggle the visibility of a dropdown menu based on either a click or hover event. The package can be customized by passing specific elements and a class name to hide/show the dropdown content.

Installation

You can install this package via npm:

npm install dropdown-toggle

Usage

Import the setDropdown function:

import { setDropdown } from 'dropdown-toggle';

Function Signature:

setDropdown(dropdownButton, dropdownContentWrapper, eventListener, hiddenClass = "hidden");

Parameters:

  • dropdownButton: HTMLElement - The button or trigger element that will toggle the dropdown content.
  • dropdownContentWrapper: HTMLElement - The wrapper element of the dropdown content that will be shown/hidden.
  • eventListener: "click" | "hover" - The type of event to listen for. It can either be "click" to toggle on click or "hover" to toggle on mouseover/mouseout.
  • hiddenClass: string (Optional, default: "hidden") - The class that hides the dropdown content. You can customize this class name if needed.

Example:

HTML:

<button id="dropdown-button">Toggle Dropdown</button>
<div id="dropdown-content" class="hidden">
    <!-- Dropdown content goes here -->
</div>

JavaScript:

import { setDropdown } from 'dropdown-toggle';

// Get the button and content elements
const dropdownButton = document.getElementById("dropdown-button");
const dropdownContentWrapper = document.getElementById("dropdown-content");

// Initialize the dropdown with a click event listener
setDropdown(dropdownButton, dropdownContentWrapper, "click");

You can also use the hover event listener instead:

setDropdown(dropdownButton, dropdownContentWrapper, "hover");

Example with Custom Hidden Class:

setDropdown(dropdownButton, dropdownContentWrapper, "click", "hidden-class");

Default Behavior:

  • Click Event: When the button is clicked, the dropdown content will toggle visibility.
  • Hover Event: When the button is hovered over, the dropdown content will appear, and it will disappear when the mouse leaves both the button and the content area.

Error Handling:

  • If an invalid eventListener type (other than click or hover) is passed, the function will log an error to the console.

License

MIT License