brtnshrdr / angular2-hotkeys

Keyboard shortcuts for Angular 2 apps
MIT License
203 stars 95 forks source link

Multiple the same combo #104

Open piernik opened 5 years ago

piernik commented 5 years ago

In my app I can open multiple modals. I want to close them with esc key. So in every modal I'm adding combo with this.hotkeysService.add() which returns HotKey | Hotkey []. But when in second modal I'm removing combo with this.hotkeysService.remove(hotKey) using hotKey instance created in second modal it removes all esc instances and esc key does not work with first modal.

wittlock commented 5 years ago

I think the easiest way to solve this is to just add the one hotkey for esc that will call a method in a service you've created and this service keeps track of any open modals and close them when it's pressed. That way you don't need to keep adding/removing the hotkey in this module.

I'll try to keep this in mind for if I try to rebuild how the remove-method works, but I doubt that will happen anytime soon, so I suggest going with the workaround mentioned above instead.