JSFiddle - React, Tailwind, and code Playground

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.

JavaScript

var canvas = document.getElementById("canvas");

function k(event) {
    event.stopPropagation();
    //event.preventDefault(); // kills the keypress
    console.log(event.type, event.target);
}

document.addEventListener("keydown", k, false);
document.addEventListener("keypress", k, false);
document.addEventListener("keyup", k, false);