diff --git a/src/react-components/link-root.js b/src/react-components/link-root.js index 92126c32bcc7e5cafe6b767a38cd89cf388dc7c2..9cd126016aee57eaca630e6387223c08eef79ee5 100644 --- a/src/react-components/link-root.js +++ b/src/react-components/link-root.js @@ -23,6 +23,25 @@ class LinkRoot extends Component { failedAtLeastOnce: false }; + componentWillMount = () => { + document.addEventListener("keydown", this.handleKeyDown); + }; + + componentWillUnmount = () => { + document.removeEventListener("keydown", this.handleKeyDown); + }; + + handleKeyDown = e => { + if (e.keyCode < 48 || e.keyCode > 57) { + return; + } + + e.preventDefault(); + e.stopPropagation(); + + this.addDigit(e.keyCode - 48); + }; + addDigit = digit => { if (this.state.enteredDigits.length >= MAX_DIGITS) return; const newDigits = [...this.state.enteredDigits, digit];