Skip to content

Commit

Permalink
Speak 'Block moved up/down' after using keyboard actions to move up/d…
Browse files Browse the repository at this point in the history
…own (WordPress#64966)

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

* Created internal helper function to create description for speak function

* Refactor away from helper function and simplify

* Add short confirmation message after block has been moved up|down

* End with period. Speak singular or plural

* Speak the amount of moved blocks

Co-authored-by: n2erjo00 <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: afercia <[email protected]>
Co-authored-by: alexstine <[email protected]>
Co-authored-by: ciampo <[email protected]>
Co-authored-by: talksina <[email protected]>
Co-authored-by: enricobattocchi <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: mtias <[email protected]>
  • Loading branch information
10 people authored Nov 1, 2024
1 parent 7ec6d6f commit 98f6210
Showing 1 changed file with 26 additions and 10 deletions.
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

0 comments on commit 98f6210

Please sign in to comment.