Skip to content

Commit

Permalink
Announce when block inserted in list view
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jan 10, 2023
1 parent 7a17f01 commit 891db0c
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import classnames from 'classnames';
*/
import { useSelect } from '@wordpress/data';
import { forwardRef, useEffect, useState } from '@wordpress/element';
import { speak } from '@wordpress/a11y';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -18,6 +20,7 @@ import { store as blockEditorStore } from '../../store';
import { updateAttributes } from './update-attributes';
import { LinkUI } from './link-ui';
import { useInsertedBlock } from './use-inserted-block';
import useBlockDisplayTitle from '../block-title/use-block-display-title';

const BLOCKS_WITH_LINK_UI_SUPPORT = [
'core/navigation-link',
Expand All @@ -42,6 +45,12 @@ const ListViewBlockContents = forwardRef(
) => {
const { clientId } = block;
const [ isLinkUIOpen, setIsLinkUIOpen ] = useState();

const blockTitle = useBlockDisplayTitle( {
clientId,
context: 'list-view',
} );

const {
blockMovingClientId,
selectedBlockInBlockEditor,
Expand Down Expand Up @@ -89,6 +98,16 @@ const ListViewBlockContents = forwardRef(
hasExistingLinkValue,
] );

useEffect( () => {
if ( clientId === lastInsertedBlockClientId && blockTitle ) {
speak(
// translators: %s: name of block being inserted (i.e. Paragraph, Image, Group etc)
sprintf( __( '%s block inserted' ), blockTitle ),
'assertive'
);
}
}, [ lastInsertedBlockClientId, clientId, blockTitle ] );

const isBlockMoveTarget =
blockMovingClientId && selectedBlockInBlockEditor === clientId;

Expand Down

0 comments on commit 891db0c

Please sign in to comment.