Skip to content

Commit

Permalink
Add aria labels for shortcuts in keyboard shortcut help modal
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Sep 3, 2018
1 parent 14344f7 commit 8e11cdb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion edit-post/components/keyboard-shortcut-help-modal/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { displayShortcutList } from '@wordpress/keycodes';
import { displayShortcutList, shortcutAriaLabel } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';

const {
Expand Down Expand Up @@ -42,14 +42,17 @@ const globalShortcuts = {
{
keyCombination: primaryShift( ',' ),
description: __( 'Show or hide the settings sidebar.' ),
ariaLabel: shortcutAriaLabel.primaryShift( ',' ),
},
{
keyCombination: ctrl( '`' ),
description: __( 'Navigate to a the next part of the editor.' ),
ariaLabel: shortcutAriaLabel.ctrl( '`' ),
},
{
keyCombination: ctrlShift( '`' ),
description: __( 'Navigate to the previous part of the editor.' ),
ariaLabel: shortcutAriaLabel.ctrlShift( '`' ),
},
{
keyCombination: shiftAlt( 'n' ),
Expand All @@ -76,6 +79,8 @@ const selectionShortcuts = {
{
keyCombination: 'Esc',
description: __( 'Clear selection.' ),
/* translators: The 'escape' key on a keyboard. */
ariaLabel: __( 'Escape' ),
},
],
};
Expand All @@ -102,6 +107,8 @@ const blockShortcuts = {
{
keyCombination: '/',
description: __( 'Change the block type after adding a new paragraph.' ),
/* translators: The forward-slash character. e.g. '/'. */
ariaLabel: __( 'Forward-slash' ),
},
],
};
Expand Down
4 changes: 2 additions & 2 deletions edit-post/components/keyboard-shortcut-help-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ const mapKeyCombination = ( keyCombination ) => keyCombination.map( ( character,

const ShortcutList = ( { shortcuts } ) => (
<dl className="edit-post-keyboard-shortcut-help__shortcut-list">
{ shortcuts.map( ( { keyCombination, description }, index ) => (
{ shortcuts.map( ( { keyCombination, description, ariaLabel }, index ) => (
<div
className="edit-post-keyboard-shortcut-help__shortcut"
key={ index }
>
<dt className="edit-post-keyboard-shortcut-help__shortcut-term">
<kbd className="edit-post-keyboard-shortcut-help__shortcut-key-combination">
<kbd className="edit-post-keyboard-shortcut-help__shortcut-key-combination" aria-label={ ariaLabel }>
{ mapKeyCombination( castArray( keyCombination ) ) }
</kbd>
</dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ
],
},
Object {
"ariaLabel": "Control + Shift + Comma",
"description": "Show or hide the settings sidebar.",
"keyCombination": Array [
"Ctrl",
Expand All @@ -73,6 +74,7 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ
],
},
Object {
"ariaLabel": "Control + Backtick",
"description": "Navigate to a the next part of the editor.",
"keyCombination": Array [
"Ctrl",
Expand All @@ -81,6 +83,7 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ
],
},
Object {
"ariaLabel": "Control + Shift + Backtick",
"description": "Navigate to the previous part of the editor.",
"keyCombination": Array [
"Ctrl",
Expand Down Expand Up @@ -139,6 +142,7 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ
],
},
Object {
"ariaLabel": "Escape",
"description": "Clear selection.",
"keyCombination": "Esc",
},
Expand Down Expand Up @@ -191,6 +195,7 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ
],
},
Object {
"ariaLabel": "Forward-slash",
"description": "Change the block type after adding a new paragraph.",
"keyCombination": "/",
},
Expand Down
1 change: 0 additions & 1 deletion packages/keycodes/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export const shortcutAriaLabel = mapValues( modifiers, ( modifier ) => {
'.': __( 'Period' ),
/* translators: backtick as in the character '`' */
'`': __( 'Backtick' ),
esc: 'Escape',
};

return [ ...modifier( _isApple ), character ]
Expand Down

0 comments on commit 8e11cdb

Please sign in to comment.