Skip to content

Commit

Permalink
Merge pull request smeup#2045 from apuliasoft/bugfix/button-key-disco…
Browse files Browse the repository at this point in the history
…nnected

bugfix(kup-button): added key shortcut checks
  • Loading branch information
pasere-smeup authored Sep 5, 2024
2 parents af636ba + ad5e525 commit e3826b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/ketchup/src/components/kup-button/kup-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ export class KupButton {

disconnectedCallback() {
this.kupManager.theme.unregister(this);
this.kupManager.keysBinding.unregister(this.keyShortcut);

if (this.keyShortcut) {
this.kupManager.keysBinding.unregister(this.keyShortcut);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class KupKeysBinding {
* @param {GenericCallback} event - Event to start when key is pressed
*/
register(key: string, event: GenericCallback): void {
if (!key || !event) {
return;
}

this.#keysEvents.set(key.toLowerCase(), { event, isLunched: false });
}

Expand All @@ -33,6 +37,9 @@ export class KupKeysBinding {
* @param {string} key - Key to remove.
*/
unregister(key: string): void {
if (!key) {
return;
}
this.#keysEvents.delete(key.toLowerCase());
}

Expand Down

0 comments on commit e3826b8

Please sign in to comment.