ayrton / react-key-handler

React component to handle keyboard events :key:
http://ayrton.be/react-key-handler
388 stars 29 forks source link

ESC Doesn't work #73

Closed soheil-zz closed 7 years ago

soheil-zz commented 7 years ago
<KeyHandler keyEventName={KEYPRESS} keyCode={27} onKeyHandle={() => this.dismissOverlay()} />

That's what I have and it doesn't work. If I put 13 it'll work fine with Enter.

ayrton commented 7 years ago

In this case your keyEventName needs to be KEYDOWN or KEYUP not KEYPRESS.

PS I recommend not using key codes but key values like this:

<KeyHandler keyValue="Escape" onKeyHandle={() => this.dismissOverlay()} />

Note to self: it's important to write documentation for this behaviour https://github.com/ayrton/react-key-handler#key-event-names

http://stackoverflow.com/questions/3396754/onkeypress-vs-onkeyup-and-onkeydown