omridevk / ng-keyboard-shortcuts

Dead Simple Keyboard Shortcuts Management for Angular
https://ng-keyboard-shortcuts.vercel.app/
147 stars 34 forks source link

Make the help screen close by pressing escape #15

Closed pszalanski closed 5 years ago

pszalanski commented 5 years ago

It would be great if I could close the help screen by pressing escape.

omridevk commented 5 years ago

@pszalanski Will add in the next release, that's a great idea Thanks :) For now, as a workaround, you can do the following (in the component where you render the help screen):

@ViewChild(KeyboardShortcutsHelpComponent) helpComponent: KeyboardShortcutsHelpComponent;

then you can add a custom shortcut component in your template that will close the help screen using the public method exposed by the component (toggle). I'll soon provide a codesendbox example.

omridevk commented 5 years ago

see example here: https://codesandbox.io/s/00m8ozl0v0

pszalanski commented 5 years ago

Great! Thanks for replying so quickly.

Good workaround, I'll try it out if I find the time. Otherwise waiting for the next version is also fine by me.

omridevk commented 5 years ago

@pszalanski As I do not want to hard code the close key binding, I would rather add another @Input to the help screen component, closeKey or something similar, that will allow you to pass whatever key you want(escape key in your case). I am currently thinking if I want to default it to escape(or not to provide default), since it will mean that escape will always be a shortcut in your app, while you might want to use it for something different. As until the next major version, this library only supports one key binding, so there can't be two commands registered to the "escape" key, only the first to register will fire. In the next major release, I am going to add support for same key binding in different commands (the behavior will be that all commands will be fired. no support for stop bubbling is planned at the moment), then it would make more sense to have a default Escape key for the help screen. Please let me know if you have an input on the matter, as any suggestions will help my decision. Thanks.

omridevk commented 5 years ago

added closeKey input to ng-keyboard-shortcuts-help

omridevk commented 5 years ago

Please re-open if not working for some reason. Thanks for the suggestion.