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

EuiSuperSelect - check for empty string before setting defaultValue #1319

Merged
merged 4 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
- Fixed error when passing empty string as `value` prop for `EuiSuperSelect` ([#1319](https://github.com/elastic/eui/pull/1319))

## [`5.1.0`](https://github.com/elastic/eui/tree/v5.1.0)

Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/super_select/super_select_complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class extends Component {
];

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.

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,65 @@ Array [
]
`;

exports[`EuiSuperSelectControl props empty value option is rendered 1`] = `
Array [
<input
type="hidden"
value=""
/>,
<div
class="euiFormControlLayout"
>
<div
class="euiFormControlLayout__childrenWrapper"
>
<span
class="euiScreenReaderOnly"
id="generated-id"
>
Select an option: , is selected
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
class="euiSuperSelectControl"
role="option"
type="button"
/>
<div
class="euiFormControlLayoutIcons euiFormControlLayoutIcons--right"
>
<span
class="euiFormControlLayoutCustomIcon"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiFormControlLayoutCustomIcon__icon"
focusable="false"
height="16"
viewBox="0 0 16 16"
width="16"
xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<path
d="M13.069 5.157L8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0z"
id="arrow_down-a"
/>
</defs>
<use
fill-rule="nonzero"
href="#arrow_down-a"
/>
</svg>
</span>
</div>
</div>
</div>,
]
`;

exports[`EuiSuperSelectControl props fullWidth is rendered 1`] = `
Array [
<input
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/super_select/super_select_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 == null) {
selectDefaultValue = defaultValue || '';
}

Expand Down
16 changes: 16 additions & 0 deletions src/components/form/super_select/super_select_control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,21 @@ describe('EuiSuperSelectControl', () => {
expect(component)
.toMatchSnapshot();
});

test('empty value option is rendered', () => {
const component = render(
<EuiSuperSelectControl
options={[
{ value: '1', inputDisplay: 'Option #1' },
{ value: '2', inputDisplay: 'Option #2' }
]}
value={''}
onChange={() => {}}
/>
);

expect(component)
.toMatchSnapshot();
});
});
});