Skip to content
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

Modify onChange with empty value behaviour for multi select to always pass an empty array #4339

Merged
merged 9 commits into from
Jan 22, 2021

Conversation

Methuselah96
Copy link
Collaborator

@Methuselah96 Methuselah96 commented Dec 18, 2020

Resolves #3632.

This change would make it so that the first parameter in onChange would always be an array if it’s a multi-select, or always an object/null if it’s a single-select. Right now the behavior is inconsistent in that removing the last value in a multi-select passes a value of null, but clearing all the values at once passes a value of []. Always passing an array for multi-select makes it easier for the end user so that they don't have to have a special case to handle null.

(See #3416 for context.)

Note that this is a breaking change.

@changeset-bot
Copy link

changeset-bot bot commented Dec 18, 2020

🦋 Changeset detected

Latest commit: 07a3997

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
react-select Major
@react-select/docs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Methuselah96 Methuselah96 added this to the 4.0 milestone Dec 18, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 18, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 07a3997:

Sandbox Source
react-codesandboxer-example Configuration

@Methuselah96 Methuselah96 changed the title Pass [] instead of null in onChange when no values on multi-select Pass [] instead of null in onChange when there are no values on multi-select Dec 18, 2020
@Methuselah96 Methuselah96 changed the title Pass [] instead of null in onChange when there are no values on multi-select Standardize value passed to onChange Dec 18, 2020
@JedWatson JedWatson changed the title Standardize value passed to onChange Modify onChange with empty value behaviour for multi select to always pass an empty array Jan 13, 2021
@JedWatson JedWatson merged commit cb4b948 into JedWatson:master Jan 22, 2021
@github-actions github-actions bot mentioned this pull request Jan 22, 2021
@Methuselah96 Methuselah96 deleted the on-change-null branch January 22, 2021 04:14
ptbrowne added a commit to cozy/cozy-ui that referenced this pull request Mar 24, 2021
BREAKING CHANGE: react-select is upgraded from v2 to v4. It should
not impact you but you should be extra careful around the areas that
use a select.

Values are now normalized: JedWatson/react-select#4339
The onChange callback receives values that are more coherent now (array
if multi select, value is always an array (can be empty), if a single
select, value can be object/null.

V4 changelog: https://github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#400
V3 changelog: https://github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#300
ptbrowne added a commit to cozy/cozy-ui that referenced this pull request Mar 24, 2021
BREAKING CHANGE: react-select is upgraded from v2 to v4. It should
not impact you but you should be extra careful around the areas that
use a select.

Values are now normalized: JedWatson/react-select#4339
The onChange callback receives values that are more coherent now (array
if multi select, value is always an array (can be empty), if a single
select, value can be object/null.

V4 changelog: https://github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#400
V3 changelog: https://github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#300
ptbrowne added a commit to cozy/cozy-ui that referenced this pull request Mar 24, 2021
BREAKING CHANGE: react-select is upgraded from v2 to v4. It should
not impact you but you should be extra careful around the areas that
use a select.

Values are now normalized: JedWatson/react-select#4339
The onChange callback receives values that are more coherent now (array
if multi select, value is always an array (can be empty), if a single
select, value can be object/null.

V4 changelog: https://github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#400
V3 changelog: https://github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#300
ptbrowne added a commit to cozy/cozy-ui that referenced this pull request Mar 24, 2021
BREAKING CHANGE: react-select is upgraded from v2 to v4. It should
not impact you but you should be extra careful around the areas that
use a select.

Values are now normalized: JedWatson/react-select#4339
The onChange callback receives values that are more coherent now (array
if multi select, value is always an array (can be empty), if a single
select, value can be object/null.

V4 changelog: https://github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#400
V3 changelog: https://github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#300
cozy-bot pushed a commit to cozy/cozy-ui that referenced this pull request Mar 25, 2021
# [48.0.0](v47.6.0...v48.0.0) (2021-03-25)

### Bug Fixes

* Remove withPrefix function, that no longer seems necessary ([15a6c6f](15a6c6f))
* Use SVGr icon for example ([696e9a9](696e9a9))

### Features

* Upgrade react-select ([f60569e](f60569e)), closes [/github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#400](https://github.com//github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md/issues/400) [/github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md#300](https://github.com//github.com/JedWatson/react-select/blob/master/packages/react-select/CHANGELOG.md/issues/300)

### BREAKING CHANGES

* react-select is upgraded from v2 to v4. It should
not impact you but you should be extra careful around the areas that
use a select.

Values are now normalized: JedWatson/react-select#4339
The onChange callback receives values that are more coherent now (array
if multi select, value is always an array (can be empty), if a single
select, value can be object/null.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Multi select] onChange returns null when no values instead of []
2 participants