Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix description logic for new blocks without inner blocks. Remove ann…
…ouncement for blocks that do not need it.
  • Loading branch information
alexstine committed Mar 29, 2022
commit 35d528308b1eca72bf5257d0a3fc43d424938d82
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import { useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '../../../store';

export function useBlockScreenReaderDescription( clientId ) {
const { hasChildBlocks, blockTitle } = useSelect(
const { hasChildBlocks, blockTitle, canSupportChildBlocks } = useSelect(
( select ) => {
const { getBlockRootClientId, getBlockName, getBlock } = select(
blockEditorStore
);
const {
getBlockRootClientId,
getBlockName,
getBlock,
getBlockListSettings,
} = select( blockEditorStore );
const clientIdToUse = getBlockRootClientId( clientId );
const blockName = getBlockName(
clientIdToUse ? clientIdToUse : clientId
Expand All @@ -25,19 +28,32 @@ export function useBlockScreenReaderDescription( clientId ) {
getBlock( clientIdToUse ? clientIdToUse : clientId )
?.innerBlocks?.length > 0,
blockTitle: blockType?.title,
canSupportChildBlocks: getBlockListSettings(
clientIdToUse ? clientIdToUse : clientId
),
};
},
[ clientId ]
);
let description;
if ( hasChildBlocks ) {
description = sprintf(
// Translators: 1: The block title to lowercase for good sentence structure.
__( 'Child block of %1$s.' ),
blockTitle.toLowerCase()
);
} else {
description = __( 'Testing non-child block description.' );
if ( canSupportChildBlocks ) {
if ( hasChildBlocks ) {
description = sprintf(
// Translators: 1: The block title to lowercase for good sentence structure.
__(
'Press Escape key to navigate child blocks of %1$s.'
),
blockTitle.toLowerCase()
);
} else {
description = sprintf(
// Translators: 1: The block title to lowercase for good sentence structure.
__(
'Press Tab followed by Enter keys to add a child block to %s.'
),
blockTitle.toLowerCase()
);
}
}
return description;
}