Skip to content

Instantly share code, notes, and snippets.

@marshallmurphy
Created May 3, 2020 23:34
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 marshallmurphy/91a2ba74bd27915f93b42f6031fc0aba to your computer and use it in GitHub Desktop.
Save marshallmurphy/91a2ba74bd27915f93b42f6031fc0aba to your computer and use it in GitHub Desktop.
...
const ToggleRow = ({ option }) => {
const [active, setActive] = useState(false);
// onKeyDown function for handling enter (13) press
function handleToggle(e) {
e.keyCode === 13 && setActive(!active);
}
return (
<div className={styles.toggleRow}>
{option}
<label className={styles.toggle} tabIndex='0' onKeyDown={e => handleToggle(e)}> // add onKeyDown function
<input
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment