Merge pull request #569 from ro-savage/autocomplete-autoselect-first-option

Feature - Autocomplete - Added autoselect first option on enter
old
Javi Velasco 2016-06-19 21:13:17 +02:00 committed by GitHub
commit 0bc5b1d776
2 changed files with 20 additions and 2 deletions

View File

@ -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);

View File

@ -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);