diff --git a/edit-post/components/header/fixed-toolbar-toggle/index.js b/edit-post/components/header/fixed-toolbar-toggle/index.js index eb7080d2c653f1..c80452c12a7f32 100644 --- a/edit-post/components/header/fixed-toolbar-toggle/index.js +++ b/edit-post/components/header/fixed-toolbar-toggle/index.js @@ -17,6 +17,7 @@ function FixedToolbarToggle( { onToggle, isActive } ) { icon={ isActive && 'yes' } isSelected={ isActive } onClick={ onToggle } + role="menuitemcheckbox" > { __( 'Fix Toolbar to Top' ) } diff --git a/edit-post/components/header/index.js b/edit-post/components/header/index.js index 41e9afe41e63e9..35549ef7818118 100644 --- a/edit-post/components/header/index.js +++ b/edit-post/components/header/index.js @@ -19,6 +19,7 @@ import './style.scss'; import MoreMenu from './more-menu'; import HeaderToolbar from './header-toolbar'; import PinnedPlugins from './pinned-plugins'; +import shortcuts from '../../keyboard-shortcuts'; function Header( { isEditorSidebarOpened, @@ -59,6 +60,7 @@ function Header( { onClick={ toggleGeneralSidebar } isToggled={ isEditorSidebarOpened } aria-expanded={ isEditorSidebarOpened } + shortcut={ shortcuts.toggleSidebar.display } > { __( 'You’ll find more settings for your page and blocks in the sidebar. Click ‘Settings’ to open it.' ) } diff --git a/edit-post/components/header/mode-switcher/index.js b/edit-post/components/header/mode-switcher/index.js index 527e77f1011172..9b1e9198821f64 100644 --- a/edit-post/components/header/mode-switcher/index.js +++ b/edit-post/components/header/mode-switcher/index.js @@ -29,7 +29,7 @@ const MODES = [ function ModeSwitcher( { onSwitch, mode } ) { const choices = MODES.map( ( choice ) => { if ( choice.value !== mode ) { - return { ...choice, shortcut: shortcuts.toggleEditorMode.label }; + return { ...choice, shortcut: shortcuts.toggleEditorMode.display }; } return choice; } ); diff --git a/edit-post/components/header/plugin-sidebar-more-menu-item/index.js b/edit-post/components/header/plugin-sidebar-more-menu-item/index.js index fa36e95c38b412..403e8aeb1c3e7e 100644 --- a/edit-post/components/header/plugin-sidebar-more-menu-item/index.js +++ b/edit-post/components/header/plugin-sidebar-more-menu-item/index.js @@ -17,6 +17,7 @@ const PluginSidebarMoreMenuItem = ( { children, icon, isSelected, onClick } ) => { children } diff --git a/edit-post/components/header/tips-toggle/index.js b/edit-post/components/header/tips-toggle/index.js index 807fd3eb652edb..3ad90c80daf995 100644 --- a/edit-post/components/header/tips-toggle/index.js +++ b/edit-post/components/header/tips-toggle/index.js @@ -15,6 +15,7 @@ function TipsToggle( { onToggle, isActive } ) { { __( 'Show Tips' ) } diff --git a/edit-post/components/keyboard-shortcuts/index.js b/edit-post/components/keyboard-shortcuts/index.js index 91667b2b54fda4..625f29e99bccd2 100644 --- a/edit-post/components/keyboard-shortcuts/index.js +++ b/edit-post/components/keyboard-shortcuts/index.js @@ -16,6 +16,7 @@ class EditorModeKeyboardShortcuts extends Component { super( ...arguments ); this.toggleMode = this.toggleMode.bind( this ); + this.toggleSidebar = this.toggleSidebar.bind( this ); } toggleMode() { @@ -23,12 +24,26 @@ class EditorModeKeyboardShortcuts extends Component { switchMode( mode === 'visual' ? 'text' : 'visual' ); } + toggleSidebar( event ) { + // This shortcut has no known clashes, but use preventDefault to prevent any + // obscure shortcuts from triggering. + event.preventDefault(); + const { isEditorSidebarOpen, closeSidebar, openSidebar } = this.props; + + if ( isEditorSidebarOpen ) { + closeSidebar(); + } else { + openSidebar(); + } + } + render() { return ( ); @@ -36,16 +51,19 @@ class EditorModeKeyboardShortcuts extends Component { } export default compose( [ - withSelect( ( select ) => { - return { - mode: select( 'core/edit-post' ).getEditorMode(), - }; - } ), - withDispatch( ( dispatch ) => { - return { - switchMode: ( mode ) => { - dispatch( 'core/edit-post' ).switchEditorMode( mode ); - }, - }; - } ), + withSelect( ( select ) => ( { + mode: select( 'core/edit-post' ).getEditorMode(), + isEditorSidebarOpen: select( 'core/edit-post' ).isEditorSidebarOpened(), + hasBlockSelection: !! select( 'core/editor' ).getBlockSelectionStart(), + } ) ), + withDispatch( ( dispatch, { hasBlockSelection } ) => ( { + switchMode( mode ) { + dispatch( 'core/edit-post' ).switchEditorMode( mode ); + }, + openSidebar() { + const sidebarToOpen = hasBlockSelection ? 'edit-post/block' : 'edit-post/document'; + dispatch( 'core/edit-post' ).openGeneralSidebar( sidebarToOpen ); + }, + closeSidebar: dispatch( 'core/edit-post' ).closeGeneralSidebar, + } ) ), ] )( EditorModeKeyboardShortcuts ); diff --git a/edit-post/components/sidebar/sidebar-header/index.js b/edit-post/components/sidebar/sidebar-header/index.js index b548b4e28c4de2..19b58e26ab5c0b 100644 --- a/edit-post/components/sidebar/sidebar-header/index.js +++ b/edit-post/components/sidebar/sidebar-header/index.js @@ -16,6 +16,7 @@ import { withDispatch, withSelect } from '@wordpress/data'; * Internal dependencies */ import './style.scss'; +import shortcuts from '../../../keyboard-shortcuts'; const SidebarHeader = ( { children, className, closeLabel, closeSidebar, title } ) => { return ( @@ -36,6 +37,7 @@ const SidebarHeader = ( { children, className, closeLabel, closeSidebar, title } onClick={ closeSidebar } icon="no-alt" label={ closeLabel } + shortcut={ shortcuts.toggleSidebar.display } /> diff --git a/edit-post/components/visual-editor/block-inspector-button.js b/edit-post/components/visual-editor/block-inspector-button.js index e6014d55e025b9..f29f081f8a2c8d 100644 --- a/edit-post/components/visual-editor/block-inspector-button.js +++ b/edit-post/components/visual-editor/block-inspector-button.js @@ -7,10 +7,15 @@ import { flow, noop } from 'lodash'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { IconButton, withSpokenMessages } from '@wordpress/components'; +import { MenuItem, withSpokenMessages } from '@wordpress/components'; import { withSelect, withDispatch } from '@wordpress/data'; import { compose } from '@wordpress/compose'; +/** + * Internal dependencies + */ +import shortcuts from '../../keyboard-shortcuts'; + export function BlockInspectorButton( { areAdvancedSettingsOpened, closeSidebar, @@ -18,7 +23,6 @@ export function BlockInspectorButton( { onClick = noop, small = false, speak, - role, } ) { const speakMessage = () => { if ( areAdvancedSettingsOpened ) { @@ -31,15 +35,15 @@ export function BlockInspectorButton( { const label = areAdvancedSettingsOpened ? __( 'Hide Block Settings' ) : __( 'Show Block Settings' ); return ( - { ! small && label } - + ); } diff --git a/edit-post/components/visual-editor/index.js b/edit-post/components/visual-editor/index.js index df1852492117e3..eb4cc9523e531b 100644 --- a/edit-post/components/visual-editor/index.js +++ b/edit-post/components/visual-editor/index.js @@ -34,7 +34,7 @@ function VisualEditor() { <_BlockSettingsMenuFirstItem> - { ( { onClose } ) => } + { ( { onClose } ) => } <_BlockSettingsMenuPluginsExtension> { ( { clientIds, onClose } ) => } diff --git a/edit-post/keyboard-shortcuts.js b/edit-post/keyboard-shortcuts.js index 100ad546c063e3..be46a74a601864 100644 --- a/edit-post/keyboard-shortcuts.js +++ b/edit-post/keyboard-shortcuts.js @@ -5,7 +5,11 @@ import { rawShortcut, displayShortcut } from '@wordpress/keycodes'; export default { toggleEditorMode: { - value: rawShortcut.secondary( 'm' ), - label: displayShortcut.secondary( 'm' ), + raw: rawShortcut.secondary( 'm' ), + display: displayShortcut.secondary( 'm' ), + }, + toggleSidebar: { + raw: rawShortcut.primaryShift( ',' ), + display: displayShortcut.primaryShift( ',' ), }, }; diff --git a/packages/components/src/menu-item/index.js b/packages/components/src/menu-item/index.js index 8bbdf95c03e00b..27460ce0e0f1ec 100644 --- a/packages/components/src/menu-item/index.js +++ b/packages/components/src/menu-item/index.js @@ -21,7 +21,7 @@ import IconButton from '../icon-button'; * * @return {WPElement} More menu item. */ -function MenuItem( { children, className, icon, onClick, shortcut, isSelected = false } ) { +function MenuItem( { children, className, icon, onClick, shortcut, isSelected, role = 'menuitem', ...props } ) { className = classnames( 'components-menu-item__button', className, { 'has-icon': icon, } ); @@ -40,7 +40,9 @@ function MenuItem( { children, className, icon, onClick, shortcut, isSelected = className={ className } icon={ icon } onClick={ onClick } - aria-pressed={ isSelected } + aria-checked={ isSelected } + role={ role } + { ...props } > { children } @@ -52,7 +54,9 @@ function MenuItem( { children, className, icon, onClick, shortcut, isSelected =