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
Allow keyboard shortcuts #10713
Allow keyboard shortcuts #10713
Conversation
Add handler for keyboard shortcuts
|
Hi @Link2Twenty, interesting! What if we integrate https://github.com/github/hotkey ? It'd be great if we'd eventually work towards a keyboard shortcuts modal populated by the registered shortcuts on each page, something like this: |
Makes objects clearer.
|
It looks like hotkeys is only for interacting with specific elements. Whereas this way you can call any function you like including, but not limited to, dom interactions. I liked how they registered their shortcuts, was much cleaner than my way so I've borrowed that. |
|
Super clean @Link2Twenty ! I've implemented something similar in #10468 that is called It would be nice to merge our efforts to go in the right direction with forem native shortcuts. My component doesn't handle key modifiers like I've already implemented Tell me what you think, feedback is appreciated! 🌞 Then, as @rhymes said, we could create an issue to work on a store that is fed by the calls to that very component. With that store, build a modal that lists all the available shortcuts for a given page. |
update to allow single character shortcuts/hotkeys
|
Thanks @reobin 😊 I've updated my code to allow it to cope with single key shortcuts now, similar to hotkeys. @nickytonline is this the sort of direction you'd like to see this go? If so we could get this merged then Reobin and I could look at using this in #10468 |
|
@Link2Twenty I really like the work you and @reobin are doing on this! 😄 |
Add inline documentation for the component.
|
Just got out of the stream. Taking a peek now @Link2Twenty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Link2Twenty, thanks for the PR! This is looking good. Just some questions.
@Link2Twenty I think going with use effect makes sense. I made a suggestion to consider making what you're proposing a custom hook. See PR review comments. Update 10 minutes after writing first paragraph.😄 I saw @reobin's PR is using a custom hook, https://github.com/forem/forem/pull/10468/files#diff-976b57823cb7a305a55921032b2708aeR45, so I think a custom hook with |
|
@nickytonline any further thought or are we good to go? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good @Link2Twenty. I have some suggestions, but they do not block the PR.
One blocker though is we need some tests. If you need to see an example of testing hooks, take a peek at https://github.com/forem/forem/blob/master/app/javascript/utilities/__tests__/dragAndDrop.test.js and if you have any questions, let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for being patient as there was a lot of back and forth and thanks so much for the PR @Link2Twenty! 🚀
|
Good job @Link2Twenty ! It seems stable enough. I'll start integrating this in #10468 some time tonight |
|
@nickytonline thanks for the help hopefully I'll have a better understanding of tests now 😅 @reobin thank you, sorry for the hold up 😬 |
|
Quick question @nickytonline @Link2Twenty : is Edit: Was thinking more about |
@reobin, for common components |
|
Just realised a problem with using |
|
Pulled the changes and all is well 👍 |
|
Hey @Ridhwana any progress on this? 😊 (no rush, of course, just curious) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me 🚀

What type of PR is this? (check all applicable)
Description
Add handler for keyboard shortcuts. This allows custom shortcuts to be set up on a page by page (or even component by component) basis.
React demo
Usage
In this example we're going to run a function when the user presses CTRL+SHIFT+P
Related Tickets & Documents
related: #5023 #596
QA Instructions, Screenshots, Recordings
This facilitates changes in the future
Added tests?
Added to documentation?
[optional] Are there any post deployment tasks we need to perform?
Once this is merged I'd like to modify this current shortcut to use this method before thinking about what other shortcuts could/should be added.
[optional] What gif best describes this PR or how it makes you feel?