Problem/Motivation
This problem occurs if content is added to a Layout builder and that content includes an element styled with a fixed width wider than the width of the column.
The column will assume the width of the wider child element, breaking the column layout.
This was discovered (and easy to reproduce) with the comment block, but this issue will happen with any content styled wider than the column width.
How this was discovered:
Steps to reproduce (also see youtube recording )
- Vanilla Drupal 8 (I used simplytest.me to verify)
- Activate Layout Builder module
- Activate Layout Builder on Article
- Modify Layout with two columns with body left and comments to the right
- Enter a artice (the comment form shows underneath instead beside)
- Enter comments
- Save
The comments appear below the body instead of to the right

Proposed resolution
Most likely resolution: Add Javascript that detects if a column includes a fixed width element that would cause the column to break to another line. In these cases, the columns should still break to another line, but their width should also be set to 100% (essentially the same behavior as what would take place at narrower screen widths, as the layouts are responsive)
Possible alternative: Add Y-scrolling to columns that would otherwise break to another line. This couuld
Approach that was discussed that will most likely not be used: setting the columns to overflow: hidden would also address the symptoms, but was considered a nonviable solution as it could potentially limit access to important content or inputs.
Remaining tasks
Get feedback on solution, ideally from real-world users.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #73 | 3028979-73.patch | 28.02 KB | gauravvvv |
| #67 | interdiff_54_67.txt | 597 bytes | arshadkhan35 |
| #67 | 3028979-54_0_reroll_against_8.9.x_branch.patch | 32 KB | arshadkhan35 |
| #65 | interdiff_62-65.txt | 964 bytes | vsujeetkumar |
| #65 | 3028979_65.patch | 33.74 KB | vsujeetkumar |
Comments
Comment #2
parijke commentedComment #3
parijke commentedComment #4
bnjmnmComment #5
bnjmnmThis was due to the comment form having inputs styled wider than the layout builder column it was placed in. This means the layout could potentially break if it contained any element with a fixed width wider than the column.
To fix this, I added
overflow: hiddento the layout columns. This was previously not set, so it used the defaultvisible.Comment #6
bnjmnmComment #7
amit.drupal commentedComment #8
amit.drupal commented@bnjmnm Test Patch #5 on Drupal 8.7.x-dev and Bartik 8.7.0-dev.
- Modify Layout with two columns with the body left and comments to the right
- Enter an article (the comment form shows underneath instead beside)
- Enter comments
- Save
Content display in a single layout. After apply patch content display in the single layout.
Patch is not working properly.
Comment #9
bnjmnm@amit.drupal - Since your steps match those I took when creating the patch, I'd like to confirm the CSS in this patch was loaded
Could you check with chrome inspector and confirm the css added in the patch is active while testing?
If using a two column layout, the rule you want to look for is:
.layout--twocol-section > .layout__region { overflow: hidden; }Comment #10
bnjmnmThis would be good to get in 8.7, so I've written tests to help reduce review-ambiguity. 3028979-10-test-only-FAIL.patch doubles as an interdiff.
If subsequent manual reviews do not see the issue addressed, please confirm the CSS rules are in place as mentioned in #9
Comment #12
xjmComment #13
bnjmnmComment #14
tim.plunkettThat test is *awesome*.
And the fix is clear and correct.
Thanks @bnjmnm!
Comment #15
xjmIt is indeed an awesome test!
I was both impressed by and nervous about that
evaluateScript(), so I checked HEAD...So there's plenty of precedent in HEAD for using it. One test even has:
$session->evaluateScript('window.jQuery("#data_div").data("testkey")')...so 👍.
Other than that, just a few test nitpicks:
Bundle for testing iron? I don't know what
festands for here. We should avoid using abbreviations in Drupal code (including test code).Nit: "Four-column" (with a hyphen) because it's a phrase modifying "layout".
How do we know for sure this is the case? This test could become a false positive if Bartik CSS changes for comments. Generally we want to add assertions for something like this to make sure the test is a true pass, and/or use a dedicated test fixture that forces whatever condition caused the bug before it was fixed.
Overall this is awesome and it's great to see that we have a way to test with. Thanks!
Comment #16
bnjmnmThat is a very good point, especially since it turned out the issue is not specific to the comment form - only discovered while using it. I changed the test to use a body field with an inline style that slightly exceeds the width of the widest possible column in Bartik. Everything related to comments was removed.
I also wanted to make sure the inline style approach was acceptable and not just leftover habits from working in React. I did a search on other test files and confirmed there were other examples of inline styles being used in tests
Comment #18
tim.plunkett#16 addresses #15 and I have no other concerns. What a cool test!
Comment #19
phenaproximaSorry, a few very minor things (the biggest concern is documenting the rationale of the test):
Not sure this comment adds anything. :)
Should be protected.
This can be assertCount(), for one less set of parentheses.
I was going to ask how the test can guarantee that the overflowing body field does, in fact, overflow the column, but then I saw what Ben said:
I think I would like this to be explicitly stated in a comment in the test (namely why Bartik was chosen, and that the test relies on details of Bartik), but it makes sense to me otherwise. +1 RTBC once these nits are addressed.
Comment #20
bnjmnm♻️🥖Reroll + addressed all the feedback in #19 (the level of detail is good stuff).
ALSO realized that the test was still loading the comment module & permissions even though it's no longer used in the test, so that's gone.
Comment #21
bnjmnmComment #22
bnjmnmIf possible, please act as if #20 never happened.
This patch addresses everything in #19.
In the interdiff, you'll also see changes to the test made due to the reroll and an update to an outdated comment.
Comment #23
tim.plunkettLooks great, thanks!
Comment #24
xjmThanks @bnjmnm! All good improvements. One thing still stands out though:
Bartik could still change its widest possible column in the future. That's we usually want some kind of an assertion that will fail if Bartik makes a change like that, or to create a different test theme fixture that has the same properties as the one that cause this bug, and test against that instead.
Comment #25
bnjmnmGood call in #24, removed Bartik from the test and added a module with CSS that replicates the symptoms of the issue.
Also want to mention that I noticed that the
layout_builder_test_css_transitionsmodule has a slightly different naming convention than Layout Builder's other the test modules. I considered renaming but decided against as this module is present in several other close-to-completion layout builder issues and will be removed when #2901792: Disable all animations in Javascript testing is completed.Comment #27
bnjmnmReroll - the size difference from #25 is because the
layout_builder_test_css_transitionsmodule is now in HEAD.Comment #28
phenaproximaNit: Why isn't this library called layout_builder.front_end_test?
"Attaches CSS to for testing"? :)
Nit: I don't think the comment is adding much, so it can probably go away. :)
Seems out of scope?
Nit: There should be a blank line after this paragraph.
This needs an @inheritdoc comment.
Also, I wonder why we don't merge the test_css_transitions module with the front_end_test module, since they seem to have an overlapping scope. However, that's not something we need to do in this issue.
This seems a bit strange. It should probably be something like:
There's no need for this anymore; $page->clickLink() will automatically do a similar assertion.
This could be something like:
This condition should probably be an additional boolean parameter passed to the test method, not hard-coded for a particular layout.
To prevent a possible fatal error if the element is not visible, we should add $this->assertNotEmpty($add_block).
This should also probably be refactored to be waitForElementVisible(); assertNotEmpty(); click();
Needs $this->assertNotEmpty() to prevent a potential fatal error.
Comment #29
bnjmnmAddressed feedback. Removed all changes to
layout_builder_test_css_transitionsas that module is now in HEAD and the changes are now out of scope (and don't change functionality)Comment #30
lauriiiUsing overflow could lead to worse problems than a broken layout. For example, there could be a button or action which would be hidden on certain screen widths, potentially preventing users from using some functionalities on the site. I'm not sure if there's a generic solution that could be applied, other than trying to eliminate all static widths in core, and encourage others to do the same.
Comment #31
phenaproxima+1, but that seems like quite a heavy undertaking and I ran into this bug today while trying to build a media demo using the layout builder. It is all too easy to encounter this problem in the course of normal page-building tasks, especially once you bring media into the picture. Besides, avoiding static widths is not always possible (embedding a video from a third-party source is a prime example).
One possible approach here, although it sucks, is to not hide horizontal overflow, but to allow it to scroll. I'm well aware that horizontal scrolling is awful (and I don't know if it's kosher from an accessibility standpoint, for that matter), but that might be an acceptable compromise until everything in core can scale correctly.
Comment #32
lauriiiStatic width elements should be avoided at all costs since they cause problems outside of layout builder with responsiveness. We should definitely add support for rendering oembed media entities with a fluid width.
I would support letting layouts break gracefully when they contain static width elements. Layout builder is already responsive, so the positionings shouldn't be taken as absolute. This would in most cases provide better UX compared to letting elements overflow one way or another.
Comment #33
xjmHmmm, this is a serious UX bug. The layout builder is basically nonfunctional if you have one of these elements contained in it. It's extremely confusing. (I know because I was utterly stumped by it.)
Comment #35
bnjmnmThis patch uses the approach suggested in #30 (which is also described as the "Most likely resolution" in the issue summary). There is JS that detects if a column has elements with static widths that exceed the column width. If this is the case, then a class is added to the section that results in all columns being 100% width (which they would also be at widths less than 40em).
I have a personal preference for the horizontal scrolling suggestion in #31, even if its kinda odd. Even then I can see why others may not like it. My main interest is getting some kind of solution to users as soon as possible, and as much as I'd like the column count on wider widths to match the section label , it's already understood that the columns will become 100% wide at certain viewport widths. This just triggers the mobile stacking a little earlier if there's an unfortunately wide static width element. The user experience is still improved.
Comment #37
bnjmnmSmall goofs in #35 addressed.
Comment #38
bnjmnmComment #41
bnjmnmThis specific patch has minor fixes so tests pass.
This is a copy of the comment from #35 so it's clear what the primary intent of the patch is
Comment #42
bnjmnmComment #43
bnjmnmComment #44
bnjmnmComment #45
phenaproximaSo the thing that concerns me about this patch is that, when the JavaScript takes effect and forces the columns into a mobile-ish layout, the user will probably be surprised as hell, because that is very unexpected behavior. To someone who doesn't know to expect it, it will flat-out look like a bug. This is going to need to be documented for sure.
At the very least, the JavaScript should call
console.log()with an informative developer-facing message. Even better, IMHO, would be to use our new shiny JavaScript messages API to set a user-facing message explaining why the columns have stopped behaving like columns. Ideally, this behavior would be configurable, since I can envision circumstances under which hiding the overflowing content would be the preferred solution.Comment #46
bkosborneInteresting problem. My personal preference is that this is up to the site builder/designer to recognize and fix by applying the 100% width to the fixed width elements. I agree it's may be a DrupalWTF to have the columns of a layout break like this, but I think it's also a DrupalWTF that Drupal would have JS that dynamically changes fixed widths of elements. I think a designer would be more frustrated trying to debug why one of their fixed with blocks is now 100% width (especially since it comes from some unknown JS) than to figure out that the columns broke because a fixed width element was inserted. The solutions presented here are not ideal because there's no obvious way this should be fixed in an automated manner.
Comment #47
bnjmnmIn Drupal slack, @aaronmchale made the following suggestion
.
While this certainly introduces a bit complexity, the tradeoff seems worthwhile. Here are a few of the reasons that come to mind:
Comment #48
bnjmnmThis is an implementation of the suggestion from @aaronmchale -- section configuration now includes an "Column Overflow Behavior" option.

The first time a section is added, the value chosen is stored in State per-user and becomes the default option for all additional sections added.
The fail patch comments the CSS for each option instead of being test-only. Otherwise the tests would fail when no "Column Overflow Behavior" field is found, instead of failing on the behavior that this patch was built to address.
Comment #51
bnjmnmMade a few changes to #48 so tests pass.
Comment #53
tim.plunkettNot sold on that amount of text in the UI but it sure seems to work.
While we can change these templates, it won't have an effect on 99% of sites, since these are copied into Stable theme.
Is there a way to accomplish what is needed without touching the templates?
Case should be "Column overflow behavior"
This is really nice of us. Maybe too much? Not sure. But either way, this is injectable
I know it's internal, but I think we should keep this around and deprecate it.
Comment #54
bnjmnm#53(intro)
. It's definitely an unweildy chunk of words, but I think it's important for that info to be there. I stuffed most of it in a details element so things are less noisy while still making the information available to users when needed.
#53.1
The change to the template isn't actually necessary, it was just removing code that is redundant now that the four column template has the classes generated by MultiColumnLayoutBase. Nothing bad happens if the template is unchanged, so I switched it back to its original form.
#53.2 Changed case
#53.3
Injected state. I'm into being nice here, since the option they choose will likely be the same for each section, and the behavior could be really confusing/frustrating if sections are inadvertently set to different overflow behaviors.
#53.4
Did the deprecation. Is a CR not necessary since this is internal, or should that still happen?
Comment #55
diamondseaJust to toss some other ideas in the mix at the last minute, the panel contents could also be resized using something like
1) Scale the content
.layout__region--content { transform: scale(.5) }or more dynamically scale it to the contents using something like CSS Transform Scale element to fit its parent (and possibly add a UI element indicating it has been scaled down).
2) Use ellipses for truncated text
.layout__region--content { text-transform: ellipsis }3) Fade out cropped content
Use a gradient to fade out the content at the bottom or right edges to indicate it has been cropped.
4) Perhaps make the large block of help text expandable with a help icon or "Show Help" link that expands when clicked.
All the above options could also be added as choices the user could select as the Column Overflow Behavior.
Comment #57
tim.plunkettI personally think this is too flexible. Layout Builder has achieved success by being customizable from contrib, but opinionated within core.
I'd like to pick a single solution and document how to accomplish other approaches in custom code.
Comment #59
vsujeetkumar commentedRe-roll patch created for 9.1.x, Please review.
Comment #60
vsujeetkumar commentedFixed test, Please review.
Comment #62
vsujeetkumar commentedFixing test.
Comment #64
tim.plunkettThe original indentation seemed fine?
This module was replaced with
css_disable_transitions_testwhich is loaded on all classes extending WebDriverTestBase, so this can be removed.Comment #65
vsujeetkumar commented@tim.plunkett Done with the changes mentioned in #64, Please review.
Comment #67
arshadkhan35 commentedRe-rolling #54 patch against 8.9.x branch.
Comment #73
gauravvvv commentedI have attached patch for 11.x. I have fixed the test failures. Not adding the interdiff as patch #67 doesn't apply anymore.
Comment #74
smustgrave commentedCan we confirm this is still an issue on D10?