-
Notifications
You must be signed in to change notification settings - Fork 843
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
EuiSuperSelect - check for empty string before setting defaultValue #1319
Conversation
There was a problem hiding this 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!
@@ -56,7 +56,7 @@ export default class extends Component { | |||
]; | |||
|
|||
this.state = { | |||
value: this.options[1].value, | |||
value: '', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -6,6 +6,7 @@ | |||
|
|||
- `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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `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)) |
@@ -33,7 +33,7 @@ export const EuiSuperSelectControl = ({ | |||
// React HTML input can not have both value and defaultValue properties. | |||
// https://reactjs.org/docs/uncontrolled-components.html#default-values | |||
let selectDefaultValue; | |||
if (!value) { | |||
if (!value && value !== '') { |
There was a problem hiding this comment.
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
if (!value && value !== '') { | |
if (value == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
If you provide
EuiSuperSelect
with an empty value''
, then a react warning is displayedThis PR verifies that value is not
''
before setting the defaultValue