Skip to content

Commit

Permalink
Block Switcher: Use a different label for multi-selection (WordPress#…
Browse files Browse the repository at this point in the history
…54692)

* Block Switcher: Use a different label for multi-selection

* Update snapshot

* Adjust e2e tests
  • Loading branch information
Mamaduka authored Sep 21, 2023
1 parent c7d0e6e commit 8ab2a97
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
35 changes: 17 additions & 18 deletions packages/block-editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
clientId: Array.isArray( clientIds ) ? clientIds[ 0 ] : clientIds,
maximumLength: 35,
} );
const isReusable = blocks.length === 1 && isReusableBlock( blocks[ 0 ] );
const isTemplate = blocks.length === 1 && isTemplatePart( blocks[ 0 ] );

const isSingleBlock = blocks.length === 1;
const isReusable = isSingleBlock && isReusableBlock( blocks[ 0 ] );
const isTemplate = isSingleBlock && isTemplatePart( blocks[ 0 ] );

function selectForMultipleBlocks( insertedBlocks ) {
if ( insertedBlocks.length > 1 ) {
Expand Down Expand Up @@ -162,24 +164,21 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => {
);
}

const blockSwitcherLabel = blockTitle;
const blockSwitcherLabel = isSingleBlock
? blockTitle
: __( 'Multiple blocks selected' );

const blockSwitcherDescription =
1 === blocks.length
? sprintf(
/* translators: %s: block title. */
__( '%s: Change block type or style' ),
blockTitle
)
: sprintf(
/* translators: %d: number of blocks. */
_n(
'Change type of %d block',
'Change type of %d blocks',
blocks.length
),
const blockSwitcherDescription = isSingleBlock
? __( 'Change block type or style' )
: sprintf(
/* translators: %d: number of blocks. */
_n(
'Change type of %d block',
'Change type of %d blocks',
blocks.length
);
),
blocks.length
);

const hasBlockOrBlockVariationTransforms =
hasPossibleBlockTransformations ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports[`BlockSwitcherDropdownMenu should render enabled block switcher with mul
aria-describedby="components-button__description-2"
aria-expanded="false"
aria-haspopup="true"
aria-label="Block Name"
aria-label="Multiple blocks selected"
class="components-button components-dropdown-menu__toggle has-icon"
data-toolbar-item="true"
type="button"
Expand Down Expand Up @@ -105,7 +105,7 @@ exports[`BlockSwitcherDropdownMenu should render switcher with blocks 1`] = `
<span
id="components-button__description-0"
>
Block Name: Change block type or style
Change block type or style
</span>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/specs/editor/blocks/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,9 @@ test.describe( 'List (@firefox)', () => {
<p>2</p>
<!-- /wp:paragraph -->` );

await page.getByRole( 'button', { name: 'Paragraph' } ).click();
await page
.getByRole( 'button', { name: 'Multiple blocks selected' } )
.click();
await page.getByRole( 'menuitem', { name: 'List' } ).click();

expect( await editor.getEditedPostContent() ).toBe( `<!-- wp:list -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test.describe( 'Keep styles on block transforms', () => {
await pageUtils.pressKeys( 'shift+ArrowUp' );
await pageUtils.pressKeys( 'shift+ArrowUp' );
await page.click( 'role=radio[name="Large"i]' );
await page.click( 'role=button[name="Paragraph"i]' );
await page.click( 'role=button[name="Multiple blocks selected"i]' );
await page.click( 'role=menuitem[name="Heading"i]' );

await expect.poll( editor.getBlocks ).toMatchObject( [
Expand Down

0 comments on commit 8ab2a97

Please sign in to comment.