Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created October 25, 2019 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/dcaaae7db870a44532c42e58cf60513f to your computer and use it in GitHub Desktop.
Save andreasvirkus/dcaaae7db870a44532c42e58cf60513f to your computer and use it in GitHub Desktop.
onKeydown(e) {
const { toggleSidebar, next, previous } = this.props;
const keyMapping = new Map([
[ 83, toggleSidebar ], // user presses the s button
[ 37, next ], // user presses the right arrow
[ 39, previous ] // user presses the left arrow
]);
if (keyMapping.has(e.which)) {
e.preventDefault();
keyMapping.get(e.which)();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment