-
Notifications
You must be signed in to change notification settings - Fork 13.9k
feat(a11y): Bring keyboard shortcuts to a global context #40169
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ac62d51
chore: remove keyboard shortcuts contextualbar
dougfabris 35c43d1
feat: add keyboard shortcuts modal and integrate with user menu
dougfabris 77e3ba8
chore: remove outdated keyboard shortcut translations from various la…
dougfabris 1b4f174
feat: add keyboard shortcut to open keyboard shortcuts modal and upda…
dougfabris 075995e
chore: changeset
dougfabris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/i18n': patch | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Moves keyboard shortcuts from the contextual bar into a modal accessible from the user menu, and adds a hotkey to open it. |
19 changes: 0 additions & 19 deletions
19
apps/meteor/client/hooks/roomActions/useKeyboardShortcutListRoomAction.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
apps/meteor/client/navbar/NavBarSettingsToolbar/UserMenu/KeyboardShortcutsModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import { Box, Divider } from '@rocket.chat/fuselage'; | ||
| import { GenericModal } from '@rocket.chat/ui-client'; | ||
| import type { ReactElement } from 'react'; | ||
| import { Fragment, memo } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| type KeyCombo = { | ||
| mac: readonly string[]; | ||
| other: readonly string[]; | ||
| }; | ||
|
|
||
| type ShortcutDefinition = { | ||
| id: string; | ||
| descriptionKey: string; | ||
| combos: readonly KeyCombo[]; | ||
| }; | ||
|
|
||
| const SHORTCUTS: readonly ShortcutDefinition[] = [ | ||
| { | ||
| id: 'openKeyboardShortcuts', | ||
| descriptionKey: 'Keyboard_Shortcuts_Show_Keyboard_Shortcuts', | ||
| combos: [{ mac: ['Shift', '?'], other: ['Shift', '?'] }], | ||
| }, | ||
| { | ||
| id: 'openSearch', | ||
| descriptionKey: 'Keyboard_Shortcuts_Open_Channel_Slash_User_Search', | ||
| combos: [ | ||
| { mac: ['Command', 'P'], other: ['Control', 'P'] }, | ||
| { mac: ['Command', 'K'], other: ['Control', 'K'] }, | ||
| ], | ||
| }, | ||
| { | ||
| id: 'markAllAsRead', | ||
| descriptionKey: 'Keyboard_Shortcuts_Mark_all_as_read', | ||
| combos: [{ mac: ['Shift', 'Escape'], other: ['Control', 'Escape'] }], | ||
| }, | ||
| { | ||
| id: 'editPreviousMessage', | ||
| descriptionKey: 'Keyboard_Shortcuts_Edit_Previous_Message', | ||
| combos: [{ mac: ['ArrowUp'], other: ['ArrowUp'] }], | ||
| }, | ||
| { | ||
| id: 'moveToBeginningHorizontal', | ||
| descriptionKey: 'Keyboard_Shortcuts_Move_To_Beginning_Of_Message', | ||
| combos: [{ mac: ['Command', 'ArrowLeft'], other: ['Alt', 'ArrowLeft'] }], | ||
| }, | ||
| { | ||
| id: 'moveToBeginningVertical', | ||
| descriptionKey: 'Keyboard_Shortcuts_Move_To_Beginning_Of_Message', | ||
| combos: [{ mac: ['Command', 'ArrowUp'], other: ['Alt', 'ArrowUp'] }], | ||
| }, | ||
| { | ||
| id: 'moveToEndHorizontal', | ||
| descriptionKey: 'Keyboard_Shortcuts_Move_To_End_Of_Message', | ||
| combos: [{ mac: ['Command', 'ArrowRight'], other: ['Alt', 'ArrowRight'] }], | ||
| }, | ||
| { | ||
| id: 'moveToEndVertical', | ||
| descriptionKey: 'Keyboard_Shortcuts_Move_To_End_Of_Message', | ||
| combos: [{ mac: ['Command', 'ArrowDown'], other: ['Alt', 'ArrowDown'] }], | ||
| }, | ||
| { | ||
| id: 'newLine', | ||
| descriptionKey: 'Keyboard_Shortcuts_New_Line_In_Message', | ||
| combos: [{ mac: ['Shift', 'Enter'], other: ['Shift', 'Enter'] }], | ||
| }, | ||
| ]; | ||
|
|
||
| const KEY_LABEL_TRANSLATIONS: Record<string, string> = { | ||
| Command: 'Keyboard_Shortcut_Key_Command', | ||
| Control: 'Keyboard_Shortcut_Key_Control', | ||
| Option: 'Keyboard_Shortcut_Key_Option', | ||
| Alt: 'Keyboard_Shortcut_Key_Alt', | ||
| Shift: 'Keyboard_Shortcut_Key_Shift', | ||
| Enter: 'Keyboard_Shortcut_Key_Enter', | ||
| Escape: 'Keyboard_Shortcut_Key_Escape', | ||
| ArrowUp: 'Keyboard_Shortcut_Key_ArrowUp', | ||
| ArrowDown: 'Keyboard_Shortcut_Key_ArrowDown', | ||
| ArrowLeft: 'Keyboard_Shortcut_Key_ArrowLeft', | ||
| ArrowRight: 'Keyboard_Shortcut_Key_ArrowRight', | ||
| }; | ||
|
|
||
| const isMacPlatform = (): boolean => | ||
| typeof navigator !== 'undefined' && typeof navigator.platform === 'string' && navigator.platform.toLowerCase().includes('mac'); | ||
|
|
||
| type KeyboardShortcutsModalProps = { | ||
| onClose: () => void; | ||
| }; | ||
|
|
||
| const KeyboardShortcutsModal = ({ onClose }: KeyboardShortcutsModalProps): ReactElement => { | ||
| const { t } = useTranslation(); | ||
| const isMac = isMacPlatform(); | ||
|
|
||
| return ( | ||
| <GenericModal icon='keyboard' variant='info' title={t('Keyboard_Shortcuts_Title')} cancelText={t('Close')} onCancel={onClose}> | ||
| <Box is='dl' aria-label={t('Keyboard_Shortcuts_Title')} m={0}> | ||
| {SHORTCUTS.map(({ id, descriptionKey, combos }) => ( | ||
| <Box key={id} mbe={12}> | ||
| <Box is='dt' fontScale='p2m' fontWeight='700' mbe={4}> | ||
| {t(descriptionKey)} | ||
| </Box> | ||
| <Box is='dd' fontScale='p2' m={0} mbe={8}> | ||
| {combos.map((combo, comboIndex) => { | ||
| const keys = isMac ? combo.mac : combo.other; | ||
| return ( | ||
| <Fragment key={comboIndex}> | ||
| {comboIndex > 0 && ( | ||
| <Box is='span' mi={8} color='hint'> | ||
| {t('or')} | ||
| </Box> | ||
| )} | ||
| <Box is='kbd'> | ||
| {keys.map((token, tokenIndex) => ( | ||
| <Fragment key={tokenIndex}> | ||
| {tokenIndex > 0 && ( | ||
| <Box is='span' mi={4} aria-hidden='true'> | ||
| + | ||
| </Box> | ||
| )} | ||
| <Box is='kbd'>{KEY_LABEL_TRANSLATIONS[token] ? t(KEY_LABEL_TRANSLATIONS[token]) : token}</Box> | ||
| </Fragment> | ||
| ))} | ||
| </Box> | ||
| </Fragment> | ||
| ); | ||
| })} | ||
| </Box> | ||
|
tassoevan marked this conversation as resolved.
|
||
| <Divider aria-hidden='true' m={0} /> | ||
| </Box> | ||
| ))} | ||
| </Box> | ||
| </GenericModal> | ||
| ); | ||
| }; | ||
|
|
||
| export default memo(KeyboardShortcutsModal); | ||
12 changes: 12 additions & 0 deletions
12
...r/client/navbar/NavBarSettingsToolbar/UserMenu/hooks/useKeyboardShortcutsModalHandler.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { useSetModal } from '@rocket.chat/ui-contexts'; | ||
|
|
||
| import KeyboardShortcutsModal from '../KeyboardShortcutsModal'; | ||
|
|
||
| export const useKeyboardShortcutsModalHandler = () => { | ||
| const setModal = useSetModal(); | ||
|
|
||
| return () => { | ||
| const handleModalClose = () => setModal(null); | ||
| setModal(<KeyboardShortcutsModal onClose={handleModalClose} />); | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
apps/meteor/client/views/room/contextualBar/KeyboardShortcuts/KeyboardShortcutSection.tsx
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
apps/meteor/client/views/room/contextualBar/KeyboardShortcuts/KeyboardShortcuts.stories.tsx
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
apps/meteor/client/views/room/contextualBar/KeyboardShortcuts/KeyboardShortcuts.tsx
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
apps/meteor/client/views/room/contextualBar/KeyboardShortcuts/KeyboardShortcutsWithData.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
apps/meteor/client/views/room/contextualBar/KeyboardShortcuts/index.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
apps/meteor/client/views/root/hooks/useKeyboardShortcutsHotkey.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { useSetModal } from '@rocket.chat/ui-contexts'; | ||
| import { useEffect } from 'react'; | ||
| import tinykeys from 'tinykeys'; | ||
|
|
||
| import KeyboardShortcutsModal from '../../../navbar/NavBarSettingsToolbar/UserMenu/KeyboardShortcutsModal'; | ||
|
|
||
| const shouldIgnoreKeyStroke = (target: EventTarget | null): boolean => { | ||
| if (!(target instanceof Element)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (target instanceof HTMLElement && target.isContentEditable) { | ||
| return true; | ||
| } | ||
|
|
||
| const { tagName } = target; | ||
| if (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') { | ||
| return true; | ||
| } | ||
|
|
||
| return target.closest('dialog[open]') !== null; | ||
| }; | ||
|
|
||
| export const useKeyboardShortcutsHotkey = () => { | ||
| const setModal = useSetModal(); | ||
|
|
||
| useEffect(() => { | ||
| const handler = (event: KeyboardEvent) => { | ||
| if (shouldIgnoreKeyStroke(event.target)) { | ||
| return; | ||
| } | ||
|
|
||
| event.preventDefault(); | ||
|
|
||
| const handleClose = () => setModal(null); | ||
| setModal(<KeyboardShortcutsModal onClose={handleClose} />); | ||
| }; | ||
|
|
||
| return tinykeys(window, { | ||
| 'Shift+?': handler, | ||
| }); | ||
| }, [setModal]); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.