Hello, i think i have found a bug. Its important to have some option selected first to reproduce the behavior!
My component:
<Select
options={datasource}
value={this.state.value}
onChange={value=>{
let isArray = value == null ? false : value.constructor == Array
this.setState({value: isArray ? null : value})
}}
/>
Scenario A:
value == { value: X, label: Y} )value == null ) - which is expected resultScenario B:
value == { value: X, label: Y} )value == []) - expected value == nullExplanation:
I mean, when you click clearing cross OR press backspace when the Select has MULTI enabled, value param is the same in both cases - an empty array. Thats correct, the result should be 0-N items, an array.
When you do this with SINGLE-value Select, clicking cross sets value param to null BUT pressing backspace sets it to empty array instead of null, which seems inconsistent and a bit confusing to me. Thats why there is the isArray condition in my onChange method. The result should be null/object, not an array.
Is this a bug or not?
Thanks for your answer in advance.
Good job & keep it up!
HK
+1 Same situation and solving similarly with lodash isArray method.
I've created a pull request to fix this issue: https://github.com/JedWatson/react-select/pull/1381
I am facing the same problem in v2.1.0
This seems to be the same issue as https://github.com/JedWatson/react-select/issues/2682
Most helpful comment
I've created a pull request to fix this issue: https://github.com/JedWatson/react-select/pull/1381