Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion packages/block-editor/src/hooks/block-rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const withBlockRenameControl = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const { name, attributes, setAttributes, isSelected } = props;

const supportsBlockNaming = hasBlockSupport( name, 'renaming', true );
const supportsBlockNaming = hasBlockSupport(
name,
'__experimentalMetadata',
false
);

return (
<>
Expand Down
71 changes: 71 additions & 0 deletions test/e2e/specs/editor/various/block-renaming.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ test.describe( 'Block Renaming', () => {
},
] );
} );

test( 'does not allow renaming of blocks that do not support the feature', async ( {
editor,
page,
pageUtils,
} ) => {
await pageUtils.pressKeys( 'access+o' );

const listView = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// Only Group supports renaming.
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'First Paragraph' },
} );

// Multiselect via keyboard.
await pageUtils.pressKeys( 'primary+a' );

const listViewParagraphNode = listView.getByRole( 'gridcell', {
name: 'Paragraph',
exact: true,
selected: true,
} );

await expect( listViewParagraphNode ).toBeVisible();

// Expect the Rename control not to exist at all.
await expect(
listViewParagraphNode.getByRole( 'menuitem', {
name: 'Rename',
} )
).toBeHidden();
} );
} );

test.describe( 'Block inspector renaming', () => {
Expand Down Expand Up @@ -219,5 +255,40 @@ test.describe( 'Block Renaming', () => {
},
] );
} );

test( 'does now allow renaming of blocks that do not support the feature', async ( {
editor,
page,
pageUtils,
} ) => {
// Only Group supports renaming.
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'First Paragraph' },
} );

// Multiselect via keyboard.
await pageUtils.pressKeys( 'primary+a' );

await editor.openDocumentSettingsSidebar();

const advancedPanelToggle = page
.getByRole( 'region', {
name: 'Editor settings',
} )
.getByRole( 'button', {
name: 'Advanced',
expanded: false,
} );

await advancedPanelToggle.click();

// Expect the Rename control not to exist at all.
await expect(
page.getByRole( 'textbox', {
name: 'Block name',
} )
).toBeHidden();
} );
} );
} );