Skip to content
Prev Previous commit
Next Next commit
Reinstate Inspector Controls renaming
  • Loading branch information
getdave committed Oct 25, 2023
commit ddd878bd82540dd415403b73fb321efeda55a34a
52 changes: 52 additions & 0 deletions packages/block-editor/src/hooks/block-rename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* WordPress dependencies
*/
import { createHigherOrderComponent } from '@wordpress/compose';
import { addFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import { hasBlockSupport } from '@wordpress/blocks';
import { TextControl } from '@wordpress/components';

/**
* Internal dependencies
*/
import { InspectorControls } from '../components';

export const withBlockRenameControl = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const { name, attributes, setAttributes, isSelected } = props;

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

return (
<>
{ isSelected && supportsBlockNaming && (
<InspectorControls group="advanced">
<TextControl
__nextHasNoMarginBottom
label={ __( 'Block name' ) }
value={ attributes?.metadata?.name || '' }
onChange={ ( newName ) => {
setAttributes( {
metadata: {
...attributes?.metadata,
name: newName,
},
} );
} }
/>
</InspectorControls>
) }

<BlockEdit key="edit" { ...props } />
</>
);
},
'withToolbarControls'
);

addFilter(
'editor.BlockEdit',
'core/block-rename-ui/with-block-rename-control',
withBlockRenameControl
);
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import './metadata';
import './metadata-name';
import './custom-fields';
import './block-hooks';
import './block-rename';

export { useCustomSides } from './dimensions';
export { useLayoutClasses, useLayoutStyles } from './layout';
Expand Down