-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add support for keyboard shortcuts to <MenuItemLink>
#10790
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
Conversation
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.
Great work! I love this feature!
className, | ||
hasDashboard: hasDashboardProp, | ||
...rest | ||
} = props; |
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.
If you just want to discard hasDashboard
, what about using _
instead of hasDashboardProp
?
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.
That's how we usually do it
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.
That's a good start but you should also add a general "keyboard shortcut" chapter to make it discoverable through search ,explaining how to add shortcuts for menu items and for custom actions.
Also, could you please add shortcuts to the simple example menu ?
if (open && keyboardShortcut != null) { | ||
return ( | ||
<Tooltip | ||
title={getKeyboardShortcutLabel(keyboardShortcut)} |
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.
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.
I don't know how to represent sequential shortcuts like this
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.
We decided to just add a space between all keys, sequential or not
useHotkeys, | ||
} from 'react-hotkeys-hook'; | ||
|
||
export const KeyboardShortcut = (props: KeyboardShortcutProps) => { |
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.
please add jsDoc to explain why we need that (to add a keyboard shortcut conditionally? I so, why don't we use the "enabled" option?)
export const getKeyboardShortcutLabel = (keyboardShortcut: Keys) => { | ||
if (typeof keyboardShortcut === 'string') { | ||
return keyboardShortcut.split('+').join(' + '); | ||
} | ||
return keyboardShortcut | ||
.map(shortcut => getKeyboardShortcutLabel(shortcut)) | ||
.join(', '); | ||
}; |
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 a bit short, we'd need to be smarter than that and show icons for key modifiers dependent on the platform (e.g. command / windows)
If you don't mind, I'll add this new page when we'll have more components supporting keyboard shortcuts (buttons, etc.) |
Co-authored-by: Jean-Baptiste Kaiser <jb@marmelab.com>
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.
Awesome user experience! I even tested the shortcuts when editing a fom, and the hook is smart enough not to trigger them in this case.
@@ -0,0 +1,119 @@ | |||
import * as React from 'react'; |
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.
Seeing this file at the root of src, it seems to have a bigger importance that it actually has. I'd put this component (and its story) under the layout
directory.
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.
You remember that we will probably use it for buttons too?
This PR adds support for keyboard shortcuts to
<MenuItemLink>
How To Test
https://react-admin-storybook-git-menu-item-keyboard-shortcuts-marmelab.vercel.app/?path=/story/ra-ui-materialui-layout-menu--with-keyboard-shortcuts
Additional Checks
master
for a bugfix or a documentation fix, ornext
for a featureAlso, please make sure to read the contributing guidelines.