Skip to content

Commit

Permalink
fix(Geosuggest): Unset activeSuggest on blur and when not in suggesti…
Browse files Browse the repository at this point in the history
…on list anymore
  • Loading branch information
Caerostris committed Jun 6, 2016
1 parent 6fcb01d commit 08ea143
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Geosuggest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ class Geosuggest extends React.Component {
regex = new RegExp(escapeRegExp(this.state.userInput), 'gim'),
skipSuggest = this.props.skipSuggest,
maxFixtures = 10,
fixturesSearched = 0;
fixturesSearched = 0,
activeSuggest = this.state.activeSuggest;

this.props.fixtures.forEach(suggest => {
if (fixturesSearched >= maxFixtures) {
Expand All @@ -196,7 +197,17 @@ class Geosuggest extends React.Component {
}
});

this.setState({suggests});
// check if activeSuggest is still in list
if (activeSuggest) {
const newSuggest = suggests.find(listedSuggest =>
activeSuggest.placeId === listedSuggest.placeId &&
activeSuggest.isFixture === listedSuggest.isFixture
);

activeSuggest = newSuggest || null;
}

this.setState({suggests, activeSuggest});
}

/**
Expand All @@ -213,7 +224,10 @@ class Geosuggest extends React.Component {
hideSuggests() {
this.props.onBlur(this.state.userInput);
const timer = setTimeout(() => {
this.setState({isSuggestsHidden: true});
this.setState({
isSuggestsHidden: true,
activeSuggest: null
});
}, 100);

this.setState({timer});
Expand Down

0 comments on commit 08ea143

Please # to comment.