Skip to content

Commit

Permalink
Fix EuiComboBox activeOptionIndex error (#1695)
Browse files Browse the repository at this point in the history
* change activeOptionIndex pattern; guard against -1

* #1695 changelog entry
  • Loading branch information
thompsongl authored Mar 7, 2019
1 parent d936781 commit 5d02ff2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions src/components/combo_box/__snapshots__/combo_box.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ exports[`props singleSelection selects existing option when opened 1`] = `
/>
<EuiPortal>
<EuiComboBoxOptionsList
activeOptionIndex={-1}
areAllOptionsSelected={false}
data-test-subj=""
fullWidth={false}
Expand Down Expand Up @@ -532,6 +533,7 @@ exports[`props singleSelection selects existing option when opened 1`] = `
position="bottom"
rootId={[Function]}
rowHeight={27}
scrollToIndex={-1}
searchValue=""
selectedOptions={
Array [
Expand Down
10 changes: 5 additions & 5 deletions src/components/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class EuiComboBox extends Component {
searchValue: initialSearchValue,
isListOpen: false,
listPosition: 'bottom',
activeOptionIndex: undefined,
activeOptionIndex: -1,
hasFocus: false,
};

Expand Down Expand Up @@ -154,7 +154,7 @@ export class EuiComboBox extends Component {
this.setState(({ activeOptionIndex, matchingOptions }) => {
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;
Expand Down Expand Up @@ -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,
});
};

Expand Down Expand Up @@ -498,7 +498,7 @@ export class EuiComboBox extends Component {
const stateUpdate = { matchingOptions };

if (activeOptionIndex >= matchingOptions.length) {
stateUpdate.activeOptionIndex = undefined;
stateUpdate.activeOptionIndex = -1;
}

return stateUpdate;
Expand Down

0 comments on commit 5d02ff2

Please sign in to comment.