JSFiddle - React, Tailwind, and code Playground
by Stefano
HTML
Hello World!
JavaScript
document.addEventListener('keydown', function (e) {
console.log('listener called')
if (e.defaultPrevented) {
console.log('default prevented already')
return; // Do nothing if the event was already processed
}
const key = e.key || e.keyCode;
if (key === 'Escape' || key === 'Esc' || key === 27) {
console.warn('Escape is not allowed at this point.');
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
e.cancelBubble = true;
}
console.log('done');
});