Skip to content

Commit

Permalink
display suggestions when up/down keys pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
carloluis committed Feb 16, 2018
1 parent 40894ec commit d64282f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/suggestor/Suggestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class Suggestor extends PureComponent {
}
processKey(code) {
const { open, index, filtered, value } = this.state;
const list = filtered.map(item => item.word);
const ssuggestions = filtered.length ? filtered : this.unfilter();

switch (code) {
case keys.ENTER:
if (open && list[index]) {
this.changeValue(list[index], true);
if (open && filtered[index]) {
this.changeValue(filtered[index].word, true);
} else {
this.setState({ open: true, filtered: this.unfilter() });
}
Expand All @@ -85,18 +85,18 @@ class Suggestor extends PureComponent {
}
break;
case keys.DOWN: {
const next = (index + open) % list.length;
this.setState({ open: true, index: next });
const next = (index + open) % ssuggestions.length;
this.setState({ open: true, index: next, filtered: ssuggestions });
break;
}
case keys.UP: {
const prev = (index || list.length) - 1;
this.setState({ open: true, index: prev });
const prev = (index || ssuggestions.length) - 1;
this.setState({ open: true, index: prev, filtered: ssuggestions });
break;
}
case keys.TAB:
if (this.props.selectOnTab && open && list[index]) {
this.changeValue(list[index], true);
if (this.props.selectOnTab && open && filtered[index]) {
this.changeValue(filtered[index].word, true);
} else {
this.handleClose();
}
Expand Down

0 comments on commit d64282f

Please sign in to comment.