Skip to content

EuiSuperSelect - check for empty string before setting defaultValue#1319

Merged
nreese merged 4 commits intoelastic:masterfrom
nreese:superSelect_noValue
Nov 20, 2018
Merged

EuiSuperSelect - check for empty string before setting defaultValue#1319
nreese merged 4 commits intoelastic:masterfrom
nreese:superSelect_noValue

Conversation

@nreese
Copy link
Contributor

@nreese nreese commented Nov 17, 2018

If you provide EuiSuperSelect with an empty value '', then a react warning is displayed

screen shot 2018-11-16 at 5 47 05 pm

This PR verifies that value is not '' before setting the defaultValue

@nreese nreese added the bug label Nov 17, 2018
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tacking this!


this.state = {
value: this.options[1].value,
value: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably didn't mean to commit changes to the example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured having an example with an empty initial selection would not hurt but I can revert the change if you would like

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understandable, though I'd almost rather have an example specifically for empty initials instead of applying to a current example.

CHANGELOG.md Outdated

- `EuiBasicTable` now converts the `EuiTableRowCell` `header` into `undefined` if it's been provided as a non-string node, hiding the header and preventing the node from being rendered as `[object Object]` on narrow screens ([#1312](https://github.com/elastic/eui/pull/1312))
- Fixed `fullWidth` size of `EuiComboBox`, a regression introduced in `4.7.0` ([#1314](https://github.com/elastic/eui/pull/1314))
- `EuiSuperSelect`, do not set value and defaultValue on input when EuiSuperSelect is passed empty string for `valueOfSelected` prop ([#1319](https://github.com/elastic/eui/pull/1319))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `EuiSuperSelect`, do not set value and defaultValue on input when EuiSuperSelect is passed empty string for `valueOfSelected` prop ([#1319](https://github.com/elastic/eui/pull/1319))
- Fixed error when passing empty string as `value` prop for `EuiSuperSelect` ([#1319](https://github.com/elastic/eui/pull/1319))

// https://reactjs.org/docs/uncontrolled-components.html#default-values
let selectDefaultValue;
if (!value) {
if (!value && value !== '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, let's change that original !value to value == null to avoid JavaScript's truthiness weirdness. This solves this '' use case but also any other, as value can be any type of React node like false or 0

Suggested change
if (!value && value !== '') {
if (value == null) {

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nreese nreese merged commit cbfc994 into elastic:master Nov 20, 2018
@snide snide mentioned this pull request Nov 30, 2018
1 task
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.

3 participants