is-hotkey icon indicating copy to clipboard operation
is-hotkey copied to clipboard

[Bug] Doesn't work with `KeyboardEvent` constructor

Open mahaveer0496 opened this issue 2 years ago • 3 comments

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

mahaveer0496 avatar Sep 19 '21 16:09 mahaveer0496

Interesting, do you know why that’s happening?

ianstormtaylor avatar Sep 25 '21 14:09 ianstormtaylor

const e = new KeyboardEvent("keydown", {
    shiftKey: true,
    key: "Tab",
    which: 9
  });
  console.log(e.which) // 0 

SCWR avatar Oct 12 '21 10:10 SCWR

@SCWR first check here is for key key, so that should work regardless 🤔

mahaveer0496 avatar Oct 13 '21 06:10 mahaveer0496