From 98ffbed7813ea6796067eb1325f03084f216ac70 Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Fri, 19 Apr 2019 13:46:37 -0500 Subject: [PATCH] Prevent refocusing EuiComboBox input after container blur event (#1863) * prevent refocusing input after container blur event * formatting * #1863 CL --- CHANGELOG.md | 1 + src/components/combo_box/combo_box.js | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 841960e5a22..3486da5bbdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ **Bug fixes** - Added `toastLifeTimeMs` typescript definition for individual toasts in `EuiGlobalToastList` ([#1846](https://github.com/elastic/eui/pull/1846)) +- Added logic to prevent refocusing `EuiComboBox` input after container blur event ([#1863](https://github.com/elastic/eui/pull/1863)) ## [`10.0.1`](https://github.com/elastic/eui/tree/v10.0.1) diff --git a/src/components/combo_box/combo_box.js b/src/components/combo_box/combo_box.js index da0003aacb3..ed17d73124d 100644 --- a/src/components/combo_box/combo_box.js +++ b/src/components/combo_box/combo_box.js @@ -213,7 +213,7 @@ export class EuiComboBox extends Component { this.onRemoveOption(this.props.selectedOptions[this.props.selectedOptions.length - 1]); }; - addCustomOption = () => { + addCustomOption = (isContainerBlur) => { const { options, selectedOptions, @@ -226,7 +226,7 @@ export class EuiComboBox extends Component { } = this.state; if (this.doesSearchMatchOnlyOption()) { - this.onAddOption(matchingOptions[0]); + this.onAddOption(matchingOptions[0], isContainerBlur); return; } @@ -294,7 +294,7 @@ export class EuiComboBox extends Component { // If the user tabs away or changes focus to another element, take whatever input they've // typed and convert it into a pill, to prevent the combo box from looking like a text input. if (!this.hasActiveOption()) { - this.addCustomOption(); + this.addCustomOption(true); } } } @@ -367,7 +367,7 @@ export class EuiComboBox extends Component { this.onAddOption(option); } - onAddOption = (addedOption) => { + onAddOption = (addedOption, isContainerBlur) => { if (addedOption.disabled) { return; } @@ -384,7 +384,9 @@ export class EuiComboBox extends Component { } this.clearActiveOption(); - this.searchInput.focus(); + if (!isContainerBlur) { + this.searchInput.focus(); + } }; onRemoveOption = (removedOption) => {