react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Pressing backspace when item is selected already

Open honzahk opened this issue 10 years ago • 4 comments

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:

  1. select an option ( onChange param value == { value: X, label: Y} )
  2. click clearing cross ( onChange param value == null ) - which is expected result

Scenario B:

  1. select an option ( onChange param value == { value: X, label: Y} )
  2. press backspace ( onChange param value == []) - expected value == null

Explanation: 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

honzahk avatar Sep 13 '16 14:09 honzahk

+1 Same situation and solving similarly with lodash isArray method.

petrgazarov avatar Oct 07 '16 19:10 petrgazarov

I've created a pull request to fix this issue: https://github.com/JedWatson/react-select/pull/1381

richardhills avatar Nov 22 '16 12:11 richardhills

I am facing the same problem in v2.1.0

smilexu avatar Oct 18 '18 09:10 smilexu

This seems to be the same issue as https://github.com/JedWatson/react-select/issues/2682

IanVS avatar Nov 20 '18 19:11 IanVS