Skip to content

useHotkeyHint shows hints for hotkeys that are disabled or suspended by an exclusive scope #198

Closed

Description

@KevinVandy

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:

  1. Go to the Scopes route.
  2. Hold Alt. The Alt+E hint on "Edit details" and the Alt+N hint on the Inbox workspace show, as expected.
  3. Press Alt+E to open the Edit details dialog. It is exclusive and allows only global and shortcut-panel.
  4. 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, useHotkeyHint returns false unless its status is active. That covers enabled, 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)

https://github.com/TanStack/hotkeys/tree/main/examples/react/kitchen-sink (Scopes route)

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions