Skip to content

Commit

Permalink
Change shortcut text for redo tooltip on Windows (#42830)
Browse files Browse the repository at this point in the history
* A11y: add Ctrl+Y text for redo tooltip on Windows

* Change shortcut text for redo tooltip on Windows
  • Loading branch information
t-hamano committed Aug 2, 2022
1 parent 9171278 commit 22ba73a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
8 changes: 6 additions & 2 deletions packages/customize-widgets/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createPortal, useState, useEffect } from '@wordpress/element';
import { __, _x, isRTL } from '@wordpress/i18n';
import { ToolbarButton } from '@wordpress/components';
import { NavigableToolbar } from '@wordpress/block-editor';
import { displayShortcut } from '@wordpress/keycodes';
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
import { plus, undo as undoIcon, redo as redoIcon } from '@wordpress/icons';

/**
Expand All @@ -31,6 +31,10 @@ function Header( {
sidebar.hasRedo(),
] );

const shortcut = isAppleOS()
? displayShortcut.primaryShift( 'z' )
: displayShortcut.primary( 'y' );

useEffect( () => {
return sidebar.subscribeHistory( () => {
setUndoRedo( [ sidebar.hasUndo(), sidebar.hasRedo() ] );
Expand Down Expand Up @@ -64,7 +68,7 @@ function Header( {
icon={ ! isRTL() ? redoIcon : undoIcon }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Redo' ) }
shortcut={ displayShortcut.primaryShift( 'z' ) }
shortcut={ shortcut }
// If there are no undo levels we don't want to actually disable this
// button, because it will remove focus for keyboard users.
// See: https://github.com/WordPress/gutenberg/issues/3486
Expand Down
8 changes: 6 additions & 2 deletions packages/edit-navigation/src/components/header/redo-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { __, isRTL } from '@wordpress/i18n';
import { ToolbarButton } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons';
import { displayShortcut } from '@wordpress/keycodes';
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';

export default function RedoButton() {
const shortcut = isAppleOS()
? displayShortcut.primaryShift( 'z' )
: displayShortcut.primary( 'y' );

const hasRedo = useSelect(
( select ) => select( coreStore ).hasRedo(),
[]
Expand All @@ -18,7 +22,7 @@ export default function RedoButton() {
<ToolbarButton
icon={ ! isRTL() ? redoIcon : undoIcon }
label={ __( 'Redo' ) }
shortcut={ displayShortcut.primaryShift( 'z' ) }
shortcut={ shortcut }
// If there are no undo levels we don't want to actually disable this
// button, because it will remove focus for keyboard users.
// See: https://github.com/WordPress/gutenberg/issues/3486
Expand Down
8 changes: 6 additions & 2 deletions packages/edit-site/src/components/header/undo-redo/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { __, isRTL } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons';
import { displayShortcut } from '@wordpress/keycodes';
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';
import { forwardRef } from '@wordpress/element';

function RedoButton( props, ref ) {
const shortcut = isAppleOS()
? displayShortcut.primaryShift( 'z' )
: displayShortcut.primary( 'y' );

const hasRedo = useSelect(
( select ) => select( coreStore ).hasRedo(),
[]
Expand All @@ -21,7 +25,7 @@ function RedoButton( props, ref ) {
ref={ ref }
icon={ ! isRTL() ? redoIcon : undoIcon }
label={ __( 'Redo' ) }
shortcut={ displayShortcut.primaryShift( 'z' ) }
shortcut={ shortcut }
// If there are no undo levels we don't want to actually disable this
// button, because it will remove focus for keyboard users.
// See: https://github.com/WordPress/gutenberg/issues/3486
Expand Down
8 changes: 6 additions & 2 deletions packages/edit-widgets/src/components/header/undo-redo/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { __, isRTL } from '@wordpress/i18n';
import { ToolbarButton } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons';
import { displayShortcut } from '@wordpress/keycodes';
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';

export default function RedoButton() {
const shortcut = isAppleOS()
? displayShortcut.primaryShift( 'z' )
: displayShortcut.primary( 'y' );

const hasRedo = useSelect(
( select ) => select( coreStore ).hasRedo(),
[]
Expand All @@ -18,7 +22,7 @@ export default function RedoButton() {
<ToolbarButton
icon={ ! isRTL() ? redoIcon : undoIcon }
label={ __( 'Redo' ) }
shortcut={ displayShortcut.primaryShift( 'z' ) }
shortcut={ shortcut }
// If there are no undo levels we don't want to actually disable this
// button, because it will remove focus for keyboard users.
// See: https://github.com/WordPress/gutenberg/issues/3486
Expand Down
8 changes: 6 additions & 2 deletions packages/editor/src/components/editor-history/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { __, isRTL } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { displayShortcut } from '@wordpress/keycodes';
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons';
import { forwardRef } from '@wordpress/element';

Expand All @@ -14,6 +14,10 @@ import { forwardRef } from '@wordpress/element';
import { store as editorStore } from '../../store';

function EditorHistoryRedo( props, ref ) {
const shortcut = isAppleOS()
? displayShortcut.primaryShift( 'z' )
: displayShortcut.primary( 'y' );

const hasRedo = useSelect(
( select ) => select( editorStore ).hasEditorRedo(),
[]
Expand All @@ -26,7 +30,7 @@ function EditorHistoryRedo( props, ref ) {
icon={ ! isRTL() ? redoIcon : undoIcon }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Redo' ) }
shortcut={ displayShortcut.primaryShift( 'z' ) }
shortcut={ shortcut }
// If there are no redo levels we don't want to actually disable this
// button, because it will remove focus for keyboard users.
// See: https://github.com/WordPress/gutenberg/issues/3486
Expand Down

0 comments on commit 22ba73a

Please sign in to comment.