Repository navigation
Theme JSON: Add a spacing.blockBackgroundPadding style property - #82057
aaronrobertshaw wants to merge 5 commits into
Conversation
Maps to the `--wp--style--block-background-padding` custom property the block stylesheets already read, so themes can change or remove the default padding without custom CSS.
Keeps the editor in step with the styles the backend generates. The property has no `support` key, so it stays out of the Global Styles UI.
…property Asserts the same output on both sides, so the editor and the front end cannot drift.
|
Size Change: +15 B (0%) Total Size: 7.91 MB 📦 View Changed
|
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Flaky tests detected in c279c2f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/32951064987 persists table layout across all tabs with unified view persistence in
|
I wonder if this'll be unexpected because that's not how other spacing values work (or any other block supports for that matter). I understand why it works like that given we're using a custom property, and conceivably theme devs can specify values for each block type if they want, so it's probably not much of an issue. |
Yeah, it's a good question. One I was concerned about initially as well. The more I thought on it though, the more it didn't seem like a big deal. Most issues and history I could find was about theme authors and users just wanting to avoid the background color dependent padding altogether. Even less to only opt out of it for a single block type. I'm certainly open to other ideas or opinions though. |
tellthemachines
left a comment
There was a problem hiding this comment.
This is working well but it feels overkill as an API, mostly because we're adding a property that can be set on any block, but will only work on a very few of them. For Group and Template Part it'll only have an effect on themes that include those stylesheets, which classic themes have to explicitly add support for and are not recommended for use on block themes at all.
It might be better to leave this for now, see how the custom property added in #82024 gets used, and then revisit if needed.
|
Appreciate the thoughtful feedback. I don't hold a strong opinion either way. The initial PR, #82024, seemed to get a positive response to adding the theme.json setting to avoid theme authors requiring custom css values. I'd be ok, with closing this PR for now and seeing how only the custom property in #82024 goes like you said. @ramonjd and @andrewserong, what do you think? |
This is a weakly held opinion, but I'd go that way, too. Conceptually I like the idea of this PR but it sort of raises a question of should you also be able to set So, my vote would be to land #82024 for now, and come back to this if/when there's a desire from theme devs to have more control over it. |
That's it in a nutshell, really. I'll close this one then get the base PR merged. We can resurrect this if needed down the line. |
Follow up to #82024. See #36586.
What?
#82024 moved the padding that blocks get when they have a background color to a
--wp--style--block-background-paddingcustom property.This PR adds a
theme.jsonstyle that sets the same property, so themes can change or remove that padding without custom CSS.Why?
Setting the custom property today means hand writing CSS in
styles.css. A first class property is easier to find, validates against the schema, and can be set for a single block type.How?
styles.spacing.blockBackgroundPaddingmaps to the custom property the block stylesheets already read, following the same pattern as the existing root padding properties. Both the backend and the editor output it, and a test on each side asserts the same output so the two can't drift apart.The property stays theme facing for now, so it does not appear anywhere in the Global Styles interface.
How to use
{ "version": 3, "styles": { "spacing": { "blockBackgroundPadding": "0" } } }Any value works, not only
0, including a preset such asvar:preset|spacing|50. For a single block type, set it understyles.blocks, for examplestyles.blocks.core/group.spacing.blockBackgroundPadding, and blocks nested inside inherit it unless they set their own.Testing Instructions
Group and Template Part only load these styles when a theme calls
add_theme_support( 'wp-block-styles' ), so test with Twenty Twenty-One as well as Twenty Twenty-Five.theme.json. Confirm the padding is removed from all seven, in the editor and on the front end.1rem 2remand confirm all seven pick it up.styles.blocks.core/group. Confirm Group changes, the other six keep the default, and a Paragraph with a background color nested inside the Group inherits the Group's value.core/paragraphvalue as well and confirm it wins over the one inherited from the Group.Alternatives
Instead of allowing custom padding values this could be a simple boolean that enables or disables the default padding. At this stage, we might as well let theme authors have more control rather than less.