I need to activate a function when the Delete or Backspace keys are pressed. The call is made inside a number input filed which is part of a form. This works:
onKeyUp={((e) => this.onCero(e))}
This does not work:
onKeyDown ={((e) => this.onCero(e))}
The function I am calling:
onCero = (e) => {
e.preventDefault();
if (e.key === "Delete" || e.key === "Backspace") {
alert(e.key);
}
};
I need to trigger the function when the key is pressed, not when it is released using React or JavaScript.
Any ideas guys? Thanks.