I need to change the behaviour of 'enter' to act like 'tab' in the browser. I have tried this code to trig another event in the enter event callBack.
const callBack = (e) => {
if (e.keyCode === 13) {
e.preventDefault();
e.stopPropagation();
document.dispatchEvent(
new KeyboardEvent("keydown", {
key: "Tab",
keyCode: 9, // example values.
code: "Tab", // put everything you need in this object.
which: 9,
shiftKey: false, // you don't need to include values
ctrlKey: false, // if you aren't going to use them.
metaKey: false, // these are here for example's sake.
})
);
}
document.addEventListener("keydown", callBack, false);
as I see console.log this code fire tab event but in the browser, the focus doesn't change as I expect to behave like pressing tab key.
any idea?