Skip to content

Commit

Permalink
Allow disabling of EuiSelect options (#324)
Browse files Browse the repository at this point in the history
* Allow disabling of EuiSelect options
  • Loading branch information
zinckiwi authored and snide committed Feb 13, 2018
1 parent fe998b8 commit 9898317
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# [`master`](https://github.com/elastic/eui/tree/master)

- Added support for `disabled` options in `EuiSelect`. [#324](https://github.com/elastic/eui/pull/324)
- Badges can now accept onClicks and custom colors. They were changed stylistically to be bolder and smaller by default. ([#381](https://github.com/elastic/eui/pull/381))
- Added component to wrap blocks of substeps `EuiSubSteps` in a shaded container. ([#375](https://github.com/elastic/eui/pull/375))
- Added horizontal steps component ([#375](https://github.com/elastic/eui/pull/375))
Expand Down
27 changes: 27 additions & 0 deletions src/components/form/select/__snapshots__/select.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ exports[`EuiSelect is rendered 1`] = `
</eui-form-control-layout>
`;

exports[`EuiSelect props disabled options are rendered 1`] = `
<eui-form-control-layout
fullwidth="false"
icon="arrowDown"
iconside="right"
isloading="false"
>
<eui-validatable-control>
<select
class="euiSelect"
>
<option
value="1"
>
Option #1
</option>
<option
disabled=""
value="2"
>
Option #2
</option>
</select>
</eui-validatable-control>
</eui-form-control-layout>
`;

exports[`EuiSelect props fullWidth is rendered 1`] = `
<eui-form-control-layout
fullwidth="true"
Expand Down
13 changes: 8 additions & 5 deletions src/components/form/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ export const EuiSelect = ({
ref={inputRef}
{...rest}
>
{options.map((option, index) => (
<option value={option.value} key={index}>{option.text}</option>
))}
{options.map((option, index) => {
const {
text,
...rest
} = option;
return <option {...rest} key={index}>{text}</option>;
})}
</select>
</EuiValidatableControl>
</EuiFormControlLayout>
Expand All @@ -58,8 +62,7 @@ EuiSelect.propTypes = {
name: PropTypes.string,
id: PropTypes.string,
options: PropTypes.arrayOf(PropTypes.shape({
value: PropTypes.string.isRequired,
text: PropTypes.string.isRequired,
text: PropTypes.string.isRequired
})).isRequired,
isInvalid: PropTypes.bool,
fullWidth: PropTypes.bool,
Expand Down
14 changes: 14 additions & 0 deletions src/components/form/select/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,19 @@ describe('EuiSelect', () => {
expect(component)
.toMatchSnapshot();
});

test('disabled options are rendered', () => {
const component = render(
<EuiSelect
options={[
{ value: '1', text: 'Option #1', disabled: false },
{ value: '2', text: 'Option #2', disabled: true }
]}
/>
);

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

0 comments on commit 9898317

Please sign in to comment.