Skip to content

Commit

Permalink
Template Part: Move "title" to block toolbar (#24450)
Browse files Browse the repository at this point in the history
* Move block title to block toolbar

* Update createTemplatePart input selector
  • Loading branch information
noahtallen committed Aug 11, 2020
1 parent 7b29541 commit 8e7844b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
17 changes: 5 additions & 12 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { useRef, useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { BlockControls } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -16,7 +17,6 @@ export default function TemplatePartEdit( {
attributes: { postId: _postId, slug, theme },
setAttributes,
clientId,
isSelected,
} ) {
const initialPostId = useRef( _postId );
const initialSlug = useRef( slug );
Expand All @@ -29,18 +29,11 @@ export default function TemplatePartEdit( {
// but wait until the third inner blocks change,
// because the first 2 are just the template part
// content loading.
const { innerBlocks, hasSelectedInnerBlock } = useSelect(
const { innerBlocks } = useSelect(
( select ) => {
const {
getBlocks,
hasSelectedInnerBlock: getHasSelectedInnerBlock,
} = select( 'core/block-editor' );
const { getBlocks } = select( 'core/block-editor' );
return {
innerBlocks: getBlocks( clientId ),
hasSelectedInnerBlock: getHasSelectedInnerBlock(
clientId,
true
),
};
},
[ clientId ]
Expand Down Expand Up @@ -68,12 +61,12 @@ export default function TemplatePartEdit( {
// Part of a template file, post ID already resolved.
return (
<>
{ ( isSelected || hasSelectedInnerBlock ) && (
<BlockControls>
<TemplatePartNamePanel
postId={ postId }
setAttributes={ setAttributes }
/>
) }
</BlockControls>
<TemplatePartInnerBlocks
postId={ postId }
hasInnerBlocks={ innerBlocks.length > 0 }
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/template-part/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@

.wp-block-template-part__name-panel {
background-color: $white;
border-radius: $radius-block-ui;
box-shadow: 0 0 0 $border-width $gray-900;
outline: 1px solid transparent;
padding: ($grid-unit-10 - $border-width - $border-width) $grid-unit-15;
padding: $grid-unit-10 $grid-unit-15;

.components-base-control__field {
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const createTemplatePart = async (
? '.wp-block[data-type="core/template-part"] .wp-block[data-type="core/template-part"] .block-editor-inner-blocks'
: '.wp-block[data-type="core/template-part"] .block-editor-inner-blocks'
);
await page.keyboard.press( 'Tab' );
await page.focus( '.wp-block-template-part__name-panel input' );
await page.keyboard.type( templatePartName );
};

Expand Down

0 comments on commit 8e7844b

Please sign in to comment.