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

selectr

v2.0.3

Published

Selectr is a jQuery plugin that aims to accomplish a seemingly simple task: make a select box that doesn't suck.

Downloads

17

Readme

NOTE: This package is unmaintained, but I'll do my best to tend to any PRs that are submitted. Why? I've found it much easier to implement the same thing natively with whichever framework/library I'm using (Knockout, Angular, etc.).

Selectr

Selectr is a jQuery plugin that aims to accomplish a seemingly simple task: make a select box that doesn't suck.

It currently supports ctrl+click, search, color-coding, and selection limiting (multi-selects). In modern browsers (Chrome, Safari, FF, IE11), selectr ensures your source element's options and itself remain in sync. If you require this behavior (e.g. because you're using a data-binding framework of some sort) in legacy IE, see Legacy Browser Caveats below.

It is built using Bootstrap components, and is written in CoffeeScript and SCSS; if your project is not using Bootstrap, you should use selectrWithPolyfill.css -- which includes all of selectr's styles along with the relevant Bootstrap styles (scoped to avoid conflicting with existing styles, of course) -- or write your own styles.

Selectr was heavily inspired by select2 and the label/assignee/milestone dropdowns in Github's issue tracker.

Click here to view demo

Installation

Selectr can be consumed as a CommonJS module, AMD module, or global var. It is built with webpack and uses the style loader, so you do not need to worry about including a stylesheet.

NOTE: CommonJS and AMD modules still merely extend jQuery, so this will not work

var selectr = require('selectr')

selectr('#my-selectr')

you must instead use the following

require('selectr')
$ = require('jquery')

$.selectr('#my-selectr')

NPM / Bower

npm install selectr

bower install selectr

Usage

To use selectr, simply fire it using jQuery

$('select').selectr()

Multi selects

To make selectr a multi select, simply use the multiple attribute on your select element as you would with regular HTML.

<select name="foo" multiple>

Color coding

Selectr supports color coding of options by setting the data-selectr-color attribute on the option. Any valid CSS color is supported, i.e. hex, rgba(a), hsl(a).

Ex.

<option data-selectr-color="rgb(255, 255, 255)" value="foo">Foo</option>

Options and defaults

title:                  'Select Options'
noMatchingOptionsText:  'No options found'
placeholder:            'Search'
resetText:              'Clear All'
width:                  '300px'
maxListHeight:          '250px'
tooltipBreakpoint:      25 # min length of option name to show tooltip on
maxSelection:           Infinity
panelStyle:				'default'
alwaysShowFooter:		false

To pass options to selectr, you may use an HTML5 data-* attribute, or an options object passed to the initialization function.

Using HTML5 data attributes

<select name="foo" data-selectr-opts='{ "title": "Foo Bar", "placeholder": "Bax Qux", "maxSelection": 5, ... }' multiple>

NOTE: Attribute must be valid JSON; that means quoted keys as well as values. This is to avoid using eval().

But wait! I need quotes/apostrophes in my title! Easy fix. Use the ASCII code, i.e. instead of ' use &#39; and instead of " use &quot;.

Using an options object

$('select').selectr({ title: 'Foo Bar', placeholder: 'Baz Qux', ... });

NOTE: Order of precedence

HTML5 data attributes take precedence over the options object. This allows you to pass certain parameters that should apply to most/all selectr instances, and "fill in the blanks" or override those options with the data-selectr-opts attribute. See demo file for an example.

Compatiblity

Requires jQuery 1.8.3+

Tested in the following browsers:

  • Chrome
  • Firefox
  • IE 8+*

*Legacy Browser (IE8-10) caveats

selectr uses MutationObservers to update the list of options, which are unsupported by older browsers. Instead of hacking together a buggy solution, I've opted to require that, in order to sync the options list in older browsers, a change event be manually fired on the source select element when the options change.