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

Speak 'Block moved up/down' after using keyboard actions to move up/down #64966

Merged
36 changes: 26 additions & 10 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { __unstableUseShortcutEventMatch as useShortcutEventMatch } from '@wordp
import { useRef } from '@wordpress/element';
import { switchToBlockType, store as blocksStore } from '@wordpress/blocks';
import { speak } from '@wordpress/a11y';
import { __ } from '@wordpress/i18n';
import { __, sprintf, _n } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -92,19 +92,35 @@ export default function BlockTools( {
return;
}

if ( isMatch( 'core/block-editor/move-up', event ) ) {
if (
isMatch( 'core/block-editor/move-up', event ) ||
isMatch( 'core/block-editor/move-down', event )
) {
const clientIds = getSelectedBlockClientIds();
if ( clientIds.length ) {
event.preventDefault();
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
moveBlocksUp( clientIds, rootClientId );
}
} else if ( isMatch( 'core/block-editor/move-down', event ) ) {
const clientIds = getSelectedBlockClientIds();
if ( clientIds.length ) {
event.preventDefault();
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
moveBlocksDown( clientIds, rootClientId );
const direction = isMatch( 'core/block-editor/move-up', event )
? 'up'
: 'down';
if ( direction === 'up' ) {
moveBlocksUp( clientIds, rootClientId );
} else {
moveBlocksDown( clientIds, rootClientId );
}
const blockLength = Array.isArray( clientIds )
? clientIds.length
: 1;
const message = sprintf(
// translators: %d: the name of the block that has been moved
_n(
'%d block moved.',
'%d blocks moved.',
clientIds.length
),
blockLength
);
speak( message );
}
} else if ( isMatch( 'core/block-editor/duplicate', event ) ) {
const clientIds = getSelectedBlockClientIds();
Expand Down
Loading