-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block spacing not applied when enabling blockGap
via blocks.registerBlockType
JS filter hook
#53155
Comments
@ryanwelcher @justintadlock could you all chime in here? |
I can confirm this doesn't work (I also tested with a couple of other blocks). But I'm not familiar enough with how this works under the hood to say why. I'm pretty sure just adding @andrewserong - Pinging you in case it is related to layout support. |
Thanks for the ping! It looks like there are a couple of questions in this issue: Adding blockGap support to to the Details blockThis isn't possible without opting the Details block in to use the layout block support. If this is something desired more generally, it might be worth opening a separate issue as a suggested feature ( @richtabor do you know if there was a reason we didn't use the layout block support for the Details block from the outset? Just thought I'd double check in case there'll be some stumbling blocks to implementing it in follow-ups. blockGap depends on layout support
Yes, So, where does that leave us for this particular issue? In terms of being able to enable For themes wishing to adjust spacing for the Details block, in the shorter-term, they might need to provide some CSS styles if the current state of block supports doesn't meet a theme's needs. |
Update: I've opened a separate issue in #53252 for adding layout and blockGap support to the Details block. We can use that issue for any discussion about potential blocks to opting-in to those supports. |
Another quick update: I've opened a PR in #53254 to update the dev docs slightly to clarify that |
That's pitty that 1.
|
Thanks for your further thoughts!
Unfortunately that block likely isn't a good candidate for layout block support as it's not a wrapper for other blocks. The layout support controls spacing for containers of child blocks.
It'd be great to add axial block spacing support to the group block, but it would also need to be aware of layout types. There's an earlier issue for it in #47084 that would be good to implement.
Block gap was originally implemented in a way that's kind of similar to that, but unfortunately due to subtle issues of inheritance when nesting blocks within other blocks (as it'd reset the value for all children), the CSS variable-based approach had to be largely deprecated. The CSS variable is still output if themes wish to use or hook into it, but so far, core blocks have largely moved away from using the variable and instead receive style values directly via the layout support.
I definitely see the value in doing that, and I believe there are other issues flagging the need for spacing controls for blocks that aren't suitable candidates for layout. For now at least, I don't think it'd be a good idea to attempt to reset the blockGap CSS variable as it's difficult to work with in a predictable way. This use case does highlight the gap (if you'll excuse the pun!) between block spacing, that is spacing between blocks, and spacing/gap in a general sense between HTML elements. The latter doesn't currently exist as a block support, but could be very useful. I imagine if it were to be developed, it might want to be a separate block support to Sorry I don't have more conclusive answers! I very much see the problem of wanting to allow more spacing controls in these particular cases. I'd be curious to hear if anyone else has other ideas about how they could be implemented, or be factored into spacing controls in general. Thanks again for the discussion here, it's very valuable to have! |
Indeed, inheritance is the issue here. That's why I'm setting the
Good point! Yes, I'm using This is tricky to have separate control for HTML elements gap, indeed. But maybe the control and naming could be the same and just generated styles would differ depending on whether a block has |
That's a very compelling idea! It'd be worth hacking around with to see how it might work 🤔 |
Thanks for diving right into this and addressing it @andrewserong! On using |
To keep it as simple as other text/writing blocks (paragraph, heading, quotes, lists, etc). We don't need layout tools for the details block—but one could add a group within it, then assign spacing to that, if you wanted to extend the visual. |
Fortunately we can add layout support in order to enable block spacing without exposing any layout tools! I've tried it for the Details block in #53282. Let me know what you think! |
@tellthemachines Thanks for the code. Does this work for you on website front-end too? I've ported the code to my theme (modified Details block I'm on WC6.3-RC3 and Gutenberg 16.3.0. |
OK, after modifying Details block |
BTW, the point 3 from my previous comment is not resolved yet. |
Would it be worth opening a separate issue for this one? I think it might potentially become fairly complex in terms of designing it as a reliable API. For example, outputting the CSS variable There's probably a few more intricacies to figure out there before attempting to build it out as a feature, but perhaps the general concept would be: what sort of block support (if any) should be available for gap/spacing for blocks that don't use layout? |
Description
When I enable
supports.spacing.blockGap
for a block viablocks.registerBlockType
JavaScript filter in my theme, the "Block spacing" control is displayed correctly in the block settings sidebar, but tweaking the control does not apply the styles on the block.Is this a bug or should I enable something more in my theme code?
(Currently I'm using
WP_HTML_Tag_Processor
to add inline style viarender_block
PHP hook. But it feels hacky and unnecessary.)Step-by-step reproduction instructions
functions.php
file with this content:Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: