Skip to content

Commit

Permalink
Fix Widgets page Undo and Redo accessibility and keyboard interaction (
Browse files Browse the repository at this point in the history
…#57677)

* Fix styling and focus style.

* Fix Widgets toolbar Undo and Redo buttons keyboard interaction.
  • Loading branch information
afercia authored Jan 11, 2024
1 parent 47026ab commit b64eec7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function DocumentTools() {
className="edit-widgets-header-toolbar"
aria-label={ __( 'Document tools' ) }
shouldUseKeyboardFocusShortcut={ ! blockToolbarCanBeFocused }
variant="unstyled"
>
<ToolbarItem
ref={ inserterButton }
Expand All @@ -104,8 +105,8 @@ function DocumentTools() {
/>
{ isMediumViewport && (
<>
<UndoButton />
<RedoButton />
<ToolbarItem as={ UndoButton } />
<ToolbarItem as={ RedoButton } />
<ToolbarItem
as={ Button }
className="edit-widgets-header-toolbar__list-view-toggle"
Expand Down
3 changes: 1 addition & 2 deletions packages/edit-widgets/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
align-items: center;
justify-content: center;
flex-shrink: 2;
overflow-x: hidden;
padding-left: $grid-unit-20;
}

Expand All @@ -67,7 +66,7 @@
}

.edit-widgets-header-toolbar {
border: none;
gap: $grid-unit-10;

// The Toolbar component adds different styles to buttons, so we reset them
// here to the original button styles
Expand Down
11 changes: 8 additions & 3 deletions packages/edit-widgets/src/components/header/undo-redo/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* WordPress dependencies
*/
import { __, isRTL } from '@wordpress/i18n';
import { ToolbarButton } from '@wordpress/components';
import { Button } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons';
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';
import { forwardRef } from '@wordpress/element';

export default function RedoButton() {
function RedoButton( props, ref ) {
const shortcut = isAppleOS()
? displayShortcut.primaryShift( 'z' )
: displayShortcut.primary( 'y' );
Expand All @@ -19,7 +20,9 @@ export default function RedoButton() {
);
const { redo } = useDispatch( coreStore );
return (
<ToolbarButton
<Button
{ ...props }
ref={ ref }
icon={ ! isRTL() ? redoIcon : undoIcon }
label={ __( 'Redo' ) }
shortcut={ shortcut }
Expand All @@ -31,3 +34,5 @@ export default function RedoButton() {
/>
);
}

export default forwardRef( RedoButton );
11 changes: 8 additions & 3 deletions packages/edit-widgets/src/components/header/undo-redo/undo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
* WordPress dependencies
*/
import { __, isRTL } from '@wordpress/i18n';
import { ToolbarButton } from '@wordpress/components';
import { Button } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { undo as undoIcon, redo as redoIcon } from '@wordpress/icons';
import { displayShortcut } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';
import { forwardRef } from '@wordpress/element';

export default function UndoButton() {
function UndoButton( props, ref ) {
const hasUndo = useSelect(
( select ) => select( coreStore ).hasUndo(),
[]
);
const { undo } = useDispatch( coreStore );
return (
<ToolbarButton
<Button
{ ...props }
ref={ ref }
icon={ ! isRTL() ? undoIcon : redoIcon }
label={ __( 'Undo' ) }
shortcut={ displayShortcut.primary( 'z' ) }
Expand All @@ -27,3 +30,5 @@ export default function UndoButton() {
/>
);
}

export default forwardRef( UndoButton );

0 comments on commit b64eec7

Please sign in to comment.