In my React app, I cannot stop propagation of keyboard events from Material UI TextField.
Example of the problem - pressing the backspace key inside the textfield triggers a delete operation in my authoring environment.
On change in the Material UI component:
<TextField onChange={handleChange} />
I try to stop propagation:
const handleChange = event => {
event.stopPropagation();
// ...
};
But this does not stop my other event listener from firing:
document.addEventListener("keydown", onKeyDown);
const onKeyDown = event => {
switch (event.code) {
case "Backspace":
case "Delete":
// ...
break;
}
Ultimately not a big deal as I can change the scope of my keydown listener from document
to the canvas
element it's intended to work with, but curious if there was a suggestion here.