Skip to content

Bugfix: Add back Hotkey.hotkey (removed in prev release) #1258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

OhadC
Copy link

@OhadC OhadC commented May 19, 2025

This PR is returning the parameter Hotkey.hotkey (that was in v4, and removed in v5).

Changes:

  • Add back Hotkey.hotkey (removed in prev release)
  • Remove the need to pass dependencies
  • memo provider values

This PR will solve: #1225 #964
After the fix:
image

OhadC added 2 commits May 19, 2025 14:30
* Add back Hotkey.hotkey (removed in prev release)
* Remove the need to pass dependencies
* memo provider values
Copy link

vercel bot commented May 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-hotkeys-hook ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2025 11:59am

@@ -245,7 +222,7 @@ export default function useHotkeys<T extends HTMLElement>(
clearTimeout(sequenceTimer)
}
}
}, [_keys, memoisedOptions, activeScopes])
}, [_keys, memoisedOptions, activeScopes, proxy, _callback])
Copy link
Author

@OhadC OhadC May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memoisedOptions.ignoreEventWhen can cause the effect to run on each render.
I think that we can destructure the options before the effect itself, and use useEventCallback on ignoreEventWhen

@eithe
Copy link

eithe commented Jun 25, 2025

Would love to get this back in so it's easy to match which hotkey was pressed in the useHotkeys callback . i.e.

useHotkeys(
  shortcuts,
  (keyEvent, { hotkey }) => {
    // Find the matching menu item based on the triggered key
    const matchingItem = Object.values(shortcutItems).find((item) => hotkey === item.shortcut);

    if (matchingItem) {
      handleItemSelect(matchingItem);
      keyEvent.preventDefault();
    }
  },
);

However, this PR seems to have other, more or less related, changes so maybe a bit difficult for the maintainer to review this? Maybe it should be even more to-the-point if possible?

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.

2 participants