Skip to content

Commit

Permalink
fixed a JS error occuring because of stale focusIndex values (#168)
Browse files Browse the repository at this point in the history
* fixed a JS error occuring because of stale focusIndex values

* trial to make yarn run on travis

* use latest node version on travis
  • Loading branch information
jfschwarz committed Jun 13, 2017
1 parent b2f7ea0 commit 8a5b234
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion .travis.yml
@@ -1,3 +1,14 @@
language: node_js
node_js:
- "4.1"
- "8.1"
before_install:
# Repo for newer Node.js versions
- curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
# Repo for Yarn
- sudo apt-key adv --keyserver pgp.mit.edu --recv D101F7899D41F3C3
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- sudo apt-get update -qq
- sudo apt-get install -y -qq yarn
cache:
directories:
- $HOME/.yarn-cache
3 changes: 3 additions & 0 deletions src/MentionsInput.js
Expand Up @@ -550,8 +550,11 @@ class MentionsInput extends React.Component {
// won't overwrite each other
this.suggestions = utils.extend({}, this.suggestions, update)

const { focusIndex } = this.state
const suggestionsCount = utils.countSuggestions(this.suggestions);
this.setState({
suggestions: this.suggestions,
focusIndex: focusIndex >= suggestionsCount ? Math.max(suggestionsCount - 1, 0) : focusIndex,
});
};

Expand Down

0 comments on commit 8a5b234

Please sign in to comment.