TanStack Hotkeys version
0.10.0
Framework/Library version
React 18.3.1
Describe the bug and the steps to reproduce it
Issue:
The space key can be used (at least on Mac) to trigger a focussed element such as a button.
The smart default (smart default: false for Mod+S, true for single keys) doesn't take this behavior into account.
This means once a useHotkey('Space',...-shortcut is set up this behavior is lost.
Likely a similar case for the "Enter"-key
Expected behavior:
It should make an exception for button-like (buttons, checkboxes, links, etc.) to preserve native behavior. i.e. "click" the button if focused, even if a 'Short'-hotkey is set.
My workaround:
const isNothingFocused = () => {
return document.activeElement === document.body || document.activeElement === null;
};
useHotkey('Space', () => {
if (isNothingFocused()) {
doSomeAction();
} else {
// Allow space for confirmation
(document.activeElement as HTMLElement)?.click();
}
});
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
https://codesandbox.io/p/sandbox/stoic-snyder-59xd9x
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
No, because I do not know how or whether it follows your design principles
Terms & Code of Conduct
TanStack Hotkeys version
0.10.0
Framework/Library version
React 18.3.1
Describe the bug and the steps to reproduce it
Issue:
The space key can be used (at least on Mac) to trigger a focussed element such as a button.
The smart default (
smart default: false for Mod+S, true for single keys) doesn't take this behavior into account.This means once a
useHotkey('Space',...-shortcut is set up this behavior is lost.Likely a similar case for the "Enter"-key
Expected behavior:
It should make an exception for button-like (buttons, checkboxes, links, etc.) to preserve native behavior. i.e. "click" the button if focused, even if a 'Short'-hotkey is set.
My workaround:
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
https://codesandbox.io/p/sandbox/stoic-snyder-59xd9x
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
No, because I do not know how or whether it follows your design principles
Terms & Code of Conduct