From 98f62101f98f3b491810f2dc9f6a6de135318687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20Erkkil=C3=A4?= <62872075+n2erjo00@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:26:47 +0200 Subject: [PATCH] Speak 'Block moved up/down' after using keyboard actions to move up/down (#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 Co-authored-by: t-hamano Co-authored-by: afercia Co-authored-by: alexstine Co-authored-by: ciampo Co-authored-by: talksina Co-authored-by: enricobattocchi Co-authored-by: youknowriad Co-authored-by: mtias --- .../src/components/block-tools/index.js | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/packages/block-editor/src/components/block-tools/index.js b/packages/block-editor/src/components/block-tools/index.js index 700b345be2027..e6c49af6b6106 100644 --- a/packages/block-editor/src/components/block-tools/index.js +++ b/packages/block-editor/src/components/block-tools/index.js @@ -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 @@ -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();