-
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
Column wrapping is broken between 599px and 782px #18416
Comments
This is an interesting problem! Confirming I can reproduce it locally. I'd like to propose a solution using CSS grid instead of flexbox. There are several advantages to that approach:
Then if the user decides that the left column should take up 65% of the space, we can add inline
|
I think there's some conveniences in using Grid (notably the gap logic), but I'm not entirely convinced it's the right way to go. At least, my understanding of the distinction between Grid and Flexbox -- and when to use which -- is largely on the basis of 1-dimensional vs. 2-dimensional content. There is a potential model of considering columns as 2-dimensional content, which is in-fact how columns were initially implemented, up until #7234. You can see the specific problems with using Grid that way in that pull request and the original issue at #5351. Introducing the column wrapper element resolved this, but in so doing essentially converted the element hierarchy to one of two containers, where each container presents its contents 1-dimensionally (a Columns of horizontal Column elements, and a Column of vertical block content).
As I see it, if we're continuing to implement the Column wrapper, then Flexbox seems like the best fit. To a lesser degree, the current browser support forces us to support Flexbox anyways. It would be a maintenance burden to need to support both. |
Related comment at #20169 (comment) with regards to the original issue reported here:
|
An approach using |
@aduth the distinction between 1 and 2-dimensional content when choosing between flexbox and grid is only a guideline. A 1-dimensional design of sufficient complexity, such as what we have, especially when custom column widths come into play, is better served by grid than flexbox. Flexbox works with fixed width contents, but it wasn't designed for that purpose. The other consideration is that our columns reflow on mobile devices, thus becoming 2-dimensional. The problem with the previous implementation was trying to map the inner blocks of each column to the grid, when we should be mapping only the columns themselves. There might be a place for a Grid block that creates a grid of inner blocks, but that's not how the columns block should behave 😅 The advantages of using grid to solve this problem are the following:
If it's acceptable to have the custom column widths editor preview not work on IE, we could do this very neatly with CSS variables and grid, and a basic IE fallback using flexbox and auto widths. If we have to fully support custom widths in IE, that would require a more complex fallback, and use of inline styles which are harder to override. We should bear in mind that even if IE users are not able to preview resizing columns in the editor, it should still be possible for theme authors to create custom IE-compatible column styles if they so desire. Overall, it seems to me it would be worth trading a little bit less functionality in IE for sizeable benefits in theme styling. I'm happy to build another prototype using grid on top of the current columns implementation and we can see how it works 😁 |
@tellthemachines I think you should open a separate issue for using CSS Grid in the Columns block. I definitely agree that it's probably the way to go in the long term, though IE11 support is definitely going to be the biggest hurdle to overcome. |
I was about to submit a ticket for this and then saw this. So I will instead just add my info in case it's useful. Describe the bug To reproduce
Expected behavior Screenshots Desktop (please complete the following information):
Additional context
|
Oh, that's wonderful! I will for sure do that. |
I'm still seeing this problem myself in the latest version on Gutenberg Drupal. I reported it there; it appears as if they haven't yet merged this fix into their release.
|
I am still seeing this problem on a fresh install of WordPress. The css here is heavy handed and forces complex overrides to be written. Is this in the stable release? |
The issue
Consider a Columns block containing 2 columns. The Columns block uses
flex-wrap: nowrap
at a viewport width of 782px and above. Below that, it usesflex-wrap: wrap
, which, due to the 32px left margin applied to the 2nd column, would immediately wrap if it weren't for this line applied to the small breakpoint inpackages/block-library/src/columns/style.scss
:flex-basis: calc(50% - #{$grid-size-large});
By subtracting half of the margin size from the flex-basis calculations of each column, the columns do not wrap needlessly and everything is fine.
Until you decide to use custom column widths. Custom column widths are set using the
style
JSX attribute and do not take into account the gap between columns, so when your viewport is between 599px and 782px (exclusive), the columns wrap, but their width does not extend to be 100% like it does at 599px and below.Here is a screenshot showing the effect of this bug, as well as some of the related CSS rules:
Proposed solutions
At first it might seem that the answer is changing the inline style attribute for custom column widths in
packages/block-library/src/columns/editor.scss
. However, while something likeflexBasis: calc(${width}% - 16px)
would stop the weird wrapping, it would also cause sets of 3 or more columns to remain side-by-side at widths as small as 600px!There is also another issue: while
16px
works, it's a hardcoded value that should be replaced by the$grid-size-large
SCSS variable. But how do you use an SCSS variable in JSX style attributes? Is that even a good idea in the first place?Looking at the comments in the code and the commit history, I think the intention is that, between the small and medium breakpoints, the Columns block should show a maximum of 2 columns side-by-side, with each column taking up 50% of the available width.
Custom column widths were added later on, and since they use inline styles, they always override the maximum columns rule. Combined with flex wrapping being enabled below the 782px breakpoint, this causes columns with custom column widths to always wrap oddly at this viewport width.
A simpler solution is to use the dreaded
!important
on the 2 columns rule, forcing columns to all be the samecalc(50% - #{$grid-size-large})
width between 599px and 782px viewport widths.Notably, this would result in odd-numbered last columns taking up half the width of the screen with nothing on the other half. Is this desirable? If not, you could simply add another rule for odd-numbered last columns (e.g.
.wp-block-column:last-child:nth-child(odd)
) to make them full-width. (Of course, this would also have to use!important
.).One con of this method is that using
!important
would make theming more difficult; then again, it is already being used by the 1 column rule for viewport widths <= 599px.How to reproduce
Environment
Tested on Twenty Nineteen, Twenty Twenty, and Divi. This is not a theme-specific issue.
The text was updated successfully, but these errors were encountered: