diff --git a/.eslintrc b/.eslintrc
index 91a9bdce67..f4253545b1 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -9,6 +9,7 @@
],
"rules": {
"curly": [2, "multi-line"],
+ "jsx-quotes": 1,
"no-shadow": 0,
"no-trailing-spaces": 0,
"no-underscore-dangle": 0,
@@ -17,7 +18,6 @@
"quotes": [2, "single", "avoid-escape"],
"react/jsx-boolean-value": 1,
"react/jsx-no-undef": 1,
- "react/jsx-quotes": 1,
"react/jsx-sort-prop-types": 1,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1,
diff --git a/.travis.yml b/.travis.yml
index 5989f0384e..8278823bda 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,6 @@
sudo: false
language: node_js
node_js:
- - "0.10"
- - "0.11"
- - "0.12"
- - "iojs-v2.5.0"
+ - "v4"
script:
- npm run coveralls
diff --git a/CHANGES.md b/CHANGES.md
new file mode 100644
index 0000000000..a224e0233e
--- /dev/null
+++ b/CHANGES.md
@@ -0,0 +1,32 @@
+# Changes
+
+## Breaking Changes
+
+Major API changes to Component props, SingleValue and Value have been merged
+
+The component is now "controlled", which means you have to pass value as a prop and always handle the `onChange` event. See https://facebook.github.io/react/docs/forms.html#controlled-components
+
+Using values that aren't in the `options` array is still supported, but they have to be full options (previous versions would expand strings into `{ label: string, value: string }`)
+
+Options & Value components get their label as their Children
+
+new `simpleValue` prop for when you want to deal with values as strings or numbers (legacy behaviour, defaults to false). onChange no longer receives an array of expanded values as the second argument.
+
+`onOptionLabelClick` -> `onValueClick`
+
+## New Select.Async Component
+
+`loadingPlaceholder` prop
+`autoload` changed to `minimumInput` and now controls the minimum input to load options
+`cacheAsyncResults` -> `cache` (new external cache support) - defaults to true
+
+## Fixes & Other Changes
+
+new `ignoreAccents` prop (on by default), thanks [Guilherme Guerchmann](https://github.com/Agamennon)
+new `escapeClearsValue` prop (on by default)
+bug where the filter wouldn't be reset after blur
+complex option values are much better supported now, won't throw duplicate key errors and will serialize to the input correctly
+
+## Notes
+
+`undefined` default props are no longer declared
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 066f1c701b..ea3dc8f3a2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -3,6 +3,17 @@
Thanks for your interest in React-Select. All forms of contribution are
welcome, from issue reports to PRs and documentation / write-ups.
+* We use node.js v4 for development and testing. Due to incompatibilities with
+JSDOM and older versions of node.js, you'll need to use node 4 to run the
+tests. If you can't install node v4 as your "default" node installation, you
+could try using [nvm](https://github.com/creationix/nvm) to install multiple
+versions concurrently.
+* If you're upgrading your node.js 0.x environment, it's sometimes necessary
+to remove the node_modules directory under react-select, and run npm install
+again, in order to ensure all the correct dependencies for the new version
+of node.js (as a minimum, you'll need to remove the `jsdom` module, and
+reinstall that).
+
Before you open a PR:
* If you're planning to add or change a major feature in a PR, please ensure
diff --git a/HISTORY.md b/HISTORY.md
index 9cb8d67b78..afc09c712c 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,10 +1,143 @@
# React-Select
-## v0.6.5 / 2015-08-26
+## v1.0.0-beta6 / 2015-11-29
+
+* Test suite complete and passing, with a couple of minor fixes thanks to @bruderstein
+
+## v1.0.0-beta5 / 2015-11-08
+
+* Fixes issues relating to serializing simple values into the hidden field
+
+## v1.0.0-beta4 / 2015-11-08
+
+* New default styles that match [Elemental UI](http://elemental-ui.com) and look right at home in the new [KeystoneJS Admin UI](http://keystonejs.com)
+
+We're potentially going to ship some theme stylesheets in the future, shout out on GitHub if this interests you.
+
+## v1.0.0-beta3 / 2015-11-08
+
+* The selected value populated in the hidden field has been fixed (was `"[object Object]"` before)
+* Added new `autofocus` prop
+* Fixed duplicate key error for options and values with duplicate `value` properties
+* SCSS variables now have `!default` so you can override them
+
+## v1.0.0-beta2 / 2015-11-06
+
+Changed since beta 1:
+
+* Async options cache works again
+* New style props for custom styling the component without modifying css classes: `style` `wrapperStyle` `menuStyle` `menuContainerStyle`
+* The menu opens and closes correctly when `searchable={false}`, there is still some work to do on this use-case
+
+## v1.0.0-beta1 / 2015-11-06
+
+This is a complete rewrite. Major changes include:
+
+* Everything is simpler (I'm nearly done and the source code is only 60% of the size of the last version)
+* No more timeouts or weird handlers, the restructuring has let me make everything more straight-forward
+* The options array is no longer preprocessed into state, just retrieved from props
+* The values array is now initialised in the Options array during render, and not stored in state, which along with the change to options makes the component more reliable and fixes issues with props not updating correctly
+* The component no longer stores its own value in state (ever) - it needs to be passed as a prop and handled with `onChange`.
+* Complex values are now enabled by default (so you're passed the option object, not its value); you can enable the legacy mode with a prop
+* The Value and Option components have been cleaned up as well for consistency
+* The hidden `` field is now optional and the component is better suited to use in a rich React.js app than it was
+* You can disable options filtering to do the filtering externally with `onInputChange`
+* Accents on characters can now be ignored
+* The `asyncOptions` prop has been replaced by a new wrapper component: `Select.Async`
+
+Note that "Tag mode" (creating options on the fly) isn't reimplemented yet.
+
+A full guide to the breaking changes and new features will be written up soon. In the meantime please see the new examples.
+
+## v0.9.1 / 2015-11-01
+
+* added; new Contributors example w/ async options loading and custom value / label keys
+* fixed; several issues with custom `valueKey` and `labelKey` props
+* fixed; autoload now loads options with no search input
+
+## v0.9.0 / 2015-10-29
+
+* added; SCSS stylesheets!
+* improved; Options rendering should be more performant
+* breaking change; Custom `Option` components now need to pass their `option` prop to event handlers; see [this commit](https://github.com/JedWatson/react-select/commit/89af12a80a972794222b193a767f44234bbe9817) for an example of the required change.
+
+## v0.8.4 / 2015-10-27
+
+* fixed; LESS math operations now work with --strict-math=on, thanks [Vincent Fretin](https://github.com/vincentfretin)
+
+## v0.8.3 / 2015-10-27
+
+* fixed; IE issue where clicking the scrollbar would close the menu, thanks [Pete Nykänen](https://github.com/petetnt)
+
+## v0.8.2 / 2015-10-22
+
+* added; Promise support for `loadAsyncOptions`, thanks [Domenico Matteo](https://github.com/dmatteo)
+
+## v0.8.1 / 2015-10-20
+
+* fixed; `loadAsyncOptions` raises TypeError in setup, see #439 for details, thanks [Pancham Mehrunkar](https://github.com/pancham348)
+
+## v0.8.0 / 2015-10-19
+
+This release contains significant DOM structure and CSS improvements by @jossmac, including:
+
+* no more `position: absolute` for inner controls
+* `display: table` is used for layout, which works in IE8 and above, and [all other modern browsers](http://caniuse.com/#feat=css-table)
+* less "magic numbers" used for layout, should fix various browser-specific alignment issues
+* clear "x" control now animates in
+* clearer `.Select--multi` className replaces `.Select.is-multi`
+* new height & theme variables
+* "dropdown" indicator chevron is no longer displayed for multi-select controls
+
+There are no functional changes, but if you've forked the LESS / CSS to create your own theme you'll want to pay close attention to PR #527 when upgrading to this version.
+
+## v0.7.0 / 2015-10-10
+
+React Select is updated for React 0.14. If you're still using React 0.13, please continue to use `react-select@0.6.x`. There are no functional differences between v0.7.0 and v0.6.12.
+
+Additionally, our tests now require Node.js 4.x. If you are developing `react-select`, please make sure you are running the latest version of node.
+
+Thanks to @bruderstein, @dmatteo and @hull for their help getting these updates shipped!
+
+## v0.6.12 / 2015-10-02
+
+* added; `labelKey` and `valueKey` props, so you can now use different keys in `option` objects for the label and value
+* fixed; additional `isMounted()` checks in timeouts
+* fixed; componentDidUpdate timeout is reset correctly, see #208 and #434, thanks [Petr Gladkikh](https://github.com/PetrGlad)
+* fixed; mousedown event on scrollbar in menu no longer hides it, thanks [Yishai Burt](https://github.com/burtyish)
+
+## v0.6.11 / 2015-09-28
+
+* added; `isLoading` prop, allows indication of async options loading in situations where more control is required, thanks [Jon Gautsch](https://github.com/jgautsch)
+
+## v0.6.10 / 2015-09-24
+
+* fixed; a build issue with the previous release that prevented the stylesheet being generated / included
+* fixed; a LESS syntax issue, thanks [Bob Cardenas](https://github.com/bcardi)
+
+## v0.6.9 / 2015-09-19
+
+* added; `style` key for package.json, thanks [Stephen Wan](https://github.com/stephen)
+* added; `onInputChange` handler that returns the current input value, thanks [Tom Leslie](https://github.com/lomteslie)
+* fixed; simplifying handleKey function & preventDefault behaviour, thanks [davidpene](https://github.com/davidpene)
+* fixed; Display spinner while auto-loading initial data, thanks [Ben Jenkinson](https://github.com/BenJenkinson)
+* fixed; better support for touch events, thanks [Montlouis-Calixte Stéphane](https://github.com/bulby97)
+* fixed; prevent value splitting on non-multi-value select, thanks [Alan R. Soares](https://github.com/alanrsoares)
+
+## v0.6.8 / 2015-09-16
+
+* fixed; broader range of allowed prereleases for React 0.14, including rc1
+* fixed; preventing backspace from navigating back in the browser history, thanks [davidpene](https://github.com/davidpene)
+
+## v0.6.7 / 2015-08-28
+
+* fixed; missing styles for `.Select-search-prompt` and `.Select-searching` issues, thanks [Jaak Erisalu](https://github.com/jaakerisalu) and [davidpene](https://github.com/davidpene)
+
+## v0.6.6 / 2015-08-26
* fixed; issue in Chrome where clicking the scrollbar would close the menu, thanks [Vladimir Matsola](https://github.com/vomchik)
-## v0.6.4 / 2015-08-24
+## v0.6.5 / 2015-08-24
* fixed; completely ignores clicks on disabled items, unless the target of the click is a link, thanks [Ben Stahl](https://github.com/bhstahl)
diff --git a/README.md b/README.md
index 19e8227e27..0a9df1687c 100644
--- a/README.md
+++ b/README.md
@@ -7,13 +7,26 @@ React-Select
A Select control built with and for [React](http://facebook.github.io/react/index.html). Initially built for use in [KeystoneJS](http://www.keystonejs.com).
+## New version 1.0.0-beta
+
+I've nearly completed a major rewrite of this component (see issue [#568](https://github.com/JedWatson/react-select/issues/568) for details and progress). The new code has been merged into `master`, and `react-select@1.0.0-beta` has been published to npm and bower.
+
+1.0.0 has some breaking changes. The documentation below still needs to be updated for the new API; notes on the changes can be found in [CHANGES.md](https://github.com/JedWatson/react-select/blob/master/CHANGES.md) and will be finalised into [HISTORY.md](https://github.com/JedWatson/react-select/blob/master/HISTORY.md) soon.
+
+Our tests need some major updates to work with the new API (see [#571](https://github.com/JedWatson/react-select/issues/571)) and are causing the build to fail, but the component is stable and robust in actual usage.
+
+Testing, feedback and PRs for the new version are appreciated.
+
+
## Demo & Examples
Live demo: [jedwatson.github.io/react-select](http://jedwatson.github.io/react-select/)
-To build the examples locally, run:
+The live demo is still running `v0.9.1`.
-```
+To build the **new 1.0.0** examples locally, clone this repo then run:
+
+```javascript
npm install
npm start
```
@@ -21,22 +34,11 @@ npm start
Then open [`localhost:8000`](http://localhost:8000) in a browser.
-## Project Status
-
-This project is quite stable and ready for production use, however there are plans to improve it including:
-
-- CSS Styles and theme support (working, could be improved)
-- Documentation website (currently just examples)
-- Custom options rendering (in progress)
-
-It's loosely based on [Selectize](http://brianreavis.github.io/selectize.js/) (in terms of behaviour and user experience) and [React-Autocomplete](https://github.com/rackt/react-autocomplete) (as a native React Combobox implementation), as well as other select controls including [Chosen](http://harvesthq.github.io/chosen/) and [Select2](http://ivaynberg.github.io/select2/).
-
-
## Installation
The easiest way to use React-Select is to install it from NPM and include it in your own React build process (using [Browserify](http://browserify.org), etc).
-```
+```javascript
npm install react-select --save
```
@@ -57,7 +59,7 @@ The `value` property of each option should be set to either a string or a number
When the value is changed, `onChange(newValue, [selectedOptions])` will fire.
-```
+```javascript
var Select = require('react-select');
var options = [
@@ -100,7 +102,7 @@ The select control will intelligently cache options for input strings that have
Unless you specify the property `autoload={false}` the control will automatically load the default set of options (i.e. for `input: ''`) when it is mounted.
-```
+```javascript
var Select = require('react-select');
var getOptions = function(input, callback) {
@@ -117,6 +119,40 @@ var getOptions = function(input, callback) {
}, 500);
};
+
+```
+
+### Async options with Promises
+
+`asyncOptions` now supports Promises, which can be used in very much the same way as callbacks.
+
+Everything that applies to `asyncOptions` with callbacks still applies to the Promises approach (e.g. caching, autoload, ...)
+
+An example using the `fetch` API and ES6 syntax, with an API that returns an object like:
+
+```javascript
+import Select from 'react-select';
+
+/*
+ * assuming the API returns something like this:
+ * const json = [
+ * { value: 'one', label: 'One' },
+ * { value: 'two', label: 'Two' }
+ * ]
+ */
+
+const getOptions = (input) => {
+ return fetch(`/users/${input}.json`)
+ .then((response) => {
+ return response.json();
+ }).then((json) => {
+ return { options: json };
+ });
+}
+
```
+### Async options loaded externally
+
+If you want to load options asynchronously externally from the `Select` component, you can have the `Select` component show a loading spinner by passing in the `isLoading` prop set to `true`.
+
+```javascript
+var Select = require('react-select');
+
+var isLoadingExternally = true;
+
+
+```
+
### Filtering options
You can control how options are filtered with the following properties:
@@ -147,45 +199,64 @@ For multi-select inputs, when providing a custom `filterOptions` method, remembe
### Further options
- Property | Type | Description
-:-----------------------|:--------------|:--------------------------------
- addLabelText | string | text to display when allowCreate is true
- allowCreate | bool | allow new options to be created in multi mode (displays an "Add \