From f708137e6efa67131c138eb2d9cc77a587c2634f Mon Sep 17 00:00:00 2001 From: p-bemportato Date: Thu, 5 Sep 2024 14:00:30 +0000 Subject: [PATCH 1/2] bugfix(kup-button): unregister key shortcut if exists --- packages/ketchup/src/components/kup-button/kup-button.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/ketchup/src/components/kup-button/kup-button.tsx b/packages/ketchup/src/components/kup-button/kup-button.tsx index 852e84646b..405e4736f1 100644 --- a/packages/ketchup/src/components/kup-button/kup-button.tsx +++ b/packages/ketchup/src/components/kup-button/kup-button.tsx @@ -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); + } } } From ad5e52563ff209fea2eb17c05ee270c4e814feca Mon Sep 17 00:00:00 2001 From: p-bemportato Date: Thu, 5 Sep 2024 14:16:08 +0000 Subject: [PATCH 2/2] fix: add checks --- .../src/managers/kup-keys-binding/kup-keys-binding.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/ketchup/src/managers/kup-keys-binding/kup-keys-binding.ts b/packages/ketchup/src/managers/kup-keys-binding/kup-keys-binding.ts index 4005c1fb8f..f31255d2bf 100644 --- a/packages/ketchup/src/managers/kup-keys-binding/kup-keys-binding.ts +++ b/packages/ketchup/src/managers/kup-keys-binding/kup-keys-binding.ts @@ -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 }); } @@ -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()); }