diff --git a/CHANGELOG.md b/CHANGELOG.md index 4738b2b9dbd..f78148178ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Added `direction` prop to EuiFlexGroup ([#711](https://github.com/elastic/eui/pull/711)) - Added `EuiEmptyPrompt` which can be used as a placeholder over empty tables and lists ([#711](https://github.com/elastic/eui/pull/711)) - Added `EuiTabbedContent` ([#737](https://github.com/elastic/eui/pull/737)) +- `EuiComboBox` added buttons for clearing and opening/closing the combo box. ([#698](https://github.com/elastic/eui/pull/698)) **Bug fixes** diff --git a/src-docs/src/views/combo_box/combo_box.js b/src-docs/src/views/combo_box/combo_box.js index 647af621fbb..db61934ae6b 100644 --- a/src-docs/src/views/combo_box/combo_box.js +++ b/src-docs/src/views/combo_box/combo_box.js @@ -76,6 +76,7 @@ export default class extends Component { selectedOptions={selectedOptions} onChange={this.onChange} onCreateOption={this.onCreateOption} + isClearable={true} /> ); } diff --git a/src/components/combo_box/__snapshots__/combo_box.test.js.snap b/src/components/combo_box/__snapshots__/combo_box.test.js.snap index eaa38d234f8..f8707b14f49 100644 --- a/src/components/combo_box/__snapshots__/combo_box.test.js.snap +++ b/src/components/combo_box/__snapshots__/combo_box.test.js.snap @@ -3,49 +3,27 @@ exports[`EuiComboBox is rendered 1`] = `
-
-
-
- -
-
-
- - - - - - -
+
`; diff --git a/src/components/combo_box/_combo_box.scss b/src/components/combo_box/_combo_box.scss index 47934f3d51b..3252abd6bf0 100644 --- a/src/components/combo_box/_combo_box.scss +++ b/src/components/combo_box/_combo_box.scss @@ -4,7 +4,7 @@ /** * 1. Allow pills to truncate their text with an ellipsis. - * 2. Don't allow pills to overlap with the caret. + * 2. Don't allow pills to overlap with the caret or clear button. * 3. */ .euiComboBox__inputWrap { @@ -13,7 +13,7 @@ $padding: $euiSizeXS; display: flex; /* 1 */ flex-wrap: wrap; /* 1 */ - padding: $padding $euiSizeXXL $padding $padding; /* 2 */ + padding: $padding $euiSizeXL*2 $padding $padding; /* 2 */ align-content: flex-start; &:hover { diff --git a/src/components/combo_box/combo_box.js b/src/components/combo_box/combo_box.js index d2ee1b3ded5..e55c391023f 100644 --- a/src/components/combo_box/combo_box.js +++ b/src/components/combo_box/combo_box.js @@ -40,11 +40,13 @@ export class EuiComboBox extends Component { renderOption: PropTypes.func, isInvalid: PropTypes.bool, rowHeight: PropTypes.number, + isClearable: PropTypes.bool, } static defaultProps = { options: [], selectedOptions: [], + isClearable: true, } constructor(props) { @@ -381,6 +383,10 @@ export class EuiComboBox extends Component { this.focusSearchInput(); }; + clearSelectedOptions = () => { + this.props.onChange([]); + } + onComboBoxClick = () => { // When the user clicks anywhere on the box, enter the interaction state. this.searchInput.focus(); @@ -497,6 +503,7 @@ export class EuiComboBox extends Component { async, // eslint-disable-line no-unused-vars isInvalid, rowHeight, + isClearable, ...rest } = this.props; @@ -560,6 +567,11 @@ export class EuiComboBox extends Component { autoSizeInputRef={this.autoSizeInputRef} inputRef={this.searchInputRef} updatePosition={this.updateListPosition} + onClear={isClearable && this.clearSelectedOptions ? this.clearSelectedOptions : undefined} + hasSelectedOptions={selectedOptions.length > 0} + isListOpen={isListOpen} + onOpen={this.openList} + onClose={this.closeList} /> {optionsList} diff --git a/src/components/combo_box/combo_box.test.js b/src/components/combo_box/combo_box.test.js index 6a5d06efa8a..e2afb397a4e 100644 --- a/src/components/combo_box/combo_box.test.js +++ b/src/components/combo_box/combo_box.test.js @@ -1,12 +1,12 @@ import React from 'react'; -import { render } from 'enzyme'; +import { shallow } from 'enzyme'; import { requiredProps } from '../../test'; import { EuiComboBox } from './combo_box'; describe('EuiComboBox', () => { test('is rendered', () => { - const component = render( + const component = shallow( ); diff --git a/src/components/combo_box/combo_box_input/combo_box_input.js b/src/components/combo_box/combo_box_input/combo_box_input.js index 244d08dd4c3..85b9e830bb0 100644 --- a/src/components/combo_box/combo_box_input/combo_box_input.js +++ b/src/components/combo_box/combo_box_input/combo_box_input.js @@ -23,6 +23,11 @@ export class EuiComboBoxInput extends Component { autoSizeInputRef: PropTypes.func, inputRef: PropTypes.func, updatePosition: PropTypes.func.isRequired, + onClear: PropTypes.func, + hasSelectedOptions: PropTypes.bool.isRequired, + isListOpen: PropTypes.bool.isRequired, + onOpen: PropTypes.func.isRequired, + onClose: PropTypes.func.isRequired, } constructor(props) { @@ -75,6 +80,11 @@ export class EuiComboBoxInput extends Component { searchValue, autoSizeInputRef, inputRef, + onClear, + hasSelectedOptions, + isListOpen, + onOpen, + onClose, } = this.props; const pills = selectedOptions.map((option) => { @@ -135,6 +145,8 @@ export class EuiComboBoxInput extends Component {
-
-
-
-
- -
-
-
- - + - -
+ +
`; diff --git a/src/components/date_picker/date_picker.test.js b/src/components/date_picker/date_picker.test.js index be5692d8195..b45429d8ef9 100644 --- a/src/components/date_picker/date_picker.test.js +++ b/src/components/date_picker/date_picker.test.js @@ -1,12 +1,12 @@ import React from 'react'; -import { render } from 'enzyme'; +import { shallow } from 'enzyme'; import { requiredProps } from '../../test'; import { EuiDatePicker } from './date_picker'; describe('EuiDatePicker', () => { test('is rendered', () => { - const component = render( + const component = shallow( ); diff --git a/src/components/form/form_control_layout/__snapshots__/form_control_layout.test.js.snap b/src/components/form/form_control_layout/__snapshots__/form_control_layout.test.js.snap index 6e08ab418ad..a010abb1aaa 100644 --- a/src/components/form/form_control_layout/__snapshots__/form_control_layout.test.js.snap +++ b/src/components/form/form_control_layout/__snapshots__/form_control_layout.test.js.snap @@ -19,6 +19,7 @@ exports[`EuiFormControlLayout props icon is rendered 1`] = ` class="euiFormControlLayout" >
{children} {optionalIcon} + {optionalClear} {optionalLoader}
); @@ -57,6 +92,8 @@ EuiFormControlLayout.propTypes = { fullWidth: PropTypes.bool, iconSide: PropTypes.oneOf(ICON_SIDES), isLoading: PropTypes.bool, + onClear: PropTypes.func, + onIconClick: PropTypes.func, className: PropTypes.string, };