Skip to content

Commit

Permalink
Cleaning up order of focusing
Browse files Browse the repository at this point in the history
The calls to setState should be batched, but this protects against an
edge-case where they may not be
  • Loading branch information
JedWatson committed Jan 31, 2017
1 parent bba9077 commit 2821f0a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,13 @@ const Select = React.createClass({

addValue (value) {
var valueArray = this.getValueArray(this.props.value);
this.setValue(valueArray.concat(value));
const visibleOptions = this._visibleOptions.filter(val => !val.disabled);
const index = visibleOptions.indexOf(value);
if (visibleOptions.length > index + 1) {
this.focusOption(visibleOptions[index + 1]);
const valueIndex = visibleOptions.indexOf(value);
this.setValue(valueArray.concat(value));
if (visibleOptions.length > valueIndex + 1) {
this.focusOption(visibleOptions[valueIndex + 1]);
} else if (index > 0) {
this.focusOption(visibleOptions[index - 1]);
this.focusOption(visibleOptions[valueIndex - 1]);
}
},

Expand Down

0 comments on commit 2821f0a

Please sign in to comment.