From 14e428e4283644adedcc227165daf52179a5e905 Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Fri, 27 Mar 2020 22:21:54 +0530 Subject: [PATCH 1/4] removed dependedncy on option list of custom option --- src-docs/src/views/combo_box/combo_box.js | 11 +---------- src/components/combo_box/combo_box.tsx | 13 ++++++++++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src-docs/src/views/combo_box/combo_box.js b/src-docs/src/views/combo_box/combo_box.js index 973334206d4..0f5c9a3a5dc 100644 --- a/src-docs/src/views/combo_box/combo_box.js +++ b/src-docs/src/views/combo_box/combo_box.js @@ -54,7 +54,7 @@ export default class extends Component { }); }; - onCreateOption = (searchValue, flattenedOptions) => { + onCreateOption = (searchValue, _) => { const normalizedSearchValue = searchValue.trim().toLowerCase(); if (!normalizedSearchValue) { @@ -65,15 +65,6 @@ export default class extends Component { label: searchValue, }; - // Create the option if it doesn't exist. - if ( - flattenedOptions.findIndex( - option => option.label.trim().toLowerCase() === normalizedSearchValue - ) === -1 - ) { - this.options.push(newOption); - } - // Select the option. this.setState(prevState => ({ selectedOptions: prevState.selectedOptions.concat(newOption), diff --git a/src/components/combo_box/combo_box.tsx b/src/components/combo_box/combo_box.tsx index 7c84e40a528..f5ff5c4cecb 100644 --- a/src/components/combo_box/combo_box.tsx +++ b/src/components/combo_box/combo_box.tsx @@ -472,7 +472,18 @@ export class EuiComboBox extends Component< if (async) { return false; } - return flattenOptionGroups(options).length === selectedOptions.length; + let numberOfSelectedOptions = 0; + selectedOptions.forEach(({ label }) => { + if ( + flattenOptionGroups(options).findIndex( + option => + option.label.trim().toLowerCase() === label.trim().toLowerCase() + ) !== -1 + ) + numberOfSelectedOptions += 1; + }); + + return flattenOptionGroups(options).length === numberOfSelectedOptions; }; isSingleSelectionCustomOption = () => { From 3d781179bbec222a5d4bc224404c7a28aacb6198 Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Tue, 31 Mar 2020 23:54:19 +0530 Subject: [PATCH 2/4] reverted all changes --- src-docs/src/views/combo_box/combo_box.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src-docs/src/views/combo_box/combo_box.js b/src-docs/src/views/combo_box/combo_box.js index 0f5c9a3a5dc..973334206d4 100644 --- a/src-docs/src/views/combo_box/combo_box.js +++ b/src-docs/src/views/combo_box/combo_box.js @@ -54,7 +54,7 @@ export default class extends Component { }); }; - onCreateOption = (searchValue, _) => { + onCreateOption = (searchValue, flattenedOptions) => { const normalizedSearchValue = searchValue.trim().toLowerCase(); if (!normalizedSearchValue) { @@ -65,6 +65,15 @@ export default class extends Component { label: searchValue, }; + // Create the option if it doesn't exist. + if ( + flattenedOptions.findIndex( + option => option.label.trim().toLowerCase() === normalizedSearchValue + ) === -1 + ) { + this.options.push(newOption); + } + // Select the option. this.setState(prevState => ({ selectedOptions: prevState.selectedOptions.concat(newOption), From 7e878d4247b4fc6611363314fe39e1d1ef201039 Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Wed, 1 Apr 2020 23:12:22 +0530 Subject: [PATCH 3/4] CL --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6733031b3f..a1b58c3a36e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) +- Removed dependency on option list for custom option of `EuiComboBox` ([#3183](https://github.com/elastic/eui/pull/3183)) - Fixed `EuiPopover` arrow position in Android and Linux ([#3188](https://github.com/elastic/eui/pull/3188)) - Improved `htmlIdGenerator` when supplying both `prefix` and `suffix` ([#3076](https://github.com/elastic/eui/pull/3076)) - Updated pagination prop descriptions for `EuiInMemoryTable` ([#3142](https://github.com/elastic/eui/pull/3142)) From 380bc73d906608f914255f492b6b064f41cfdd18 Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Thu, 2 Apr 2020 01:02:51 +0530 Subject: [PATCH 4/4] Optimized --- src/components/combo_box/combo_box.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/combo_box/combo_box.tsx b/src/components/combo_box/combo_box.tsx index 6be6654e4c2..b3f6b794068 100644 --- a/src/components/combo_box/combo_box.tsx +++ b/src/components/combo_box/combo_box.tsx @@ -472,18 +472,21 @@ export class EuiComboBox extends Component< if (async) { return false; } + + const flattenOptions = flattenOptionGroups(options).map(option => { + return { ...option, label: option.label.trim().toLowerCase() }; + }); + let numberOfSelectedOptions = 0; selectedOptions.forEach(({ label }) => { + const trimmedLabel = label.trim().toLowerCase(); if ( - flattenOptionGroups(options).findIndex( - option => - option.label.trim().toLowerCase() === label.trim().toLowerCase() - ) !== -1 + flattenOptions.findIndex(option => option.label === trimmedLabel) !== -1 ) numberOfSelectedOptions += 1; }); - return flattenOptionGroups(options).length === numberOfSelectedOptions; + return flattenOptions.length === numberOfSelectedOptions; }; isSingleSelectionCustomOption = () => {