Skip to content

fix(hooks): add input guard and exact modifier matching to useKeyboardShortcut (#30) - #80

Open
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/use-keyboard-shortcut-input-guard-and-exact-modifiers
Open

ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/use-keyboard-shortcut-input-guard-and-exact-modifiers

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Addresses and fixes #30 by correcting two core behavioral defects in useKeyboardShortcut:

  1. Input target guard: Added isInputElement guard to prevent shortcuts from unintentionally hijacking keystrokes while the user is typing inside <input>, <textarea>, <select>, or contenteditable elements, while allowing explicit override via allowInInputs?: boolean.
  2. Exact modifier matching: Fixed modifier evaluation to verify that active modifier keys (ctrlKey, metaKey, altKey, shiftKey) strictly match expected modifiers rather than only testing if the specified modifier is present, preventing spurious matches when extra held modifiers (e.g. Ctrl+Shift+K for a Ctrl+K shortcut) are pressed. Supports single modifiers or arrays of modifiers.
  3. Unit tests: Added complete test suite in src/hooks/useKeyboardShortcut.test.ts covering basic match, extra modifier exclusion, composite modifiers, form control input suppression, and allowInInputs opt-in.

Closes #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useKeyboardShortcut fires inside text inputs/textareas and doesn't exclude extra held modifiers

1 participant