is-hotkey
is-hotkey copied to clipboard
[Bug] Doesn't work with `KeyboardEvent` constructor
The following code returns false instead of true
const e = new KeyboardEvent("keydown", {
key: "Tab",
code: "Tab",
which: "9",
shiftKey: true
});
console.log(e.shiftKey, e.key);
console.log(isHotKey("shift+Tab", e));
Use case - Was mocking keyboard events in jest unit tests. Codesandbox - https://codesandbox.io/s/affectionate-haibt-f0kbx?file=/src/App.js:109-299
Interesting, do you know why that’s happening?
const e = new KeyboardEvent("keydown", {
shiftKey: true,
key: "Tab",
which: 9
});
console.log(e.which) // 0
@SCWR first check here is for key
key, so that should work regardless 🤔