Skip to content

Commit

Permalink
fix(react): initialize highlightedIndex for Downshift (#7776)
Browse files Browse the repository at this point in the history
* fix(react): initialize highlightedIndex for Downshift

* fix(react): use fallback null for undefined highlightedIndex

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
joshblack and kodiakhq[bot] committed Feb 11, 2021
1 parent 6862256 commit 3fa1c18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export default class FilterableMultiSelect extends React.Component {
inputValue: '',
topItems: [],
inputFocused: false,
highlightedIndex: null,
};
}

Expand Down Expand Up @@ -215,11 +216,14 @@ export default class FilterableMultiSelect extends React.Component {
switch (type) {
case Downshift.stateChangeTypes.keyDownArrowUp:
case Downshift.stateChangeTypes.itemMouseEnter:
this.setState({ highlightedIndex: changes.highlightedIndex });
// Sometimes, `changes.highlightedIndex` can be undefined.
// This causes Downshift to think we are switching from controlled to
// uncontrolled
this.setState({ highlightedIndex: changes.highlightedIndex || null });
break;
case Downshift.stateChangeTypes.keyDownArrowDown:
this.setState({
highlightedIndex: changes.highlightedIndex,
highlightedIndex: changes.highlightedIndex || null,
});
if (!this.state.isOpen) {
this.handleOnMenuChange(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ exports[`MultiSelect.Filterable should render 1`] = `
defaultIsOpen={false}
environment={[Window]}
getA11yStatusMessage={[Function]}
highlightedIndex={null}
id="test-filterable-multiselect"
inputValue=""
isOpen={false}
Expand Down

0 comments on commit 3fa1c18

Please sign in to comment.