omridevk / ng-keyboard-shortcuts

Dead Simple Keyboard Shortcuts Management for Angular

Home Page:https://ng-keyboard-shortcuts.vercel.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ShortcutInput "target" trigger the command even if the target element is NOT in focus

amr-alamir opened this issue · comments

I can't get the target prop of ShortcutInput interface to limit command triggering only when the target is in focus.

I created this stackblitz in which a value is supposed to change with up and down arrow only if input has focus

here is a code snippet

{
    key: "down",
    preventDefault: true,
    command: () => --this.val,
    target: this.input.nativeElement,
}

In either case ( input focused or not ) value is still changing.

what am I doing wrong? or is this a bug?

commented

It seems like a regression, i'll have look into it, will update tomorrow.
Thanks for reporting the issue.

commented

And thanks for the stackblitz which made it a lot easier to see the issue.

commented

Yes, this indeed seems like a regression bug, i'll fix it ASAP. thanks a lot for reporting the issue (this issue only happens when using sequences, and since one key counts as sequence (at least as far as the code goes).
Sorry for the inconvenience.

commented

k, found the root cause of the issue:
https://github.com/omridevk/ng-keyboard-shortcuts/blob/master/projects/ng-keyboard-shortcuts/src/lib/ng-keyboard-shortcuts.service.ts#L155-L157
seems like I have not implemented the same behavior in the sequences code.
Will have a new version released tomorrow. thanks for the patience and again thanks for catching the issue.
Hopefully my tests (going to add some) will catch these kind of regressions in the future.

Thank you for the quick response and for all these efforts that make our life easier ☺.

commented

@amr-alamir
Fixed in version:
https://github.com/omridevk/ng-keyboard-shortcuts/releases/tag/8.2.5

Please feel free to update via NPM.
And please let me know if the issue persist.

commented

Closing, please re-open if issue persist.

Thank you for the fix, and here is the working stackblitz

commented

I'll update the documentation example to include such use use cass