From 07c0d304bc051cdbf92c88f10e8a374a24db1419 Mon Sep 17 00:00:00 2001 From: Saravanakumar D Date: Sat, 30 May 2026 01:02:00 -0700 Subject: [PATCH] fix(use-keyboard-shortcuts): guard against undefined e.key and shortcut.key Some keyboard events (dead keys, modifier-only presses) have e.key as undefined. Similarly, malformed shortcut definitions may lack a key. Added early-return guards to prevent TypeError. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- packages/use-keyboard-shortcuts/package.json | 2 +- packages/use-keyboard-shortcuts/src/use-keyboard-shortcuts.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/use-keyboard-shortcuts/package.json b/packages/use-keyboard-shortcuts/package.json index 206652a8..7cc55a1d 100644 --- a/packages/use-keyboard-shortcuts/package.json +++ b/packages/use-keyboard-shortcuts/package.json @@ -1,6 +1,6 @@ { "name": "@bytelyst/use-keyboard-shortcuts", - "version": "0.1.7", + "version": "0.1.8", "type": "module", "exports": { ".": { diff --git a/packages/use-keyboard-shortcuts/src/use-keyboard-shortcuts.ts b/packages/use-keyboard-shortcuts/src/use-keyboard-shortcuts.ts index 75657404..fd4a0981 100644 --- a/packages/use-keyboard-shortcuts/src/use-keyboard-shortcuts.ts +++ b/packages/use-keyboard-shortcuts/src/use-keyboard-shortcuts.ts @@ -32,9 +32,11 @@ export function useKeyboardShortcuts(shortcuts: ShortcutDef[]): void { } function handleKeyDown(e: KeyboardEvent) { + if (!e.key) return; const inInput = isInputElement(e.target); for (const shortcut of shortcuts) { + if (!shortcut.key) continue; const metaMatch = shortcut.meta ? e.metaKey || e.ctrlKey : !(e.metaKey || e.ctrlKey); const shiftMatch = shortcut.shift ? e.shiftKey : !e.shiftKey; const altMatch = shortcut.alt ? e.altKey : !e.altKey;