Skip to content

Cover: declare the inner blocks template in block type settings#80120

Open
ellatrix wants to merge 1 commit into
add/block-type-templatesfrom
add/cover-block-type-template
Open

Cover: declare the inner blocks template in block type settings#80120
ellatrix wants to merge 1 commit into
add/block-type-templatesfrom
add/cover-block-type-template

Conversation

@ellatrix

Copy link
Copy Markdown
Member

What?

Declares the Cover block's inner blocks template in its block type settings, like every other block in #80027, and teaches the placeholder to show whenever the block has no background and no content.

Alternative to #80028, following #80028 (comment). Built on top of #80027.

Why?

On trunk the placeholder worked by accident: the placeholder branch returns early without rendering the inner blocks container, so the template only applied once a background was chosen. With templates applied at insertion (#80027), the scaffolded paragraph would suppress the placeholder forever. Instead of scaffolding imperatively in every placeholder-exit handler (#80028), the placeholder condition absorbs the logic: a single empty scaffold paragraph does not count as content.

How?

  1. Static template in settings. The fontSize: 'large' attribute is now unconditional; the theme font size check cannot be expressed statically.
  2. hasInnerBlocks becomes hasInnerContent in the placeholder condition: more than one inner block, or one block that is not an empty paragraph.
  3. The placeholder-exit handlers select the scaffolded paragraph so typing the title works immediately, preserving the trunk behavior of templateInsertUpdatesSelection. Forgetting a future handler only costs focus, never content.

Behavior changes:

  • An inserted then abandoned Cover saves with an empty inner paragraph, consistent with List, Quote and Buttons.
  • Removing the last background from a contentless Cover returns it to the placeholder (previously the invisible empty paragraph prevented this).

The image transform e2e test raced the upload: transforming before completion silently loses the image on trunk too, but the paragraph masked the placeholder so the test passed. It now waits for the final URL.

Testing Instructions

  1. Insert a Cover block; the media/color placeholder appears as before.
  2. Pick an overlay color or upload media; the title paragraph appears focused, type into it.
  3. Remove the overlay color again without typing; the placeholder returns.
  4. Transform a group with content but no background into a Cover; the content shows, no placeholder.

Testing Instructions for Keyboard

Insert a Cover, Tab to a color swatch in the placeholder, press Enter, and type the title.

Use of AI Tools

🤖 Generated with Claude Code

Declare the cover template in block type settings so it is scaffolded
at insertion like other blocks. The placeholder now shows whenever
there is no background and the inner blocks are at most the untouched
scaffold paragraph, and it returns when the background is removed from
a contentless cover. The placeholder-exit handlers select the
scaffolded paragraph so typing the title works right away.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Jul 10, 2026
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Size Change: +84 B (0%)

Total Size: 7.67 MB

📦 View Changed
Filename Size Change
build/scripts/block-library/index.min.js 333 kB +84 B (+0.03%)

compressed-size-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant