Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-selectize

furqanZafar24.4k3.0.1TypeScript support: included

A Stateless & Flexible Select component for React inspired by Selectize

react-component, select, selectize, multiselect, singleselect, simpleselect, tags, dropdown, combobox

readme

npm version Build Status Coverage Status

React Selectize

ReactSelectize is a stateless Select component for ReactJS, that provides a platform for the more developer friendly SimpleSelect & MultiSelect components.

Both SimpleSelect & MultiSelect have been designed to work as drop in replacement for the built-in React.DOM.Select component.

styles & features inspired by React Select & Selectize.

DEMO / Examples: furqanZafar.github.io/react-selectize

Motivation

  • existing components do not behave like built-in React.DOM.* components.
  • existing components synchronize props with state an anti pattern, which makes them prone to bugs & difficult for contributers to push new features without breaking something else.
  • more features.

Features

Deps

Peer Deps

  • create-react-class
  • react
  • react-dom
  • react-transition-group
  • react-dom-factories

Install

  • npm: npm install react-selectize

your package.json must look like this

{
    "dependencies": {
        "react": "^16.0.0-beta.2",
        "react-addons-css-transition-group": "^15.6.0",
        "react-addons-shallow-compare": "^15.6.0",
        "react-dom": "^16.0.0-beta.2",
        "react-dom-factories": "^1.0.0",
        "react-selectize": "^3.0.1",
        "react-transition-group": "^1.1.2"
    }
}

to include the default styles add the following import statement to your stylus file: @import 'node_modules/react-selectize/themes/index.css'

  • bower: bower install https://unpkg.com/react-selectize@3.0.1/bower.zip

  • 1998 script tag:

    <html>
    <head>
    <!-- PRELUDE -->
    <script src="http://www.preludels.com/prelude-browser-min.js" type="text/javascript" ></script>
    <script src="https://unpkg.com/prelude-extension@0.0.11/dist/index.min.js" type="text/javascript" ></script>
    
    <!-- REACT -->
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-with-addons.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script>
    <script type="text/javascript" src="https://unpkg.com/react-dom-factories@1.0.0"></script>
    
    <!-- optional dependency (only required with using the tether prop) -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.1.1/js/tether.min.js" type="text/javascript" ></script>
    
    <!-- REACT SELECTIZE -->
    <script src="https://unpkg.com/react-selectize@3.0.1/dist/index.min.js" type="text/javascript" ></script>
    
    <!-- THEMES (default, bootstrap3, material) -->
    <link rel="stylesheet" href="https://unpkg.com/react-selectize@3.0.1/dist/index.min.css"/>
    
    </head>
    <body>
    <div id="mount-node"></div>
    <script type="text/javascript">
     ReactDOM.render(
      React.createElement(reactSelectize.SimpleSelect, {
       style: {width: 300},
       tether: true,
       placeholder: "Select fruit", 
       options: [{label: "apple", value: "apple"}, {label: "banana", value: "banana"}]
      }), 
      document.getElementById("mount-node")
     );
    </script>
    </body>
    </html>

Usage (jsx)

import React, {Component} from 'react';
import {ReactSelectize, SimpleSelect, MultiSelect} from 'react-selectize';
.
.
.
<SimpleSelect placeholder="Select a fruit" onValueChange={value => alert(value)}>
  <option value = "apple">apple</option>
  <option value = "mango">mango</option>
  <option value = "orange">orange</option>
  <option value = "banana">banana</option>
</SimpleSelect>
.
.
.
// Note: options can be passed as props as well, for example
<MultiSelect
    placeholder = "Select fruits"
    options = {["apple", "mango", "orange", "banana"].map(
      fruit => ({label: fruit, value: fruit})
    )}
    onValuesChange = {value => alert(value)}
/>

Usage (livescript)

{create-factory}:React = require \react
{SimpleSelect, MultiSelect, ReactSelectize} = require \react-selectize
SimpleSelect = create-factory SimpleSelect
MultiSelect = create-factory MultiSelect
.
.
.
SimpleSelect do     
    placeholder: 'Select a fruit'
    options: <[apple mango orange banana]> |> map ~> label: it, value: it
    on-value-change: (value) ~>
        alert value
.
.
.
MultiSelect do
    placeholder: 'Select fruits'
    options: <[apple mango orange banana]> |> map ~> label: it, value: it
    on-values-change: (values) ~>
        alert values

Gotchas

  • the default structure of an option object is {label: String, value :: a} where a implies that value property can be of any equatable type

  • SimpleSelect notifies change via onValueChange prop whereas MultiSelect notifies change via onValuesChange prop

  • the onValueChange callback for SimpleSelect is passed 1 parameter. the selected option object (instead of the value property of the option object)

  • the onValuesChange callback for MultiSelect is passed 1 parameter an Array of selected option objects (instead of a collection of the value properties or a comma separated string of value properties)

  • both the SimpleSelect & MultiSelect will manage the open, search, value & anchor props using internal state, if they are not provided via props: when passing open, search, value or anchor via props, you must update them on*Change (just like in the case of standard react html input components)

    value = {state.selectedValue}
    onValueChange = {function(value){
      self.setState({selectedValue: value});
    }}
    search = {state.search}
    onSearchChange = {function(value){    
      self.setState({search: value});
    }}
  • when using custom option object, you should implement the uid function which accepts an option object and returns a unique id, for example:

    // assuming the type of our option object is:
    // {firstName :: String, lastName :: String, age :: Int}
    uid = {function(item){
      return item.firstName + item.lastName;    
    }}

    the uid function is used internally for performance optimization.

Development

  • npm install
  • npm start
  • visit localhost:8000
  • npm test , npm run coverage for unit tests & coverage
  • for production build/test run MINIFY=true gulp

changelog

React Selectize

3.0.1 / 29th July 2017

3.0.0 / 29th July 2017

  • support for React 16 & node 8.2.1 thanks @elisherer

2.1.0 / 1st December 2016

  • added on-blur-resets-input thanks @dcalhoun

2.0.2 / 11th May 2016

  • simple select accepts 0 as value (thanks @Nyalab)

v2.0.1 / 11th April 2016

v2.0.0 / 11th April 2016

  • switched to major version semver
  • added React@15.0 to peer deps
  • abandoned git flow branching model

v0.9.0 / 18th March 2016

  • added on-paste and value-from-paste props to SimpleSelect
  • added highlighted-uid and on-highlighted-uid-change props to track the current highlighted option
  • fixed a bug in dropdown-direction prop

v0.8.4 / 4th March 2016

  • added tether-props prop to customize the parent element (defaults to body)
  • expose highlighted-ui & on-highlighted-uid-change props for MultiSelect
  • fixed cancel-keyboard-event-on-selection prop

v0.8.3 / 2nd March 2016

  • "double click bug" fix

v0.8.2 / 2nd March 2016

  • added a new prop firstOptionIndexToHighlight to both Simple & MultiSelect
  • made the text in search field selectable

v0.8.1 / 19th February 2016

  • added cancelKeyboardEventOnSelection prop

v0.8.0 / 15th February 2016

  • added hideResetButton prop thanks @marchbnr
  • added renderToggleButton prop
  • added renderResetButton prop
  • bug fixes for IE 11 (#37)
  • renamed css classes (Breaking Changes)
Before Now
.control-wrapper .root-node
.react-selectize-selected-values .react-selectize-search-field-and-selected-values
.react-selectize-arrow-container .react-selectize-toggle-button-container
.react-selectize-arrow .react-selectize-toggle-button
.react-selectize-reset-container .react-selectize-reset-button-container
.react-selectize-reset .react-selectize-reset-button

v0.7.4 / 10th February 2016

v0.7.3 / 10th February 2016

  • css fixes for IE11

v0.7.2 / 8th February 2016

  • css improvements

v0.7.1 / 7th February 2016

  • bower support (using npmcdn)

v0.7.0 / 7th February 2016

  • umd build
  • added theme prop, 3 built-in themes (default, bootstrap3 & material)
  • Breaking Change: moved index.css from src/ directory to themes & dist directory
  • fixed issues with search & open props
  • Breaking Change: removed autosize prop

v0.6.2 / 2nd February 2016

  • hide the reset button if the select is empty
  • minor css improvements

v0.6.1 / 1st February 2016

  • disable keyboard selection when control or command keys are pressed
  • minor css improvements

v0.6.0 / 30th January 2016

  • added autofocus prop, that will automatically toggle the dropdown on load
  • removed the requirement for passing callback as the last argument to on-*-change props
  • fixed many focus & blur related issues
  • Breaking Change replaced on-enter prop with on-keyboard-selection-failed

v0.5.3 / 27th January 2016

  • introduced name & serialize props for form serialization

v0.5.2 / 26th January 2016

  • fixed option groups related bug

v0.5.1 / 25th January 2016

  • fixed tabbing (broken in v0.5.0, caused by refactoring related to blur method) (#25)

v0.5.0 / 25th January 2016

  • added tether prop
  • added blur method
  • close dropdown when nothing is selected on pressing the return key
  • namespaced css classes (Breaking Change) :

.dropdown-transition div is only used if any one (or both) of transition-enter, transition-leave props is / are specified, before the .dropdown div was always being wrapped in .dropdown-transition even if animation was not required.

Before Now
.arrow .react-selectize-arrow
.control .react-selectize-control
.dropdown .react-selectize-dropdown
.dropdown-transition .react-selectize-dropdown-container
.placeholder .react-selectize-placeholder
.reset .react-selectize-reset

v0.4.1 / 22nd January 2016

  • merged pull request (fixes an issue when unmounting with dropdown open) (#23), thanks @yuters

v0.4.0 / 21st January 2016

  • Added two new props delimiters & valuesFromPaste (#21)

v0.3.11 / 20th January 2016

  • fixed case sensitivity bug in MultiSelect. (#20)

v0.3.10 / 19th January 2016

  • fixed a bug where elements behind the dropdown were not clickable even though the dropdown was closed. (#18)

v0.3.9 / 18th January 2016

  • added on-enter :: Item -> Void prop, fired (with the highlighted-option) when the user hits the enter key (#19)

v0.3.8 / 16th January 2016

  • fixed a bug where passing restore-on-backspace prop wouldn't work in conjunction with render-no-results-found prop (#14)

v0.3.7 / 2nd November 2015

  • call on-blur only if the dropdown is open, thanks @alurim

v0.3.6 / 30th October 2015

  • updated package.json to include (React 0.14.0 and above) thanks @HankMcCoy

v0.3.5 / 16th October 2015

  • improved the default auto-size implementation

v0.3.4 / 14th October 2015

  • fixed a bug where the height of the ".dropdown-transition" element blocked the dom underneath (#6)

v0.3.3 / 13th October 2015

  • added missing dependency react-addons-css-transition-group to package.json

v0.3.2 / 13th October 2015

  • animated dropdown

v0.3.1 / 10th October 2015

  • added defaultValue prop for SimpleSelect & defaultValues prop for MultiSelect

v0.3.0 / 9th October 2015

  • upgraded to react 0.14.0
  • you can now return an object from the uid prop, made uid prop optional (even for custom option object)
  • added editable prop for SimpleSelect
  • fixed a bug where changing the selectable property would not rerender the option
  • wrap around when navigating options with arrow keys
  • close multi-select when there are no more options left to select

v0.2.6 / 8th October 2015

  • fixed a bug where selecting an option did not update the highlighted-uid (multi select). Thanks @edgarzakaryan

v0.2.5 / 28th September 2015

  • create index.css to fix style duplication when importing both SimpleSelect.css & MultiSelect.css
  • clicking on the arrow button toggles the dropdown
  • minor css tweaks

v0.2.4 / 26th September 2015

  • perf optimization, using result of props.uid method to compare items instead of deep equals
  • added HighlightedText component to help with search highlighting

v0.2.3 / 23rd September 2015

  • fixed a bug where passing a single child element would not show up in the dropdown
  • fixed other minor bugs identified by unit testing

v0.2.2 / 21st September 2015

  • fixed a bug where the input element would not autosize on entering search text
  • avoid firing onValueChange with undefined value when the user enters new search text

v0.2.1 / 20th September 2015

  • fixed React Warnings caused by missing key property for ValueWrapper components
  • allowing for wide range of react versions including 0.14.x-rc*
  • uid property for MultiSelect components

v0.2.0 / 19th September 2015

  • drop in replacement for React.DOM.Select, accepts options as children
  • added a new prop dropdownDirection, setting it to -1 forces the options menu to open upwards
  • option group support (as rows and columns)
  • updated the signature of refs.selectInstance.focus from a -> Void to a -> (a -> Void) -> Void, i.e. the focus function now accepts a callback as the first parameter which is fired when the options menu is visible
  • improved performance by implementing shouldComponentUpdate lifecycle method for *Wrapper classes, added uid :: (Eq e) => Item -> e prop
  • changed the signature of renderOption & renderValue props from Int -> Item -> ReactElement to Item -> ReactElement

v0.1.6 / 19th September 2015

  • introduced a new prop autosize, allows consumers to provide custom autosize logic for search input, the default implementation now supports nonmodern browsers

v0.1.4 / 15th September 2015

  • fixed option menu toggle on tap/click in mobile safari

v0.1.3 / 12th September 2015

  • fixed a bug where invoking the callback onValueChange synchronously would not close the options menu
  • fixed a bug where the SimpleSelect onValueChange callback was invoked even when the user selected the same item
  • minor tweaks & improvements to the default stylesheet

v0.1.2 / 11th September 2015

  • updated package.json added keywords & removed license property

v0.1.1 / 11th September 2015

  • added highlightFirstSelectableOption method to both the SimpleSelect & the MultiSelect components.
  • changed filterOptions signature for SimpleSelect from [Item] -> Item -> String -> [Item] to [Item]-> String -> [Item]