Skip to content

Commit

Permalink
Refactored handleKeyDown switch
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-sakharov committed Dec 17, 2017
1 parent a065ad4 commit e61c4de
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class Select extends React.Component {

let toOpen = this.state.isOpen || this._openAfterFocus || this.props.openOnFocus;
toOpen = this._focusAfterClear ? false : toOpen; //if focus happens after clear values, don't open dropdown yet.

if (this.props.onFocus) {
this.props.onFocus(event);
}
Expand Down Expand Up @@ -423,14 +423,14 @@ class Select extends React.Component {
event.preventDefault();
this.popValue();
}
return;
break;
case 9: // tab
if (event.shiftKey || !this.state.isOpen || !this.props.tabSelectsValue) {
return;
break;
}
event.preventDefault();
this.selectFocusedOption();
return;
break;
case 13: // enter
event.preventDefault();
event.stopPropagation();
Expand All @@ -439,62 +439,66 @@ class Select extends React.Component {
} else {
this.focusNextOption();
}
return;
break;
break;
case 27: // escape
event.preventDefault();
if (this.state.isOpen) {
this.closeMenu();
event.stopPropagation();
} else if (this.props.clearable && this.props.escapeClearsValue) {
this.clearValue(event);
event.stopPropagation();
}
break;
break;
case 32: // space
if (this.props.searchable) {
return;
break;
}
event.preventDefault();
if (!this.state.isOpen) {
this.focusNextOption();
return;
break;
}
event.stopPropagation();
this.selectFocusedOption();
break;
break;
case 38: // up
event.preventDefault();
this.focusPreviousOption();
break;
break;
case 40: // down
event.preventDefault();
this.focusNextOption();
break;
break;
case 33: // page up
event.preventDefault();
this.focusPageUpOption();
break;
break;
case 34: // page down
event.preventDefault();
this.focusPageDownOption();
break;
break;
case 35: // end key
if (event.shiftKey) {
return;
break;
}
event.preventDefault();
this.focusEndOption();
break;
break;
case 36: // home key
if (event.shiftKey) {
return;
break;
}
event.preventDefault();
this.focusStartOption();
break;
break;
case 46: // delete
event.preventDefault();
if (!this.state.inputValue && this.props.deleteRemoves) {
event.preventDefault();
this.popValue();
}
return;
default: return;
break;
}
event.preventDefault();
}

handleValueClick (option, event) {
Expand Down

0 comments on commit e61c4de

Please sign in to comment.