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

Created option to simulate no selection of EuiSelect #422

Merged
merged 3 commits into from
Feb 21, 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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
- Added `EuiDelayHide` component. [#412](https://github.com/elastic/eui/pull/412)
- Decreased overall size of checkbox, radio, and switches as well as better styles for the different states. ([#407](https://github.com/elastic/eui/pull/407))
- `EuiFilePicker` added for `input type="file"` needs. ([#402](https://github.com/elastic/eui/pull/402))
- Add `isLoading` prop to `EuiButton` ([#427](https://github.com/elastic/eui/pull/427))
- Added icons: `eye`, `eyeClosed`, `grab`, `heatmap`, `vector` ([#427](https://github.com/elastic/eui/pull/427))
- Add `isLoading` prop to `EuiButton` ([#427](https://github.com/elastic/eui/pull/427))
- Added icons: `eye`, `eyeClosed`, `grab`, `heatmap`, `vector` ([#427](https://github.com/elastic/eui/pull/427))
- Added `hasNoInitialSelection` option to `EuiSelect`. ([#422](https://github.com/elastic/eui/pull/422))

**Bug fixes**

Expand Down
3 changes: 2 additions & 1 deletion src-docs/src/views/form/form_rows.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ export default class extends Component {
</EuiFormRow>

<EuiFormRow
label="Select"
label="Select (with no initial selection)"
>
<EuiSelect
hasNoInitialSelection={true}
options={[
{ value: 'option_one', text: 'Option one' },
{ value: 'option_two', text: 'Option two' },
Expand Down
15 changes: 15 additions & 0 deletions src/components/form/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const EuiSelect = ({
isInvalid,
fullWidth,
isLoading,
hasNoInitialSelection,
...rest
}) => {
const classes = classNames(
Expand All @@ -30,6 +31,13 @@ export const EuiSelect = ({
className
);

let emtpyOptionNode;
if (hasNoInitialSelection) {
emtpyOptionNode = (
<option selected disabled hidden style={{ display: 'none' }}>&nbsp;</option>
);
}

return (
<EuiFormControlLayout
icon="arrowDown"
Expand All @@ -45,6 +53,7 @@ export const EuiSelect = ({
ref={inputRef}
{...rest}
>
{emtpyOptionNode}
{options.map((option, index) => {
const {
text,
Expand All @@ -67,11 +76,17 @@ EuiSelect.propTypes = {
isInvalid: PropTypes.bool,
fullWidth: PropTypes.bool,
isLoading: PropTypes.bool,

/**
* Simulates no selection by creating an empty, selected, hidden first option
*/
hasNoInitialSelection: PropTypes.bool,
inputRef: PropTypes.func,
};

EuiSelect.defaultProps = {
options: [],
fullWidth: false,
isLoading: false,
hasNoInitialSelection: false,
};