Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Part: Move "title" to block toolbar #24450

Merged
merged 2 commits into from
Aug 11, 2020
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
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