From 5d02ff2782aa13dc638850c6363d15132b710c2e Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Thu, 7 Mar 2019 12:48:29 -0600 Subject: [PATCH] Fix EuiComboBox `activeOptionIndex` error (#1695) * change activeOptionIndex pattern; guard against -1 * #1695 changelog entry --- CHANGELOG.md | 1 + .../combo_box/__snapshots__/combo_box.test.js.snap | 2 ++ src/components/combo_box/combo_box.js | 10 +++++----- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e762277fb48..1eb5677f5dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ **Bug fixes** - Fixed floating point arithmetic bug in `EuiRangeTrack`'s value validation ([#1687](https://github.com/elastic/eui/pull/1687)) +- Fixed `EuiComboBox` `activeOptonIndex` error with empty search results ([#1695](https://github.com/elastic/eui/pull/1695)) ## [`9.0.2`](https://github.com/elastic/eui/tree/v9.0.2) 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 40176609338..54b0198f286 100644 --- a/src/components/combo_box/__snapshots__/combo_box.test.js.snap +++ b/src/components/combo_box/__snapshots__/combo_box.test.js.snap @@ -451,6 +451,7 @@ exports[`props singleSelection selects existing option when opened 1`] = ` /> { let nextActiveOptionIndex; - if (activeOptionIndex == null) { + if (activeOptionIndex < 0) { // If this is the beginning of the user's keyboard navigation of the menu, then we'll focus // either the first or last item. nextActiveOptionIndex = amount < 0 ? matchingOptions.length - 1 : 0; @@ -186,12 +186,12 @@ export class EuiComboBox extends Component { }; hasActiveOption = () => { - return this.state.activeOptionIndex != null && this.state.activeOptionIndex < this.state.matchingOptions.length; + return this.state.activeOptionIndex > -1 && this.state.activeOptionIndex < this.state.matchingOptions.length; }; clearActiveOption = () => { this.setState({ - activeOptionIndex: undefined, + activeOptionIndex: -1, }); }; @@ -498,7 +498,7 @@ export class EuiComboBox extends Component { const stateUpdate = { matchingOptions }; if (activeOptionIndex >= matchingOptions.length) { - stateUpdate.activeOptionIndex = undefined; + stateUpdate.activeOptionIndex = -1; } return stateUpdate;