From 11a3660d8da8a8f5c4fbcd6e06a7a693e4df53c1 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 9 Jan 2025 17:49:33 +0400 Subject: [PATCH] Fix edited block name's initial state and fallback --- packages/block-editor/src/components/block-rename/modal.js | 7 ++++--- test/e2e/specs/editor/various/block-renaming.spec.js | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/block-rename/modal.js b/packages/block-editor/src/components/block-rename/modal.js index 1c038f13f69b4e..3f99e71b7b699e 100644 --- a/packages/block-editor/src/components/block-rename/modal.js +++ b/packages/block-editor/src/components/block-rename/modal.js @@ -21,7 +21,7 @@ import { useBlockDisplayInformation } from '..'; import isEmptyString from './is-empty-string'; export default function BlockRenameModal( { clientId, onClose } ) { - const [ editedBlockName, setEditedBlockName ] = useState( '' ); + const [ editedBlockName, setEditedBlockName ] = useState(); const blockInformation = useBlockDisplayInformation( clientId ); const { metadata } = useSelect( @@ -47,7 +47,8 @@ export default function BlockRenameModal( { clientId, onClose } ) { ( binding ) => binding.source === 'core/pattern-overrides' ); - const nameHasChanged = editedBlockName !== blockName; + const nameHasChanged = + editedBlockName !== undefined && editedBlockName !== blockName; const nameIsOriginal = editedBlockName === originalBlockName; const nameIsEmpty = isEmptyString( editedBlockName ); @@ -107,7 +108,7 @@ export default function BlockRenameModal( { clientId, onClose } ) { { await pageUtils.pressKeys( 'primary+a' ); await page.keyboard.press( 'Delete' ); - // Check placeholder for input is the original block name. + // Check that input is empty and placeholder is the original block name. await expect( nameInput ).toHaveAttribute( 'placeholder', 'Group' ); + await expect( nameInput ).toHaveValue( '' ); // It should be possible to submit empty. await expect( saveButton ).toBeEnabled();