-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multivalue - Removing all selected items send null on onChange #4021
Comments
I troubleshooted it for you in codesandbox and can confirm that this wasn't an issue until version 3.0. On versions 2.4.4 and lower, this was not an issue. With all the other dependencies updated to their latest stable versions...
Hopefully that helps you get to the bottom of the issue so you can fix it for us and we can stop using an old version of react-select. Here is the link to the codesandbox with all the dependencies updated to their latest versions including react-select so you can see for yourself the error that triggers after selecting an option and then unselecting it... https://codesandbox.io/s/react-select-issue-4021-lfysf You can fork it and test it with the versions I mentioned above to confirm everything. Here is a link to my working version that still uses react-select 2.4.4... |
Greetings everyone. This is expected behavior per the upgrade notes to V3 #3585 (Taken from the above link) Normalized ValuesAt the moment, if no value is specified by the consumer, it's instantiated as a null value, regardless of whether the select isMulti or not. When isMulti is false this is fine. On selection of an option, the value becomes an object, and on clearing of said value, it returns to being null. However when isMulti is true, this becomes more inconsistent. On selection of options, the value becomes an array of options, removing values extricates them from this array, removing the last selected value results in an empty array, instead of the initial base state of null. We rectify this in 3.0.0, on removal of all selected values in an isMulti Select, the value passed to onChange is This is both related and also the exact opposite behavior of another known issue that exists that has the value returned as I will be closing this ticket out, and welcome any questions or concerns if there are any |
Thanks for the detailed answer |
Hello,
found on version 3.1.0 (didn't try below, except on the one given in the default sandbox and is not reproducible).
When removing all the selected options from a multivalue select, an error is raised (eg: Cannot read property 'map' of null) when you want to use array methods on event received on onChange property
prerequisites:
sandbox: https://codesandbox.io/s/react-codesandboxer-example-tvb2l
scenario:
actual result:
exception thrown =>
TypeError
Cannot read property 'map' of null
expected result:
event received is an empty array
The text was updated successfully, but these errors were encountered: