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

react-dropdown-input

v0.1.11

Published

Displays a Bootstrap Input element with a DropdownMenu of possible options (similar to a combobox)

Downloads

5,689

Readme

npm package

React-Dropdown-Input

React-dropdown-input displays a "combobox" for React. More explicitly, it shows a text input box; once the user starts to type, a dropdown menu opens with matching options. The user can choose one of those options either by clicking one, or by using the arrow keys and hitting Enter.

It is styled with bootstrap, using the React-Bootstrap package; it actually displays a ReactBootstrap.Input element with a ReactBootstrap.DropdownMenu of possible options.

Demo

http://racingtadpole.github.io/react-dropdown-input/example/

Installation

npm install react-dropdown-input --save

Sample Usage

var searchNames = ['Sydney', 'Melbourne', 'Brisbane', 
    'Adelaide', 'Perth', 'Hobart'];
//...
<DropdownInput 
    options={searchNames}
    defaultValue={this.props.initialValue}
    menuClassName='dropdown-input'
    onSelect={this.handleSelectName}
    placeholder='Search...'
/>

In more detail...

The options are simply passed as a javascript array (or immutablejs object) to the options prop.

Supply one or both of these callbacks: onSelect & onChange.

  • onSelect fires when an option is clicked, or when Enter is pressed. It passes the object:

      { value: input text,
        index: option index, or -1 if user entered their own text and pressed Enter
      }
  • onChange fires whenever the input text value changes, either due to a click or typing. It passes the object:

      { value: input text }

Other props you can pass:

  • filter: a function that determines which options to show, given the input text (see defaultFilter in the code for the default).
  • menuClassName: a class for the menu, which you need for the css styling below; eg. 'dropdown-input'.
  • max: the maximum number of options to display.
  • maxText: text of a disabled MenuItem to show at the end of a list, if the max is exceeded replaces '#' with the number not shown; defaults to '+# more not shown'.

You can also pass <DropdownInput> all the properties that <ReactBootstrap.Input> allows, eg. ButtonAfter.

IMPORTANT NOTE ABOUT CSS

You need to turn off Bootstrap's hover highlighting css for this element; we do it manually using the active class instead. You may also need to re-enable the hover highlighting on the active class. Eg. in sass, add this:

.dropdown-input.dropdown-menu > li > a {
  &:hover,
  &:focus {
    color: $dropdown-link-color;  // #333
    background-color: $dropdown-bg; // #fff
  }
}
.dropdown-input.dropdown-menu > .active > a {
  &:hover,
  &:focus {
    text-decoration: none;
    color: $dropdown-link-hover-color;  // #fff
    background-color: $dropdown-link-hover-bg;  // #337ab7
  }
}

If you're showing maxText, you may also want to make sure it can't be selected too:

.dropdown-input.dropdown-menu>.active.disabled>a {
  text-decoration: none;
  color: $dropdown-link-disabled-color; // #777
  background-color: $dropdown-bg; // #fff
}

Release History

  • 0.1.0 Initial release
  • 0.1.1 Point to js (not jsx), update README
  • 0.1.2 Update example
  • 0.1.3 Align package.json version number with git tag
  • 0.1.4 Added maxText property
  • 0.1.5 Added eslint to dev
  • 0.1.6 Corrected number not shown
  • 0.1.7 Don't pass options and menuClassName props through to Input
  • 0.1.8 Added working tests using jest
  • 0.1.9 Use self-closing tag in ReadMe
  • 0.1.10 Remove extra comments, rename var as DropdownInput
  • 0.1.11 Prevent form submission if open