Cover block: check fontSizes settings before setting fontSize in innerBlocks#34993
Conversation
|
Size Change: +45 B (0%) Total Size: 1.06 MB
ℹ️ View Unchanged
|
… the settings. If it is, we allow the cover block's innerBlocksTemplate – a paragraph block - a default fontSize of 'large'. If the theme has disabled typography.fontSizes support, we omit fontSize. This ensures that the block does not display any unintended side effects of block supports such as auto-generated classnames.
c274bef to
cd47a81
Compare
andrewserong
left a comment
There was a problem hiding this comment.
Thanks for putting this together @ramonjd! This is testing well for me:
✅ No change in behaviour on non-theme.json themes (e.g. Twenty Twenty One)
✅ If the fontSizes array in theme.json is empty, the behaviour described here works
✅ If the fontSizes array is removed, it falls back to Gutenberg's theme.json setting so the large size is used
✅ Only affects newly added Cover blocks, existing ones are unaffected
| Editor | Front end |
|---|---|
![]() |
![]() |
I suppose we could go a step further and explicitly check for the presence of the large font size, but to keep the code simple, I quite like the approach of skipping the attribute if there are no custom font sizes at all.
LGTM!
|
Appreciate the review @andrewserong 🙇
Thanks for the suggestion. I can see that being an advantage if the large font size isn't available in the Maybe for another PR! |


Description
Fixes #34120
And so the days of the Cover block dictating font size attributes to its innerBlocks irrespective of the contents of theme.json and the wishes of theme developers ... takes breath ... are over.
In this proposed code change, we check the editor settings for
fontSizesblock support before setting afontSizeattribute on the Cover block's innards (a paragraph).Why? Because, as described in #34120, the existence of the
fontSizeattribute, even where the theme has deactivated fontSize support, tells the fontSize hook to add thehas-large-font-sizeclass to the block container.Props to @andrewserong and @philbuchanan
How has this been tested?
Manually, using a browser with 👀 We don't set innerBlock attributes for native mobile.
Best tested with smooth blues or jazz.
For testing, I'm using TT1 Blocks theme and editing the
theme.jsondirectly in WordPress, e.g.,/wp-admin/theme-editor.php?file=theme.json&theme=tt1-blocksExisting behavior
Before applying this patch, check existing behavior.
Edit
settings.typographyin yourtheme.json:"fontSizes": []In the editor, insert a cover block. Check that font size controls are disabled in the block inspector sidebar, and that the paragraph inner block has the class of
has-large-font-size.With the changes in this PR applied
With this patch applied, refresh the editor and insert a new cover block.
Check that font size controls are disabled in the block inspector sidebar, and that the paragraph inner block does not have the class of
has-large-font-size.Publish that post and check the frontend! The class should be absent on the paragraph block as well.
Known knowns
Here are some things I discovered along the way. None have any negative impact on this PR I think.
We can override via specific block settings in
theme.jsonas well. For example, deactivatingfontSizesinsettings.typography, but activating them insettings.blocks['core/cover'].typography.The values themselves won't have any effect since the Cover Block doesn't yet support fontSizes.
Edge case: a mismatch might also occur when we turn off fontSizes for the paragraph block in
settings.blocks['core/paragraph'].typography, but it's still activated insettings.typography.The controls do not appear, but the Cover block will read the global settings.
Oh yes, and WordPress core fontSizes will ultimately kick in if none are enabled elsewhere. 😄
Screenshots
With
fontSizesenabled:Without

fontSizesenabled:Types of changes
This is a compatibility change, ensure the inner blocks of the Cover block respect the theme.json settings.
Checklist:
*.native.jsfiles for terms that need renaming or removal).