-
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
[Multi select] onChange returns null when no values instead of [] #3632
Comments
This appears to be the intended behavor with v3: #3416 I just ran into a bug in my app because of this change as well. Curious as to how others handle it. |
react-select changed behavior with version 3, so that removing the last selected option from a multiselect results in value of `null` instead of `[]` as before. This was resulting in an error in the tickets selector, which assumes an array of selected filters. Related: JedWatson/react-select#3632
And interestingly, if user uses the clear all button to remove all the values in Multi select, the value would be set to an empty array. I was wondering why removing the last value results in |
Temporary workaround for this bug: import React, { Component } from 'react';
import ReactSelect from 'react-select';
class Select extends Component {
defaultProps = {
onChange: () => {},
};
handleChange = selected =>
this.props.onChange(!selected && this.props.isMulti ? [] : selected);
render() {
return <ReactSelect {...this.props} onChange={this.handleChange} />;
}
};
export default Select; |
I was having some problems with that as well and to fix it I've redefined the value on the onChange to an empty array.
|
I am still having the same Issue |
I was having the very same problem, needed to use const handleOnChange = (value: ValueType<SelectableItem>, action: ActionMeta) => {
if (!onChange) return;
if (value === null) {
onChange([], action);
} else {
onChange(value, action);
}
};
<ReactSelect
onChange={handleOnChange} ... /> |
Super simple inline fix for people Googling:
Replace stateChangeMethod with whatever you're using to update state. In my case I was using Hooks so I had a specific function just for that bit of state. |
Hello - In an effort to sustain the We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our efforts towards the current major version. If you aren't using the latest version of However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you! |
@bladey Hello. Thank you. But issue is still here. |
+1 |
Thanks @rusakovic! |
Would the maintainers be happy with a PR that normalises empty values for |
I'm definitely in favor of this. I'm working on porting @bladey @JedWatson I can make a PR for this change if you guys are okay with this change. There are only a couple of places where we would need to change the behavior in order for it to be consistent. |
+1, causing some issues on my end, Basically the issue is that the isClearable "X" returns --- I know we can fix by making a wrapper and normalize to either |
I also agree the discrepancy between container "X" and element "X" is not expected, and empty multi select should be [] not null, to avoid any extra conversion by users. I'm using |
…lied for FuseChipSelect. JedWatson/react-select#3632
All is in the title. We implemented a version of the Multi select. and it seems that when you clear the last value (or the only one) of the field, the onChange returns you null. I would clearly expect an empty array at this stage :)
Here is your sandbox updated with the onChange callback :)
https://5jtqt.codesandbox.io/
Thanks for looking at it!
The text was updated successfully, but these errors were encountered: