3.1.1 • Published 5 years ago

dropdown-select v3.1.1

Weekly downloads
26
License
ISC
Repository
github
Last release
5 years ago

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:

PropertyTypeDefaultDescription
autoCompletebooleantrueEnables / Disables auto complete options while typing
disabledbooleanfalseTo disable the select or not
fetchOptionsfunctionundefinedAsync Select property, the control calls this function when input value changed
labelKeystringundefinedUsed to identify the option label
optionsarray[]Array of strings (OR) Array of objects
onChangefunctionundefinedControl onChange event handler, this function will be called with new option as parameter
placeholderstring / arraystringInput placeholder, for Multi Select you can pass an array with singular and plural name for items. Eg: 'Person', 'People'
tabIndexstringundefinedtabIndex of the control
valuestring / object / array'' or []For Multi select, the default value is [] and for Simple and Async select, the default value is empty string
valueKeystringundefinedUsed to identify the option value

Style Properties:

PropertyTypeDefaultDescription
classNameStringundefinedOverrides outer control styles
inputClassNameStringundefinedOverrides control input styles
optionsClassNameStringundefinedOverrides control options container styles
optionClassNameStringundefinedOverrides 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

3.1.1

5 years ago

3.1.0

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.0.5

6 years ago

2.1.0

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago