From 8a5b234165b4e6912b73fbfa8591bd5e36ff1800 Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Tue, 13 Jun 2017 10:56:44 +0200 Subject: [PATCH] fixed a JS error occuring because of stale focusIndex values (#168) * fixed a JS error occuring because of stale focusIndex values * trial to make yarn run on travis * use latest node version on travis --- .travis.yml | 13 ++++++++++++- src/MentionsInput.js | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a1eae3c8..b37219af 100644 --- a/.travis.yml +++ b/.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 \ No newline at end of file diff --git a/src/MentionsInput.js b/src/MentionsInput.js index 35dd370f..af1e5b09 100644 --- a/src/MentionsInput.js +++ b/src/MentionsInput.js @@ -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, }); };