Skip to content

Instantly share code, notes, and snippets.

@surajitbasak109
Created February 10, 2020 20:21
Show Gist options
  • Save surajitbasak109/376bf5b1ceadfc8bce14078089551727 to your computer and use it in GitHub Desktop.
Save surajitbasak109/376bf5b1ceadfc8bce14078089551727 to your computer and use it in GitHub Desktop.
hanldeKeyup(evt) {
//...more code...
}
hanldeKeydown(evt) {
const { cursor, searchItems } = this.state;
// arrow up/down button should select next/previous list element
if (evt.keyCode === 38 && cursor > 0) {
this.setState(prevState => ({
cursor: prevState.cursor - 1
}));
} else if (evt.keyCode === 40 && cursor < searchItems.length - 1) {
this.setState(prevState => ({
cursor: prevState.cursor + 1
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment