I need to set up combination of buttons in input form of my react app.
- "CTRL + "ArrowUp"
- "ArrowUp"
My code is something like this.
//Form
<input onKeyDown={keyHandler}/>
//handler
const keyhandler = (e) => {
if(e.key === "ArrowUp") {//do something}
if(e.key === 'ArrowUp' && e.getModifierState("Control")) {//do another thing}
The problem is when event fired with combination, first 'if' also true. How separate "ArrowUp" and "ArrowUp" with ctrl button?
I also try like this (but it didn't help):
if(e.key === 'ArrowUp' && event.ctrlKey){ //do another thing}
Aucun commentaire:
Enregistrer un commentaire