-
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
Columns - fix margins, keep 2-col breakpoint #12816
Conversation
Columns were broken b/w the small and medium breakpoints, and when there are an odd number of columns. This fixes those issues. orig: https://codepen.io/drdogbot7/pen/NEOQPQ Fix: https://codepen.io/drdogbot7/pen/GwYVNz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is such a nice pull request. Meaning to address a specific problem, well documented, lots of thoughts put into it. Thanks so much. Once we get this in you should be sure to add yourself to the contributors.md doc if you'd like and if you're not already there.
How does this one relate to #12199? Should it be merged along with the other, or is one of them sufficient?
I took this for a spin and especially on the frontend this seems to work well:
However there seems to be a small discrepancy in the editor view. Here's 5.0.1:
Here's this branch:
It's the same in 2019:
I'm not sure quite what it is, the CSS seems to be on point. Can you reproduce? I saw this with 2 columns.
I have some comments about the code comments as well, but I will leave those separately. But overall, this is a great PR and with a few small tweaks I think we should get it in!
@@ -89,13 +89,17 @@ | |||
|
|||
// Beyond mobile, allow 2 columns. | |||
@include break-small() { | |||
flex-basis: 50%; | |||
// Size should be half the available width, minus the margins added below |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tofumatt has taught me to be consistent (going forward, I was a bad actor for a long time) with our code comment system. Which is capital first letter, end with a period.
In this case we're missing a period at the end.
@@ -89,13 +89,17 @@ | |||
|
|||
// Beyond mobile, allow 2 columns. | |||
@include break-small() { | |||
flex-basis: 50%; | |||
// Size should be half the available width, minus the margins added below | |||
// In the editor, we also need to account for additional block padding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I know this is really nitpicky, but we're basically a margin fix and some code comments polish from shipping this.
&:nth-child(odd) { | ||
margin-right: initial; | ||
} | ||
// Add left margin to all but first column |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks.
&:not(:first-child) { | ||
margin-left: $grid-size-large * 2; | ||
} | ||
|
||
// add right margin to all but last column |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capital first letter and period.
@@ -18,7 +18,9 @@ | |||
|
|||
// Beyond mobile, allow 2 columns. | |||
@include break-small() { | |||
flex-basis: 50%; | |||
|
|||
// Size should be half the available width, minus the margins added below |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a period. Hey, actually I think I'll stop these reviews and just push a fix. Hold on.
flex-basis: 50%; | ||
// Size should be half the available width, minus the margins added below. | ||
// In the editor, we also need to account for additional block padding. | ||
flex-basis: calc(50% - #{$grid-size-large * 2} - #{$block-padding * 2}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a stab at fixing the margin issue I noted. When I reverted this back to flex-basis: 50%;
(editor only), I got things working:
Keep in mind that the editor uses a lot of negative margins left and right so as to make available a selectable/hoverable space left and right of blocks. This might be why the additional grid stuff isn't necessary here. Am I missing something?
This is with flex-basis: 50%;
:
Again, I have no doubt that this is necessary on the front-end, but I think it's what's causing issues in the editor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good call. But if you change "break-medium" back to "break-small" here: https://github.com/WordPress/gutenberg/pull/12816/files#diff-49ac41bc72e24e343a451fe254801c0fR38 — it works again:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the small (2-column) breakpoint… I think as long as there's a margin b/w the columns, then flex-basis
needs to account for that doesn't it? 50% plus any margin will always wrap after the first column, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. But keep in mind that there is negative margins applied to columns in the editor only, to ensure that this looks right. Keep in mind the markup in the editor is different from the markup on the frontend — there are a lot more divs in the editor to enable the various tools for each block. So until we have access to something like display: contents;
there's likely always going to be a discrepancy between the frontend and backend.
Did you try flex-basis: 50%? For me it seemed to fix the issue of the extra right margin, but there could be situations I haven't accounted for there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me flex-basis:50%;
fixes the extra margin at the medium breakpoint, but only at the expense of breaking 2-column layout at the small breakpoint.
I think the problem was actually that at the medium breakpoint, I had reset the ODD/EVEN margins to initial
. That's correct on the front-end, but in the editor, they should be set to $block-padding.
It gets a little confusing with all the nesting, but I think that's right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me flex-basis:50%; fixes the extra margin at the medium breakpoint, but only at the expense of breaking 2-column layout at the small breakpoint.
This only works if you also set the wrap property to nowrap as noted in #12816 (comment).
But I'm going to take a look at your latest push, see if that fixes it!
Pushed some polish to the comments, and left an idea for a solution in https://github.com/WordPress/gutenberg/pull/12816/files#r242051845. |
I pushed a new commit which works for me. In the editor I get 2 columns at the small breakpoint and no extra margins at the medium breakpoint. I adjusted the margins so that we get the same spacing b/w columns (64px) in the editor and front-end. I don't love using Calc b/c it feels a little dirty to me, but I don't see a better way to get 2 even columns. Something like this might be ideal in the future, but it only works in FF currently.
One issue I still have is that the vertical spacing b/w rows is a little tight. The front-end CSS adds a |
The latest change seems to improve things a fair bit at the 2 column breakpoint. But the margins seem too big now, compared to master. This branch: Master: There's also an issue with many columns: Here's master: It's a big headache, I know. And it's getting late for me here in Denmark. I promise I'll take a good long stab at this tomorrow, look at your latest changes, and see if I can fix it up. |
@@ -35,7 +35,7 @@ | |||
// Responsiveness: Allow wrapping on mobile. | |||
flex-wrap: wrap; | |||
|
|||
@include break-small() { | |||
@include break-medium() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this a little bit already, but what is the context for changing this to medium?
To my understanding the ideal situation is this:
- Mobile (small) breakpoint has 1 column
- Medium breakpoint has 2 columns
- Above Medium has user set amount of columns.
To me this says that Mobile should wrap, but anything above mobile should not wrap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the context for changing this to medium?
The reason to change this to medium is so that the small-to-medium breakpoint (600px - 782px) can wrap after the EVEN columns.
Mobile:
1 (wrap)
2 (wrap)
3 (wrap)
4 (wrap)
5
Small to Medium
1, 2 (wrap)
3, 4 (wrap)
5
<!-- no wrap -->
Medium and up
1, 2, 3, 4, 5
If we set 'nowrap' at the Small breakpoint (600px), then the small-to-medium breakpoint doesn't work. flex-wrap:nowrap
will prevent the columns from wrapping.
Mobile:
1 (wrap)
2 (wrap)
3 (wrap)
4 (wrap)
5
<!-- no wrap -->
Small to Medium
1, 2, 3, 4, 5
Medium and up
1, 2, 3, 4, 5
I'm not opposed to removing the small-to-medium breakpoint entirely; I just didn't think that was the original intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a solid point. Thank you for clarifying, and for the patience.
- Reduce the margin between columns. This fixes an overlap issue at 6 columns wide. - Improve the wrapping and mobile, by adding a bottom margin to the column container.
Okay, I think the branch is now in a good state. I pushed a few small tweaks. I discovered at the wide alignments there was no overlap as previously noted here: But it was present when not wide: This suggested that the problem was lack of room, more than any other thing. So I reduced the margins, which I have come around to, were too large regardless. This is a big PR, so I think it's good to make this change along with it, especially as it solves a problem. There was an overlap issue at the 2 column breakpoint: This was because flex causes a new margin context, which means the block margins collapse. In other words, because we wrap the column blocks (singular), those now need a bottom margin. I added that: This was also necessary for mobile: This is now the frontend: And this is the backend: I think this is ready for a wider code review and good testing. So I'm expanding the range. |
I have addressed my own feedback points. Now awaiting others' reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working for me. Looks consistent between FE and Editor. 👍
// Beyond the medium breakpoint, show the user-set amount of columns. | ||
@include break-medium() { | ||
// Because columns do not wrap, reset the column margin. | ||
margin-bottom: initial; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initial
(also used in style.scss) should probably be replaced with the actual value of 0
for better browser support.
This was news to me not too long ago but IE doesn't support initial
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like postcss or something else is actually converting it to 0
in the final CSS anyway. Still probably a good idea to avoid the abstraction here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still probably a good idea to avoid the abstraction here.
Makes sense to me. I guess using initial
doesn't really get us anything.
@@ -18,7 +18,9 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change the shorthand flex: 1
to just the property we're using from it, flex-grow: 1
, here?
A little redundant. This is essentially what we currently have:
.wp-block-column {
flex: 1;
(flex-grow: 1)
(flex-basis: 0%)
flex-basis: 100%;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call there I'd say. I still always have to lookup what Flex:1;
actually means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I don't think we need to set flex:1;
or flex-grow:1;
at all. flex-basis:100%;
(or width:100%;
) is all we need.
} | ||
|
||
// All columns fit in one row at this breakpoint. | ||
@include break-medium() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This even, child, nth, first, not
reset stuff makes me dizzy 😵
Any interest in simplifying this?
Something along these lines maybe:
@include break-medium() {
// Fill in the left and right margin holes left by the previous small breakpoint.
// First column already has a margin-right and no margin-left.
&:not(:first-child) {
margin-left: $grid-size-large;
margin-right: $grid-size-large;
}
// Remove right margin on last column.
&:last-child {
margin-right: 0;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the value in simplifying things, but I also see the value in not changing the logic once a block is already in the wild. I'd defer to @jasmussen and others on this.
There's no real benefit to this, honestly. I may have gotten a little carried away trying make it simple. And it still looks complicated. 😀 |
I love the great feedback on this thread. In this particular case, I applaud the simplification. It's worth noting that the smaller the change we make, the more likely it is to get in soon. Already now this is sort of a big change, though we can mitigate that with thorough testing:
A note on IE11 — I recall columns working there, but the experience doesn't have to be top tier, it just has to not be broken. |
If we want to simplify and make it easy to understand, and we're willing to make significant changes then:
Now here's our entire style.scss
This was my thinking originally, but if we want to really simplify, then let's do it. EDIT:
Now it's more clear what those styles are doing, and we don't have to override our ODD/EVEN rules later. |
That's similar to how the text-columns are doing it. https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/text-columns/style.scss Skinning this cat could go on and on. Since the columns are actually "broken" currently, we should probably get a fix in sooner than later. We can iterate and improve the code after that if needed. Is there still a text-column block, btw? Not sure I've ever seen it... |
So, that brings us to the big question. When can we ship this? We have 5.0.x releases, which are supposed to be really small or really critical. And we have major releases which can be bigger, like 5.1. The latter obviously is a while out. @youknowriad if you have time — what are the chances for this pull request to make it to a minor release? And if it's too big as is, how small would it have to be to land in a minor release? |
I think this can go in 5.1 which is targeted for February. At this point it's not certain whether there will be a 5.0.3 before that. |
…flex-basis to width
I pushed a small update.
I did basic testing of editor and FE in Chrome, Safari, Firefox (all mac), as well as IE11. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good!
I tested this with a few different themes. Take a look at these gifs. The first two themes still showed an indention issue, but the last theme, Twenty Nineteen, appeared fine.
https://cloudup.com/cl64LZYWXyZ
I tested on MacBook Pro, Chrome 71.0.
I'm not entirely sure if this is a theme issue, or something else. If I can help with providing more info, please let me know.
I mostly agree @WraithKenny . I at one point had a version which eliminated the even, odd stuff.
In this case, a negative left margin would take this block out of the center and move it to the left of the screen. Like I said though, I do agree. There have got to be simpler methods. |
I do agree with @WraithKenny and @m-e-h that simpler would be better for the sake of theming, but the point of this PR is just to fix the bugs that were present in the initial release, not to make any other changes. |
I just tested in Atomic Theme and Monostack and I couldn't replicate these issues that @mapk had. Possibly themes have been updated? |
Closing this to avoid confusion. #12199 has similar fixes. |
This is a revision of #12408 which includes better comments and also applies the same fixes in the editor.
Background
There should be 3 breakpoints:
Mobile: less than 600px
all columns full width and stacked. No margins.
Small: 600px - 782px
columns wrap in rows of 2. Margins on the inside.
Medium: bigger than 782px
all columns fit in one row. Margins on the inside.
PROBLEMS!
PROBLEM 1
Columns don't wrap properly at Small breakpoint
SOLUTION
not
selectors to Medium breakpointPROBLEM 2
At the Medium breakpoint, when there is an odd number of columns, and extra margin is added to the last item.
SOLUTION
odd
andeven
selectors toinitial
at the Medium breakpointHow has this been tested?
tested in local wordpress docker env
ORIG:
https://codepen.io/drdogbot7/pen/NEOQPQ
FIX:
https://codepen.io/drdogbot7/pen/GwYVNz
Types of changes
Only css affecting core/columns.
Checklist:
closes #13035