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

dropdown-select

v3.1.1

Published

A Dropdown Select Control for React JS

Downloads

42

Readme

dropdown-select

A group of dropdown select controls for React JS.

Demo

Live Demo:

Features

  • Multi Select
  • Async Select
  • Auto Complete
  • Minimal Interface
  • Can Control using Keyboard
  • Works with redux-form

Installation

Add package using Yarn or Npm.

yarn add dropdown-select
npm install dropdown-select

Usage

Import dropdown select controls and its styles into your component.

import { Select, AsyncSelect, MultiSelect } from 'dropdown-select';
import 'dropdown-select/dist/css/dropdown-select.css';

Alternatively, you can import the styles from .scss files as follows:

@import '~dropdown-select/dist/css/dropdown-select.css';

Simple Select: (with array of string options)

<Select
  options={['option1', 'option2', ...]}
  />

Simple Select: (with array of object options)

options = [
  {
    label: 'label1',
    value: 'value1'
  },
  {
    label: 'label2',
    value: 'value2'
  },
]
<Select options={options} labelKey="label" valueKey="value" />

Async Select:

<AsyncSelect fetchOptions={this.fetchOptions} />

Multi Select: (Checkboxed Options)

It accepts and returns array of options

<MultiSelect options={[]} />

Using simple select as custom component in redux-form

renderSelectField({ input, options, meta: { touched, error } }) {
  return (
    <div>
      <SimpleSelect
        {...input}
        options={options}
        labelKey="name"
        valueKey="id"
        />
      {touched && error && <span className="error">{error}</span>}
    </div>
  );
}

render() {
  const { handleSubmit } = this.props
  const options = []

  return (
    <form onSubmit={handleSubmit}>
      <Field
        name="fieldName"
        options={options}
        component={this.renderSelectField}
        />
      <button type="submit">Submit</button>
    </form>
  );
}

Functional Properties:

| Property | Type | Default | Description | | ------------ | ----------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------- | | autoComplete | boolean | true | Enables / Disables auto complete options while typing | | disabled | boolean | false | To disable the select or not | | fetchOptions | function | undefined | Async Select property, the control calls this function when input value changed | | labelKey | string | undefined | Used to identify the option label | | options | array | [] | Array of strings (OR) Array of objects | | onChange | function | undefined | Control onChange event handler, this function will be called with new option as parameter | | placeholder | string / array | string | Input placeholder, for Multi Select you can pass an array with singular and plural name for items. Eg: ['Person', 'People'] | | tabIndex | string | undefined | tabIndex of the control | | value | string / object / array | '' or [] | For Multi select, the default value is [] and for Simple and Async select, the default value is empty string | | valueKey | string | undefined | Used to identify the option value |

Style Properties:

| Property | Type | Default | Description | | ---------------- | ------ | --------- | ------------------------------------------ | | className | String | undefined | Overrides outer control styles | | inputClassName | String | undefined | Overrides control input styles | | optionsClassName | String | undefined | Overrides control options container styles | | optionClassName | String | undefined | Overrides control option styles |


Notes on Performance:

  • Use <Select /> if options length < 200

  • Use <AsyncSelect /> if options length > 200

Further Reading

For advanced use cases, please refer react-select