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>
This commit is contained in:
parent
4df134ec96
commit
07c0d304bc
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bytelyst/use-keyboard-shortcuts",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user