Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Widgets page Undo and Redo accessibility and keyboard interaction #57677

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
Loading