Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Try: add padding CSS rules instead of in the templates #291

Merged
merged 26 commits into from
Dec 14, 2021
Merged

Conversation

MaggieCabrera
Copy link
Collaborator

@MaggieCabrera MaggieCabrera commented Dec 10, 2021

This PR provides an interim solution to the padding problem that eventually will be solved in Gutenberg (WordPress/gutenberg#35607). This leverages a custom outer spacing variable that will be absorbed with the future variable implemented for the editor plus a series of CSS rules that will eventually disappear as the editor provides a global solution instead.

To test this check that the full width blocks all over the theme go all the way to the borders of the viewport while the rest of the site maintains a padding on mobile to stop content from extending. The editor should show the same as the frontend does.

Alternative to #289

Addresses #234

@kjellr
Copy link
Collaborator

kjellr commented Dec 10, 2021

In general, this is looking promising. I know this is in progress, but leaving a few notes here:

Many of our full-width patterns provide their own padding to ensure their inner content doesn't bump up against the edges. But currently, they are bumping up against the edges even so:

Screen Shot 2021-12-10 at 9 50 34 AM

Also, I think we need to be more specific about these rules. Here's an example of the post content placed inside of a column. As you can see, the left/right negative margin is being applied when it shouldn't be:

Screen Shot 2021-12-10 at 10 01 24 AM

@MaggieCabrera
Copy link
Collaborator Author

Thanks @kjellr! Generally, I've found in most cases the only problem is that we are applying full width where we really don't need to do so. Such is the case of the first pattern that you mention (I've just fixed that). I'll have a look at the other case, but I think we could use as many eyes on this as possible so we cover all the possible cases.

I'll clean up this PR so that it's ready for review.

@kjellr
Copy link
Collaborator

kjellr commented Dec 10, 2021

we are applying full width where we really don't need to do so

Could be. But we also need to ensure there are fallbacks in place because we can't control what weird stuff other people do. This is exactly why the layout rules tend to get so complicated. 😅

@MaggieCabrera
Copy link
Collaborator Author

@kjellr how did you manage to get that full width item inside the two column layout? it doesn't let me:

Screenshot 2021-12-10 at 16 51 36

@kjellr
Copy link
Collaborator

kjellr commented Dec 10, 2021

I set the Query block there to inherit the default layout. Generally that's a bad idea in this setup, but I was trying to break it and find holes. 😄 When I did this, it looked fine in the editor, but broke in the front end.

@kjellr
Copy link
Collaborator

kjellr commented Dec 10, 2021

I pushed a few small fixes to templates. In general, this is looking pretty good — I've been running through a bunch of content and haven't found any major errors. We should try some tests where there are alignfull items inside of columns though, cause I expect there could be issues.

I'm going to mark it as ready for a true review.

@kjellr kjellr marked this pull request as ready for review December 10, 2021 19:57
style.css Show resolved Hide resolved
style.css Outdated Show resolved Hide resolved
@MaggieCabrera MaggieCabrera self-assigned this Dec 13, 2021
@MaggieCabrera
Copy link
Collaborator Author

I introduced the exception for columns, I think this is the intended behavior, right?

Screenshot 2021-12-13 at 14 09 27

This is the markup I sued on the example above:


<!-- wp:columns {"align":"full"} -->
<div class="wp-block-columns alignfull"><!-- wp:column {"backgroundColor":"primary","textColor":"background"} -->
<div class="wp-block-column has-background-color has-primary-background-color has-text-color has-background"><!-- wp:paragraph -->
<p>1 column full aligned</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"backgroundColor":"secondary"} -->
<div class="wp-block-column has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>column 1</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"backgroundColor":"secondary"} -->
<div class="wp-block-column has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>Column 2</p>
<!-- /wp:paragraph -->

<!-- wp:group {"layout":{"inherit":true}} -->
<div class="wp-block-group"><!-- wp:group {"align":"full","backgroundColor":"primary","textColor":"background"} -->
<div class="wp-block-group alignfull has-background-color has-primary-background-color has-text-color has-background"><!-- wp:paragraph -->
<p>group full aligned</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group --></div>
<!-- /wp:group -->

<!-- wp:paragraph -->
<p>---</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->

<!-- wp:columns {"align":"full"} -->
<div class="wp-block-columns alignfull"><!-- wp:column {"backgroundColor":"secondary"} -->
<div class="wp-block-column has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>column 1</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"backgroundColor":"secondary"} -->
<div class="wp-block-column has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>Column 2</p>
<!-- /wp:paragraph -->

<!-- wp:group {"layout":{"inherit":true}} -->
<div class="wp-block-group"><!-- wp:group {"align":"full","backgroundColor":"primary","textColor":"background"} -->
<div class="wp-block-group alignfull has-background-color has-primary-background-color has-text-color has-background"><!-- wp:paragraph -->
<p>group full aligned</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group --></div>
<!-- /wp:group -->

<!-- wp:paragraph -->
<p>---</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->

@kjellr
Copy link
Collaborator

kjellr commented Dec 13, 2021

That looks about right to me.


A couple general questions I thought of this morning:

  • Is there anything to this approach/CSS that could be ported upstream to Gutenberg instead? At a glance, this code isn't very specific to this theme. If we merge this, I expect other themes will copy/paste this code, and if possible it might be better to just place it in Gutenberg somewhere so it can be revised and replaced in the future more easily.
  • We should test alongside the current implementation of sit padding, and make sure it doesn't break horribly.

@MaggieCabrera
Copy link
Collaborator Author

Ugh, I just noticed the 1 column example above is not correct, I'll have another pass at that.

@MaggieCabrera
Copy link
Collaborator Author

* Is there anything to this approach/CSS that could be ported upstream to Gutenberg instead? At a glance, this code isn't very specific to this theme. If we merge this, I expect other themes will copy/paste this code, and if possible it might be better to just place it in Gutenberg somewhere so it can be revised and replaced in the future more easily.

I don't think so, no. It needs more testing, to see if we've missed something somewhere we don't want the negative margins besides the columns case. The idea for GB was to be able to handle the padding variable with a built-in variable so themes could opt-in into this, else you will break themes that implement this differently or don't want this behavior at all.

* We should test alongside the current implementation of sit padding, and make sure it doesn't break horribly.

I don't know what you mean exactly, what implementation?

@MaggieCabrera
Copy link
Collaborator Author

@kjellr for the case of a full width block inside a one column that is not full width, the current behavior doesn't make the inner block go all the way to the borders because of the fixed width of the parent so I don't think we need a rule for those. I'm removing that exception

@MaggieCabrera
Copy link
Collaborator Author

The group thing, on trunk:

Screenshot 2021-12-13 at 14 30 54

On this PR:

Screenshot 2021-12-13 at 14 30 37

@MaggieCabrera
Copy link
Collaborator Author

This is ready for another look, I don't have any broken cases in my arsenal, please try and break this

@kjellr
Copy link
Collaborator

kjellr commented Dec 13, 2021

Are you seeing extra padding in the site editor?

Front End Site Editor
Screen Shot 2021-12-13 at 9 33 20 AM Screen Shot 2021-12-13 at 9 33 30 AM

@MaggieCabrera
Copy link
Collaborator Author

Are you seeing extra padding in the site editor?

What I'm seeing is that the alignfull on that block is only working because the block has the class (in the front), but that block doesn't have alignment options showing up on the toolbar, so the editor doesn't add the data attribute that we are targeting in the editor. So I think that's a case of refactoring the template part, do you see it somewhere else?

@kjellr
Copy link
Collaborator

kjellr commented Dec 13, 2021

Ok I see, we have to add an additional group wrapper there. 😅

Pushed 6210863 to take care of that.

Copy link
Collaborator

@jffng jffng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still forming opinions on whether I think it's a generally a good idea to introduce these global rules to the theme, but right now I am noticing some regressions:

The home page header is getting some Gutenberg padding rules applying to it now, note the .wp-group-block:where rule:

Screen Shot 2021-12-13 at 11 36 56 AM

The default footer lacks padding on smaller viewports:

Screen Shot 2021-12-13 at 11 29 28 AM

The default header appears at default instead of wide width:

Screen Shot 2021-12-13 at 11 39 00 AM

@jffng jffng force-pushed the try-padding-rules branch from 48ff11a to 395e093 Compare December 13, 2021 19:35
@jffng
Copy link
Collaborator

jffng commented Dec 13, 2021

I made three changes to try and resolve the issues reported above:

  • Removed a wrapper in the default footer pattern to get the global padding to be respected 5f6c14a
  • Removed a wrapper in the default header and also removed inherit: true on the header template part inside the templates. I'm not sure why / how this was got in there to begin with, it also was inconsistent because the 404 and archive templates did not have it set on the header template part: 705a6da
  • Added an extra selector to get the default padding of group block's that have a background to match the custom variable we have set. I'm not sure about this one. 395e093

@kjellr
Copy link
Collaborator

kjellr commented Dec 14, 2021

I found a use case that doesn't work right: A full-width Group block with a background color. The full-width child here is supposed to go to the edge, but it doesn't. I'll try and push a fix.

Screen Shot 2021-12-14 at 9 12 04 AM

@kjellr
Copy link
Collaborator

kjellr commented Dec 14, 2021

I fixed that, and also synced things up so that wide/full blocks inside of a full-width group block are aligned with wide/full blocks outside of one:

Before After
Screen Shot 2021-12-14 at 9 33 10 AM Screen Shot 2021-12-14 at 9 32 52 AM

At the moment, the only issue I'm seeing is that full-width items inside of non-full width parents incorrectly inherit the negative margins and padding:

Screen Shot 2021-12-14 at 9 49 41 AM

As far as I can tell, we can't really clear that without breaking all kinds of other stuff. So I think we just have to let it be.

*/

.wp-site-blocks,
.is-root-container,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the site editor, check out the archive or home template. This rule is applying an unwanted padding in the query:

Screen Shot 2021-12-14 at 10 29 03 AM

Copy link
Collaborator

@kjellr kjellr Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I believe is-root-container is used in multiple places. We should switch to something else or be more specific.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a potential fix in c4a80d3. It uses more specific selectors, but also required specifying both the root container for the site editor and for the post/page editor.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm actually, now that I'm looking closer I'm not sure that'll do it. 😕

Copy link
Collaborator

@kjellr kjellr Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😕 It doesn't. Reverting that commit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, after some further digging, I can see that this is basically a re-creation of this issue: WordPress/gutenberg#33248.

Basically, the Query block renders using some nested DOM elements, and that causes this duplicate selector where it shouldn't be. In the post/page editor, Gutenberg itself provides some is-root-container styles that cause the same behavior you're seeing here.

Since WordPress/gutenberg#33248 is listed as a must-have for 5.9, and is currently in progress I think we're ok to push through with this bug present for now.

@jasmussen
Copy link

TT2 is my favorite theme in years, in part because it's able to do so much with just blocks alone. It's clearly shown the need to solve this at the block editor level. It's also shown how tricky it is to get that right, and so I think it's good to buy some time with this solution. Hopefully the usage and rules can help us zero in on the right heuristic to implement.

As for the specific rules, it's definitely a little hard to parse if you haven't built a ton of the CSS. At a high level, the code looks good for me, and in testing, things look right to me:
Screenshot 2021-12-14 at 16 34 26

Screenshot 2021-12-14 at 16 34 32

I also tried some patterns out, and it all appears to work well. The GIF was too big, so it's here.

I would love for the clamp rules to be absorbed by the system as well — the inability to see or intuitively edit the some of the paddings feels a little janky. But that's a separate issue, and probably not one that needs solving in the near future.

Ultimately, if we go with this approach, which as noted I think is good to do for the time being, it seems okay to merge soon and then keep an eye out for anything that might need following up on.

@kjellr
Copy link
Collaborator

kjellr commented Dec 14, 2021

Thanks for the testing! I also tested with the current Site Padding implementation, and it works fine... it just adds padding to the outside of all this:

Example Example
Screen Shot 2021-12-14 at 11 01 48 AM Screen Shot 2021-12-14 at 11 02 16 AM

I'd like to reiterate what I said over in this other thread:

This is not our ideal solution, but it's the least complicated one for today. It's a handful of CSS rules, and it generally works without the user changing their behavior or opting into anything. The end goal is to get a solution merged into Gutenberg, but I think this is a first step towards that and is worth testing during the upcoming Beta cycle.

Copy link
Collaborator

@jffng jffng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's bring this since we've noted it as being a temporary solution, and have some consensus that this the best tradeoff to achieve the intended design result with the current tools available.

Kudos @MaggieCabrera for the PR and @jasmussen for all the testing and feedback!

@MaggieCabrera
Copy link
Collaborator Author

Thank you all for testing this, it's a complicated problem!

@richtabor
Copy link
Member

Hey all 👋 — love this. I noticed that there's a discrepancy between the use of the spacing.outer var and the padding set by various patterns. If you modify the outer value in theme.json, you'll see that the patterns don't adjust as well (as many set their own padding left/right values.

I took a stab at it in #310 — which lets the patterns adapt to the outer value. Let me know what you think :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants