Repository navigation
Description
TanStack Hotkeys version
@tanstack/react-hotkeys v0.16.0 (@tanstack/hotkeys v0.17.0)
Framework/Library version
React v19
Describe the bug and the steps to reproduce it
useHotkeyHint returns true whenever the held modifiers match the hotkey, even when the hotkey can't fire. A hint should only show for a hotkey that would fire if pressed now: enabled, and not in a suspended scope.
Steps, in the React kitchen-sink example:
- Go to the Scopes route.
- Hold Alt. The
Alt+Ehint on "Edit details" and theAlt+Nhint on the Inbox workspace show, as expected. - Press Alt+E to open the Edit details dialog. It is exclusive and allows only
globalandshortcut-panel. - Hold Alt again.
Expected: no hints for scopes.edit or workspace.add. Their scopes are suspended, useAppHotkeyList reports them as suspended, and pressing them does nothing.
Actual: both hints still show behind the dialog.
The same thing happens for registrations with enabled: false. The example already works around that case by hand: the Hint component takes an enabled prop, and the workspace pane renders {current && <Hint id="workspace.add" />}.
The hook's doc comment currently says to "combine with the action's enabled state" and that it "does not check whether its target is focused". Apps can't easily combine it with scope state, though. useAppHotkeyList is the only public way to read an app hotkey's status, and it subscribes to the whole list.
Proposed change while the library is in v0:
- For an app hotkey,
useHotkeyHintreturnsfalseunless its status isactive. That coversenabled, suspended scopes, and app hotkeys that nothing has registered. - For registrations with a
target, also hide the hint while focus is outside the target. Not tested yet. - Decide what a plain hotkey (not an app hotkey) should do, since the hook has no registration to look at for it.
Current workaround:
const status = useAppHotkeyList().find((item) => item.appHotkey.id === id)?.status
const visible = useHotkeyHint(appHotkey) && status === 'active'Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
No response
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Activity