-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new keyboard shortcuts for block settings menu (#8279)
Adds new keyboard shortcuts for the block settings menu: Cmd+Shift+D / Ctrl+Shift+D - duplicate block Cmd+shift+, / Ctrl+shift+, - show/hide sidebar * Add duplicate shortcut to block settings menu - Move onDuplicate dispatch from BlockDuplicateButton into a new HOC called `withBlockSettingsActions` - Add `shortcuts` as a prop in `withBlockSettingsActions` that is passed to its wrapped component - Pass onDuplicate and shortcut through to BlockDuplicateButton - Add new BlockSettingsKeyboardShortcuts component for handling shortcut functionality Make BlockDuplicateButton a dumb component - move HOC logic to withBlockSettingsActions Add keyboard shortcut for block removal (Cmd/Special/Windows + DEL) - Move block remove action dispatch from BlockRemoveButton up to withBlockSettingsActions - Make BlockRemoveButton a dumb component - Add keyboard shortcut for block removal to BlockSettingsKeyboardShortcuts - Pass onRemove into KeyboardShortcuts and BlockRemoveButton Add shortcut for toggling the sidebar - Add shortcut keys to list of keyboard shortcuts for edit-post - Add open/close dispatchers to EditorModeKeyboardShortcuts and hook up - Make BlockInspectorButton display the keyboard shortcut MenuItem should use aria-checked attribute instead of aria-pressed See example implementation of a MenuBar here for details: https://www.w3.org/TR/wai-aria-practices/examples/menubar/menubar-2/menubar-2.html Provide a default role for MenuItem component of menuitem Still allows the role to be overriden for other menuitem types (i.e. menuitemcheckbox, menuitemradio), but defaults to menuitem. Also makes the provision of isSelected prop optional since the resulting aria-checked role should not be used with a menu-item. Update usages of MenuItem that should not use the default role Switch menu items in block settings menu that have a shortcut to use MenuItem Use the MenuItem component which correctly renders the shortcut. The need for wrapping components BlockDuplicateButton and BlockRemoveButton is minimal, so remove them. Remove role props, since MenuItem implements a default Make all block settings menu items use MenuItem component instead of IconButton Spread additional props for MenuItem onto rendered component This allows MenuItem to support additional props like `disabled` Remove stroke being applied to MenuItem icons Most icons don't have stroke - this style rule was adding an additional stroke to SVG icons, making them appear chunky and blurry. Remove use of !important Fix lack of left margin on menu items with icons Fix potential access of undefined property When removing the block, there's momentarily a null item in the blocks array Render block settings when typing, but make it hidden This ensures BlockSettingsKeyboardShortcuts is rendered and shortcuts work while actively typing * Rename shortcut keycodes to raw/display to match block settings menu * displayShortcut removes `+` symbol between shortcuts when the provided key is any single character * displayShortcut capitalizes provided key (e.g. Del instead of DEL) * Avoid placing a + between ⌘ and key entirely * Change duplicate shortcut to Cmd/Ctrl shift D * Change toggleSidebar shortcut to `cmd/ctrl + shift + ,` to avoid conflict with Chrome settings shortcut * When toggling the sidebar using the keyboard, open the correct tab based on whether block(s) are selected * Add keyboard shortcuts to tooltips for closing and opening the settings sidebar * Make use of stopImmediatePropagation less zealous Code is supposed to prevent further handling of keyboard events when a block is deleted, but doesn't consider cases where a block is not deleted: - If the user hits delete and the block is kept, but content from another block merged in - If the user hits delete, but the block has content and is thus not deleted * Add modifier key exceptions to prevent deletion or merge of blocks * Make block deletion shortcut Cmd+Opt+Backspace or Cmd+Opt+Delete - For Windows that's Ctrl+Alt+Backspace or Ctrl+Alt+Delete * Add further clauses where event should return early Iron out inconsistent behaviour with use of backspace/delete key when it can result in deletion or merging of blocks. When specific modifiers are pressed the event should not have any effect. Here, the use of preventDefault and stopImmediatePropagation were blocking further binding of keyboard shortcuts and preventing browser/system level keyboard shortcuts. * Make keyboard shortcut for delete Cmd+Alt+Delete * Abbreviate display shortcut to prevent line wrapping in block settings menu * Merge `withBlockSettingsActions` into `BlockSettingsMenu` - BlockSettingsMenu was the only consumer of withBlockSettings - shortcuts object is now not injected into props * Remove BlockSettingsKeyboardShortcuts component, which had no logic * Use preventDefault to prevent any additional browser/os shortcuts and add comments * Use object method shorthand * Add !important back in, with clarifying comment * Use lodash noop over noop arrow function * Destructure dispatching functions * Refine exceptions to RichText Backspace/Delete handling * Remove the Remove Block shortcut * Revert changes to RichText back to master version * Fix unit tests (stylelint)
- Loading branch information
Showing
31 changed files
with
243 additions
and
265 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
Oops, something went wrong.