4.11.2 • Published 2 months ago

react-dropdown-select v4.11.2

Weekly downloads
16,199
License
MIT
Repository
github
Last release
2 months ago

react-dropdown-select

Customisable dropdown select for react

npm.io npm.io Coverage Status Codacy Badge

Features

  • configurable via props
  • total custom components overrides for all internals via render prop callbacks (with access to internal props, state and methods)
  • stylable via css (or custom components)
  • portal support for rendering dropdown outside local DOM tree. e.g. in document.body
  • auto position
  • small bundle size

Installation

npm install --save react-dropdown-select

Web site

Web site, docs and demo

Motivation

react-select is very nice, but sometimes project requirements are beyond it's abilities

Usage

import:

import Select from "react-dropdown-select";

and use as:

const options = [
  {
    value: 1,
    label: 'Leanne Graham'
  },
  {
    value: 2,
    label: 'Ervin Howell'
  }
];

<Select options={options} onChange={(values) => this.setValues(values)} />;

If your options don't have value and label fields, include labelField and valueField in the props:

const options = [
  {
    id: 1,
    name: 'Leanne Graham'
  },
  {
    id: 2,
    name: 'Ervin Howell'
  }
];

<Select
  options={options}
  labelField="name"
  valueField="id"
  onChange={(values) => this.setValues(values)}
/>;

options and onChange are the minimum required props

Help and Contributions

How to help/contribute

  • fix issues, pull request are very welcome
  • write, improve docs
  • write tests (we use jest)
  • suggest features and improvements

Demo

Edit react-dropdown-select

API

Component props

PropTypeDefaultDescription
valuesarray[]Selected values
optionsarray[]Available options, (option with key disabled: true will be disabled)
keepOpenboolfalseIf true, dropdown will always stay open (good for debugging)
defaultMenuIsOpenboolfalseIf true, dropdown will be open by default
autoFocusboolfalseIf true, and searchable, dropdown will auto focus
clearOnBlurbooltrueIf true, and searchable, search value will be cleared on blur
clearOnSelectbooltrueIf true, and searchable, search value will be cleared upon value select/de-select
namestringnullIf set, input type hidden would be added in the component with the value of the name prop as name and select's values as value
requiredboolfalseIf set, input type hidden would be added in the component with required prop as true/false
patternstringnullIf set, input type hidden would be added in the component with pattern prop as regex
dropdownGapnumber5Gap between select element and dropdown
multiboolfalseIf true - will act as multi-select, if false - only one option will be selected at the time
placeholderstring"Select..."Placeholder shown where there are no selected values
addPlaceholderstring""Secondary placeholder on search field if any value selected
disabledboolfalseDisable select and all interactions
styleobject{}Style object to pass to select
classNamestringCSS class attribute to pass to select
loadingboolfalseLoading indicator
clearableboolfalseClear all indicator
searchablebooltrueIf true, select will have search input text
separatorboolfalseSeparator line between close all and dropdown handle
dropdownHandlebooltrueDropdown handle to open/close dropdown
dropdownHeightstring"300px"Minimum height of a dropdown
directionstring"ltr"direction of a dropdown "ltr", "rtl" or "auto"
searchBystringlabelSearch by object property in values
sortBystringnullSort by object property in values
labelFieldstring"label"Field in data to use for label
valueFieldstring"value"Field in data to use for value
colorstring"#0074D9"Base color to use in component, also can be overwritten via CSS
closeOnScrollboolfalseIf true, scrolling the page will close the dropdown
closeOnSelectboolfalseIf true, selecting option will close the dropdown
closeOnClickInputboolfalseIf true, clicking input will close the dropdown if you are not searching.
dropdownPositionstring"bottom"Available options are "auto", "top" and "bottom" defaults to "bottom". Auto will adjust itself according Select's position on the page
keepSelectedInListbooltrueIf false, selected item will not appear in a list
portalDOM elementfalseIf valid dom element specified - dropdown will break out to render inside the specified element
createboolfalseIf true, select will create value from search string and fire onCreateNew callback prop
backspaceDeletebooltrueIf true, backspace key will delete last value
createNewLabelstring"add {search}"If create set to true, this will be the label of the "add new" component. {search} will be replaced by search value
disabledLabelstring"disabled"Label shown on disabled field (after) the text
selectAllboolfalseAllow to select all
selectAllLabelstring"Select all"Label for "Select all"
clearAllLabelstring"Clear all"Label for "Clear all"
additionalPropsobjectnullAdditional props to pass to Select

Callback props

by using renderer props to override components some of the functionality will have to be handled manually with a help of internal props, states and methods exposed

PropTypeDefaultDescription
onChangefuncOn values change callback, returns array of values objects
onDropdownClosefuncFires upon dropdown close
onDropdownOpenfuncFires upon dropdown open
onCreateNewfuncFires upon creation of new item if create prop set to true
onClearAllfuncFires upon clearing all values (via custom renderers)
onSelectAllfuncFires upon selecting all values (via custom renderers)
onDropdownCloseRequestfuncundefinedFires upon dropdown closing state, stops the closing and provides own method close()
contentRendererfuncOverrides internal content component (the contents of the select component)
itemRendererfuncOverrides internal item in a dropdown
noDataRendererfuncOverrides internal "no data" (shown where search has no results)
optionRendererfuncOverrides internal option (the pillow with an "x") on the select content
inputRendererfuncOverrides internal input text
loadingRendererfuncOverrides internal loading
clearRendererfuncOverrides internal clear button
separatorRendererfuncOverrides internal separator
dropdownRendererfuncOverrides internal dropdown component
dropdownHandleRendererfuncOverrides internal dropdown handle
searchFnfuncundefinedOverrides internal search function
handleKeyDownFnfuncundefinedOverrides internal keyDown function

License

MIT

4.11.2

2 months ago

4.11.1

3 months ago

4.11.0

4 months ago

4.9.4

10 months ago

4.10.0

9 months ago

4.9.3

1 year ago

4.9.0

2 years ago

4.8.4

2 years ago

4.8.1

2 years ago

4.8.3

2 years ago

4.8.2

2 years ago

4.8.0

2 years ago

4.7.4

3 years ago

4.7.3

3 years ago

4.7.2

3 years ago

4.7.1

3 years ago

4.7.0

3 years ago

4.6.1

3 years ago

4.6.0

3 years ago

4.5.2

4 years ago

4.5.1

4 years ago

4.5.0

4 years ago

4.4.2

4 years ago

4.4.1

4 years ago

4.4.0

4 years ago

4.3.1

4 years ago

4.3.0

4 years ago

4.2.0

4 years ago

4.1.0

4 years ago

4.1.1

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.12.0

4 years ago

3.11.1

4 years ago

3.11.0

4 years ago

3.10.0

4 years ago

3.9.0

4 years ago

3.8.1

4 years ago

3.8.0

4 years ago

3.7.0

4 years ago

3.6.8

4 years ago

3.6.7

4 years ago

3.6.6

4 years ago

3.6.5

4 years ago

3.6.4

5 years ago

3.6.3

5 years ago

3.6.2

5 years ago

3.6.1

5 years ago

3.6.0

5 years ago

3.5.1

5 years ago

3.5.0

5 years ago

3.3.4

5 years ago

3.3.3

5 years ago

3.3.2

5 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.6

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.6.2

5 years ago

1.6.0

5 years ago

1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.4.10

5 years ago

1.4.9

5 years ago

1.4.8

5 years ago

1.4.7

5 years ago

1.4.6

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago