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

Post Template Block: Move inner blocks container to separate component #35945

Merged
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
9 changes: 7 additions & 2 deletions packages/block-library/src/post-template/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const TEMPLATE = [
[ 'core/post-date' ],
[ 'core/post-excerpt' ],
];

function PostTemplateInnerBlocks() {
const innerBlocksProps = useInnerBlocksProps( {}, { template: TEMPLATE } );
return <li { ...innerBlocksProps } />;
}

export default function PostTemplateEdit( {
clientId,
context: {
Expand Down Expand Up @@ -125,7 +131,6 @@ export default function PostTemplateEdit( {
[ `columns-${ columns }` ]: hasLayoutFlex,
} ),
} );
const innerBlocksProps = useInnerBlocksProps( {}, { template: TEMPLATE } );

if ( ! posts ) {
return (
Expand All @@ -149,7 +154,7 @@ export default function PostTemplateEdit( {
>
{ blockContext ===
( activeBlockContext || blockContexts[ 0 ] ) ? (
<li { ...innerBlocksProps } />
<PostTemplateInnerBlocks />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes a lot of sense because in practice this creates a list of Post Template inner blocks so all block props should be computed in that context that is set by the BlockContextProvider.

@michalczaplinski, we will need to apply the same changes as in the final version of this PR to the Comment Template block.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #36174 to align the Comment Template block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoop, sorry for getting to this late @gziolo and thanks for taking care of this! 😊

) : (
<li>
<BlockPreview
Expand Down