-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Undefined spacing presets in theme.json cause zero spacing when are in pattern markup #60129
Comments
@WordPress/block-themers for thoughts from you all! |
I like the idea but I think this is a bit more tricky than it looks. The spacing preset slugs can actually be anything. For example, you could specify |
That's fine. This idea is to include the CSS variables for the 20-80 presets in a CSS hierarchy level that theme presets will overwrite. In other words, Patterns using 20-80 presets will work on any theme because that's the default WordPress spacing scale, while patterns using any other custom presets will only work in a theme that defines those presets in its theme.json. |
There are other presets like the default colors that are printed even if a theme opts-out of them.
Could the editor add a fallback value to the CSS var()? |
This requires to check the existence of the spacing presets, before adding fallback.
IMO, this is the better approach and solves variables with any naming pattern, by taking native CSS variable fallback approach. gap: var(--wp--preset--spacing--50, --wp--style--block-gap)
This is still an issue. May be block gap variable could also add a default fallback value? --wp--style--block-gap: var(value-from-theme-json, editor-defined-default-fallback-value) |
Just to share another example where the issue came up. New Block hooks API allows injecting blocks, or groups of blocks in templates. In Jetpack plugin we're adding a group of blocks (group, paragraphs, and a subscription form) at the end of each post; so essentially a pattern. We had to use pixel values for spacing to make the pattern work reliably across themes. We had issues with some chosen spacing variables missing, as well too much size variety between themes that the pattern didn't look good anymore in some themes. |
I believe this issue will improve thanks to Theme.json version 3 because The issue will remain for themes that set cc: @scruffian @ajlende related to #61842 |
Related to #39371
What problem does this address?
Developers have a lot of flexibility when creating a spacing scale for a theme. This is great.
For instance, TT4 uses a 10-60 scale, and TT3 uses a 30-80 scale.
However, when a spacing preset is in a pattern markup (maybe copied from a public library or another theme) but is not defined in the theme.json of the active theme, the result is zero spacing.
The following is an example of the preset
--wp--preset--spacing--20
being used in a pattern while it is not defined:The editor only creates CSS variables for the presets defined in theme.json, resulting in zero spacing.
What is your proposed solution?
We could avoid this issue by defaulting to the variable
--wp--style--block-gap
when a spacing preset is not defined.Here is a possible implementation for the default 20-80 spacing scale:
For reference: What is blockGap and how can I use it?
cc: @richtabor @annezazu
The text was updated successfully, but these errors were encountered: