Merge pull request #569 from ro-savage/autocomplete-autoselect-first-option
Feature - Autocomplete - Added autoselect first option on enterold
commit
0bc5b1d776
|
@ -114,8 +114,17 @@ const factory = (Chip, Input) => {
|
|||
};
|
||||
|
||||
handleQueryKeyUp = (event) => {
|
||||
if (event.which === 13 && this.state.active) this.select(this.state.active, event);
|
||||
if (event.which === 13) {
|
||||
let target = this.state.active;
|
||||
if (!target) {
|
||||
target = [...this.suggestions().keys()][0];
|
||||
this.setState({active: target});
|
||||
}
|
||||
this.select(target, event);
|
||||
}
|
||||
|
||||
if (event.which === 27) ReactDOM.findDOMNode(this).querySelector('input').blur();
|
||||
|
||||
if ([40, 38].indexOf(event.which) !== -1) {
|
||||
const suggestionsKeys = [...this.suggestions().keys()];
|
||||
let index = suggestionsKeys.indexOf(this.state.active) + (event.which === 40 ? +1 : -1);
|
||||
|
|
|
@ -100,8 +100,17 @@ var factory = function factory(Chip, Input) {
|
|||
_this.setState({ query: '' });
|
||||
}
|
||||
}, _this.handleQueryKeyUp = function (event) {
|
||||
if (event.which === 13 && _this.state.active) _this.select(_this.state.active, event);
|
||||
if (event.which === 13) {
|
||||
var target = _this.state.active;
|
||||
if (!target) {
|
||||
target = [].concat(_toConsumableArray(_this.suggestions().keys()))[0];
|
||||
_this.setState({ active: target });
|
||||
}
|
||||
_this.select(target, event);
|
||||
}
|
||||
|
||||
if (event.which === 27) _reactDom2.default.findDOMNode(_this).querySelector('input').blur();
|
||||
|
||||
if ([40, 38].indexOf(event.which) !== -1) {
|
||||
var suggestionsKeys = [].concat(_toConsumableArray(_this.suggestions().keys()));
|
||||
var index = suggestionsKeys.indexOf(_this.state.active) + (event.which === 40 ? +1 : -1);
|
||||
|
|
Loading…
Reference in New Issue