JSFiddle - React, Tailwind, and code Playground
by jfriend00
HTML
Click in here, press a button on the keyboard, and then look at your console. Once you enable <code>event.preventDefault()</code> you won't see a <code>keypress</code> anymore.
<br><br>
<textarea id="test" cols="80" rows="10">Some editable text</textarea>
JavaScript
var test = document.getElementById("test");
function k(event) {
event.stopPropagation();
event.preventDefault(); // kills the keypress
console.log(event.type, event.target);
}
test.addEventListener("keydown", k, false);
test.addEventListener("keypress", k, false);
test.addEventListener("keyup", k, false);