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

cleaner-select

v1.1.0

Published

A much cleaner select menu.

Downloads

2

Readme

A pretty clean and incredibly simple select menu patcher featuring search and descriptions. It has the following advantages over other libraries:

  • No other libraries required: Unlike some other libraries which require jQuery, this runs without any additional libraries needed. It is not dependent on any framework such as React which makes it ideal for frameworks such as Hotwired, as well as traditional ones like React.
  • Fairly lightweight: There are a few small tradeoffs for size to allow for true library independence, but we'd class 6kb as pretty small. Especially since you can dynamically import it in!
  • Search: Unlike the default select menu, you can quickly search for what you want.
  • Descriptions support: You can add descriptions to your options!
  • Accessible: A lot of effort was put into trying to make this as accessible as possible.
  • Mobile friendly: Automatically scales to fit nicely on mobile displays.
  • Simple interface: I'm sure you will agree after reading below!
  • Data tags powered: Whilst being very easy to port to frameworks such as React, this also makes it a perfect fit for server side frameworks like Rails.

Compatibility

cleaner-select works on any browser that supports ResizeObserver. This means if your browser was made after 2020 (I really hope it is), it should work fine. The one exception to this is Internet Explorer where you might still need to polyfill if you need to support it for whatever reason.

Usage

To use cleaner-select, you will need to import the module and then call the mount method on it with the select element.

// Make this your select element. For example, in Stimulus, it may be desirable to put all this in a controller and use `this.element` instead of a variable.
const selectElement = document.getElementById("select_menu");

// Move this variable whereever is appropriate for the framework you are using.
let destructor = () => {};

// You probably want to dynamically import this. No point making bundles bigger than needed for something dynamic.
import("cleaner-select").then(({ mount }) => {
    destructor = mount(selectElement);
});

Please note it is important that before you destroy the site of the page, you call the destructor. This will stop any leaks and destroy active menus.

cleaner-select will use the font attached to the body. This is useful because you may want to change this for accessibility reasons.

cleaner-select can recognise the following data attributes on select tags:

  • data-search-text: Replaces the default Search... text. Useful for internationalisation.
  • data-force-theme: Can be either light or dark to force a specific theme. By default, will use the system to figure out what theme it should use.
  • data-dark-highlight-color: The color used to highlight the background of a selected item in dark mode. Defaults to #0176ff.
  • data-light-highlight-color: The color used to highlight the background of a selected item in light mode. Defaults to #77b9fc.

Each option inside your select can also have an additional data-description attribute. This will include some additional information that will be rendered in the menu:

<select>
    <option data-description="This is a description!">Title</option>
</select>

description preview