RobertWHurst / Keystrokes

Keystrokes as an easy to use library for binding functions to keys and key combos. It can be used with any TypeScript or JavaScript project, even in non-browser environments.
MIT License
158 stars 6 forks source link

originalEvent.composedPath() return empty array #2

Closed Senasiko closed 1 year ago

Senasiko commented 1 year ago

Describe the bug when use composedPath in bindKeyCombo callback, return empty array.

bindKeyCombo('Meta + z', (e) => {
    const path = e.originalEvent.composedPath(); // path is []
});

The issue seems to be that callback exec in next micro task https://stackoverflow.com/questions/62181537/why-does-composedpath-on-event-returns-different-value-when-delayed

Expected behavior return true array

Additional context Add any other context about the problem here.

RobertWHurst commented 1 year ago

I'll have a look at this today. Out of curiosity, what are you using the method for?

RobertWHurst commented 1 year ago

@Senasiko have a look at #3 if you wish. I'll be adding a test case to verify the fix as well as test the new mapper function before it's merged. Given that you have looked through the code, and that this PR should fix your use case I'd be interested in your thoughts.

Senasiko commented 1 year ago

Oh thanks. I use composedPath() to determine event whether triggered in the dom I expect.

I'll have a look at this today. Out of curiosity, what are you using the method for?

RobertWHurst commented 1 year ago

Ok, I've added a few tests and fixed a bug. Next is updating the docs. I'll take a pass at that tonight, then I should be able to roll out a release shortly after that.

RobertWHurst commented 1 year ago

Sorry that took so long. The latest release has your composedPath now.