From 2577abf03965ab7bf2880f303879583ded164e01 Mon Sep 17 00:00:00 2001 From: Scott Gould Date: Fri, 19 Jan 2018 15:44:52 +0000 Subject: [PATCH 1/3] Allow disabling of EuiSelect options --- .../select/__snapshots__/select.test.js.snap | 27 +++++++++++++++++++ src/components/form/select/select.js | 14 +++++++--- src/components/form/select/select.test.js | 14 ++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/components/form/select/__snapshots__/select.test.js.snap b/src/components/form/select/__snapshots__/select.test.js.snap index 2892acd89f3..cbced5b237e 100644 --- a/src/components/form/select/__snapshots__/select.test.js.snap +++ b/src/components/form/select/__snapshots__/select.test.js.snap @@ -19,6 +19,33 @@ exports[`EuiSelect is rendered 1`] = ` `; +exports[`EuiSelect props disabled options are rendered 1`] = ` + + + + + +`; + exports[`EuiSelect props fullWidth is rendered 1`] = ` - {options.map((option, index) => ( - - ))} + {options.map((option, index) => { + const props = { + key: index, + value: option.value + }; + if (option.disabled) { + props.disabled = true; + } + return ; + })} @@ -60,6 +67,7 @@ EuiSelect.propTypes = { options: PropTypes.arrayOf(PropTypes.shape({ value: PropTypes.string.isRequired, text: PropTypes.string.isRequired, + disabled: PropTypes.bool, })).isRequired, isInvalid: PropTypes.bool, fullWidth: PropTypes.bool, diff --git a/src/components/form/select/select.test.js b/src/components/form/select/select.test.js index cfb984e0aa5..65679aef148 100644 --- a/src/components/form/select/select.test.js +++ b/src/components/form/select/select.test.js @@ -62,5 +62,19 @@ describe('EuiSelect', () => { expect(component) .toMatchSnapshot(); }); + + test('disabled options are rendered', () => { + const component = render( + + ); + + expect(component) + .toMatchSnapshot(); + }); }); }); From 7c8f09e6e561ed100641fdc512821114670a06d3 Mon Sep 17 00:00:00 2001 From: Scott Gould Date: Fri, 19 Jan 2018 15:50:36 +0000 Subject: [PATCH 2/3] Add changelog line --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 297314074a6..d891764adca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Added `isColorDark` color util [(#311)](https://github.com/elastic/eui/pull/311) - EuiButton, EuiButtonEmpty and EuiButtonIcon can now take an `href` [(#316)](https://github.com/elastic/eui/pull/316) - In `EuiSideNav`, allow a callback to be passed that renders the individual items in the navigation. This makes interoperability with e.g. `react-router` easier. [#310](https://github.com/elastic/eui/pull/310) +- Added support for `disabled` options in `EuiSelect`. [#324](https://github.com/elastic/eui/pull/324) **Bug fixes** From 601735874ec9bd37706faf25c591b367f14a02f8 Mon Sep 17 00:00:00 2001 From: Scott Gould Date: Fri, 19 Jan 2018 16:24:58 +0000 Subject: [PATCH 3/3] Pass through html-native option props implicitly --- src/components/form/select/select.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/components/form/select/select.js b/src/components/form/select/select.js index 8590d4377dc..76d3c47329b 100644 --- a/src/components/form/select/select.js +++ b/src/components/form/select/select.js @@ -46,14 +46,11 @@ export const EuiSelect = ({ {...rest} > {options.map((option, index) => { - const props = { - key: index, - value: option.value - }; - if (option.disabled) { - props.disabled = true; - } - return ; + const { + text, + ...rest + } = option; + return ; })} @@ -65,9 +62,7 @@ EuiSelect.propTypes = { name: PropTypes.string, id: PropTypes.string, options: PropTypes.arrayOf(PropTypes.shape({ - value: PropTypes.string.isRequired, - text: PropTypes.string.isRequired, - disabled: PropTypes.bool, + text: PropTypes.string.isRequired })).isRequired, isInvalid: PropTypes.bool, fullWidth: PropTypes.bool,