From afa7cc082256afda2b0dc20f616868f474bd7fc2 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Wed, 1 Jan 2020 11:00:46 -0800 Subject: [PATCH 1/4] added clearable prop to EuiFieldSearch --- .../src/views/form_controls/display_toggles.js | 15 +++++++++++++++ src-docs/src/views/form_controls/field_search.js | 4 ++-- .../form/field_search/_field_search.scss | 14 ++++++++++---- src/components/form/field_search/field_search.js | 12 ++++++++++++ .../__snapshots__/search_box.test.js.snap | 2 ++ 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src-docs/src/views/form_controls/display_toggles.js b/src-docs/src/views/form_controls/display_toggles.js index c126cd96f56..4df62ce2ecd 100644 --- a/src-docs/src/views/form_controls/display_toggles.js +++ b/src-docs/src/views/form_controls/display_toggles.js @@ -27,6 +27,7 @@ export class DisplayToggles extends Component { append: false, isPopoverOpen: false, invalid: false, + isClearable: false, }; } @@ -48,6 +49,7 @@ export class DisplayToggles extends Component { canPrepend, canAppend, canInvalid, + canClear, children, extras, } = this.props; @@ -59,6 +61,7 @@ export class DisplayToggles extends Component { if (canLoading) canProps.isLoading = this.state.loading; if (canFullWidth) canProps.fullWidth = this.state.fullWidth; if (canCompressed) canProps.compressed = this.state.compressed; + if (canClear) canProps.isClearable = this.state.isClearable; if (canPrepend && this.state.prepend) canProps.prepend = 'Prepend'; if (canAppend && this.state.append) canProps.append = 'Append'; if (canInvalid) canProps.isInvalid = this.state.invalid; @@ -145,6 +148,18 @@ export class DisplayToggles extends Component { /> )} + {canClear && ( + + + this.updateProperty(e.target.checked, 'isClearable') + } + /> + + )} {canCompressed && ( { this.setState({ - value: e.target.value, + value: e === '' ? '' : e.target.value, }); }; render() { return ( /* DisplayToggles wrapper for Docs only */ - + { + this.props.onChange(''); + this.inputElement.focus(); + }; + componentWillUnmount() { this.cleanups.forEach(cleanup => cleanup()); } @@ -100,6 +110,7 @@ export class EuiFieldSearch extends Component { incremental, compressed, onSearch, + isClearable, ...rest } = this.props; @@ -118,6 +129,7 @@ export class EuiFieldSearch extends Component { icon="search" fullWidth={fullWidth} isLoading={isLoading} + clear={isClearable && value ? { onClick: this.onClear } : null} compressed={compressed}> Date: Wed, 1 Jan 2020 11:35:45 -0800 Subject: [PATCH 2/4] cl --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c52426ad960..97ab57ce4ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Added `tableLayout` prop to `EuiTable`, `EuiBasicTable` and `EuiInMemoryTable` to provide the option of auto layout ([#2697](https://github.com/elastic/eui/pull/2697)) - Converted `EuiSuggest` to Typescript ([#2692](https://github.com/elastic/eui/pull/2692)) - Converted `EuiErrorBoundary` to Typescript ([#2690](https://github.com/elastic/eui/pull/2690)) +- Added `isClearable` prop to `EuiFieldSearch` ([#2723](https://github.com/elastic/eui/pull/2723)) **Bug fixes** From c29f216306557d03ac197a957483a209444f3ab7 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Thu, 2 Jan 2020 10:40:20 -0800 Subject: [PATCH 3/4] PR feedback --- .../field_search/__snapshots__/field_search.test.js.snap | 1 + src/components/form/field_search/field_search.js | 8 ++++++-- .../search_bar/__snapshots__/search_box.test.js.snap | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/form/field_search/__snapshots__/field_search.test.js.snap b/src/components/form/field_search/__snapshots__/field_search.test.js.snap index f674fd59e13..6d3eb2848ea 100644 --- a/src/components/form/field_search/__snapshots__/field_search.test.js.snap +++ b/src/components/form/field_search/__snapshots__/field_search.test.js.snap @@ -2,6 +2,7 @@ exports[`EuiFieldSearch is rendered 1`] = ` Date: Thu, 2 Jan 2020 17:56:36 -0800 Subject: [PATCH 4/4] gave clearable a custom toggle --- .../src/views/form_controls/display_toggles.js | 15 --------------- src-docs/src/views/form_controls/field_search.js | 16 ++++++++++++++-- src/components/form/field_search/field_search.js | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src-docs/src/views/form_controls/display_toggles.js b/src-docs/src/views/form_controls/display_toggles.js index 4df62ce2ecd..c126cd96f56 100644 --- a/src-docs/src/views/form_controls/display_toggles.js +++ b/src-docs/src/views/form_controls/display_toggles.js @@ -27,7 +27,6 @@ export class DisplayToggles extends Component { append: false, isPopoverOpen: false, invalid: false, - isClearable: false, }; } @@ -49,7 +48,6 @@ export class DisplayToggles extends Component { canPrepend, canAppend, canInvalid, - canClear, children, extras, } = this.props; @@ -61,7 +59,6 @@ export class DisplayToggles extends Component { if (canLoading) canProps.isLoading = this.state.loading; if (canFullWidth) canProps.fullWidth = this.state.fullWidth; if (canCompressed) canProps.compressed = this.state.compressed; - if (canClear) canProps.isClearable = this.state.isClearable; if (canPrepend && this.state.prepend) canProps.prepend = 'Prepend'; if (canAppend && this.state.append) canProps.append = 'Append'; if (canInvalid) canProps.isInvalid = this.state.invalid; @@ -148,18 +145,6 @@ export class DisplayToggles extends Component { /> )} - {canClear && ( - - - this.updateProperty(e.target.checked, 'isClearable') - } - /> - - )} {canCompressed && ( + { + this.setState({ isClearable: e.target.checked }); + }} + />, + ]}> diff --git a/src/components/form/field_search/field_search.js b/src/components/form/field_search/field_search.js index d536bb2185f..f9acc8d706b 100644 --- a/src/components/form/field_search/field_search.js +++ b/src/components/form/field_search/field_search.js @@ -32,7 +32,7 @@ const propTypes = { */ compressed: PropTypes.bool, /** - * Shows a clear button when set to true + * Shows a button that quickly clears any input */ isClearable: PropTypes.bool, };