Skip to content
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: Update columns to allow full height stretch when vertically aligned #32909

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

aaronrobertshaw
Copy link
Contributor

Fixes: #32907

Description

  • Allows column blocks to stretch to the full height when aligned vertically so background colors appear as expected.

Notes

The ability to set a background color on individual columns was recently added. Prior to then columns simply set align-self styles to achieve the vertical alignment.

This PR changes columns to be display: flex; and vertically align their children within them in line with the column's vertical alignment selection. This is working with multiple inner blocks or nested columns.

How has this been tested?

Manually.

  1. Checkout this PR, create a new post and add a columns block, choosing the 50/50 split
  2. Within the first column insert a tall image or block of content.
  3. Select the second column, set a background color and add some short content
  4. Try out the different vertical alignment options for the second column
  5. Save post and confirm display is correct on the frontend
  6. Switch themes and reconfirm display is correct

Screenshots

Before After
Screen Shot 2021-06-23 at 5 45 35 pm vertical-align-column-fix

Types of changes

Bug fix / enhancement.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@aaronrobertshaw aaronrobertshaw added [Block] Columns Affects the Columns Block CSS Styling Related to editor and front end styles, CSS-specific issues. labels Jun 23, 2021
@aaronrobertshaw aaronrobertshaw self-assigned this Jun 23, 2021
@github-actions
Copy link

github-actions bot commented Jun 23, 2021

Size Change: +378 B (0%)

Total Size: 1.06 MB

Filename Size Change
build/block-library/blocks/columns/style-rtl.css 607 B +110 B (+22%) 🚨
build/block-library/blocks/columns/style.css 606 B +110 B (+22%) 🚨
build/block-library/style-rtl.css 10.4 kB +79 B (+1%)
build/block-library/style.css 10.4 kB +79 B (+1%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.19 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.2 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/index.min.js 134 kB
build/block-editor/style-rtl.css 13.9 kB
build/block-editor/style.css 13.8 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 474 B
build/block-library/blocks/button/editor.css 474 B
build/block-library/blocks/button/style-rtl.css 600 B
build/block-library/blocks/button/style.css 600 B
build/block-library/blocks/buttons/editor-rtl.css 315 B
build/block-library/blocks/buttons/editor.css 315 B
build/block-library/blocks/buttons/style-rtl.css 370 B
build/block-library/blocks/buttons/style.css 370 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 206 B
build/block-library/blocks/columns/editor.css 205 B
build/block-library/blocks/cover/editor-rtl.css 666 B
build/block-library/blocks/cover/editor.css 670 B
build/block-library/blocks/cover/style-rtl.css 1.23 kB
build/block-library/blocks/cover/style.css 1.23 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 983 B
build/block-library/blocks/gallery/editor.css 988 B
build/block-library/blocks/gallery/style-rtl.css 1.6 kB
build/block-library/blocks/gallery/style.css 1.59 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 728 B
build/block-library/blocks/image/editor.css 728 B
build/block-library/blocks/image/style-rtl.css 482 B
build/block-library/blocks/image/style.css 487 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 488 B
build/block-library/blocks/media-text/style.css 485 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 568 B
build/block-library/blocks/navigation-link/editor.css 570 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 300 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/style-rtl.css 195 B
build/block-library/blocks/navigation-submenu/style.css 195 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.72 kB
build/block-library/blocks/navigation/editor.css 1.72 kB
build/block-library/blocks/navigation/style-rtl.css 1.5 kB
build/block-library/blocks/navigation/style.css 1.49 kB
build/block-library/blocks/navigation/view.min.js 2.74 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 202 B
build/block-library/blocks/page-list/style.css 202 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/editor-rtl.css 210 B
build/block-library/blocks/post-author/editor.css 210 B
build/block-library/blocks/post-author/style-rtl.css 182 B
build/block-library/blocks/post-author/style.css 181 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B
build/block-library/blocks/post-comments-form/style.css 140 B
build/block-library/blocks/post-comments/style-rtl.css 360 B
build/block-library/blocks/post-comments/style.css 359 B
build/block-library/blocks/post-content/editor-rtl.css 138 B
build/block-library/blocks/post-content/editor.css 138 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 398 B
build/block-library/blocks/post-featured-image/editor.css 398 B
build/block-library/blocks/post-featured-image/style-rtl.css 143 B
build/block-library/blocks/post-featured-image/style.css 143 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 378 B
build/block-library/blocks/post-template/style.css 379 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 60 B
build/block-library/blocks/post-title/style.css 60 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 378 B
build/block-library/blocks/pullquote/style.css 378 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 262 B
build/block-library/blocks/query-pagination/editor.css 255 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query-title/editor-rtl.css 85 B
build/block-library/blocks/query-title/editor.css 85 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 220 B
build/block-library/blocks/quote/theme.css 222 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 374 B
build/block-library/blocks/search/style.css 375 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 250 B
build/block-library/blocks/separator/style.css 250 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 462 B
build/block-library/blocks/site-logo/editor.css 464 B
build/block-library/blocks/site-logo/style-rtl.css 153 B
build/block-library/blocks/site-logo/style.css 153 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 165 B
build/block-library/blocks/social-link/editor.css 165 B
build/block-library/blocks/social-links/editor-rtl.css 812 B
build/block-library/blocks/social-links/editor.css 811 B
build/block-library/blocks/social-links/style-rtl.css 1.3 kB
build/block-library/blocks/social-links/style.css 1.3 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 636 B
build/block-library/blocks/template-part/editor.css 635 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/editor-rtl.css 90 B
build/block-library/blocks/term-description/editor.css 90 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 853 B
build/block-library/common.css 849 B
build/block-library/editor-rtl.css 9.76 kB
build/block-library/editor.css 9.75 kB
build/block-library/index.min.js 147 kB
build/block-library/reset-rtl.css 527 B
build/block-library/reset.css 527 B
build/block-library/theme-rtl.css 665 B
build/block-library/theme.css 669 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 47 kB
build/components/index.min.js 210 kB
build/components/style-rtl.css 15.9 kB
build/components/style.css 15.9 kB
build/compose/index.min.js 10.3 kB
build/core-data/index.min.js 12.3 kB
build/customize-widgets/index.min.js 11.1 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/data/index.min.js 7.1 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.45 kB
build/edit-navigation/index.min.js 15.1 kB
build/edit-navigation/style-rtl.css 3.69 kB
build/edit-navigation/style.css 3.69 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 28.9 kB
build/edit-post/style-rtl.css 7.18 kB
build/edit-post/style.css 7.17 kB
build/edit-site/index.min.js 27.4 kB
build/edit-site/style-rtl.css 5.21 kB
build/edit-site/style.css 5.21 kB
build/edit-widgets/index.min.js 16.1 kB
build/edit-widgets/style-rtl.css 4.09 kB
build/edit-widgets/style.css 4.09 kB
build/editor/index.min.js 37.7 kB
build/editor/style-rtl.css 3.76 kB
build/editor/style.css 3.75 kB
build/element/index.min.js 3.17 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 5.34 kB
build/format-library/style-rtl.css 668 B
build/format-library/style.css 670 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.6 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.72 kB
build/keycodes/index.min.js 1.3 kB
build/list-reusable-blocks/index.min.js 1.85 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.88 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.28 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.6 kB
build/server-side-render/index.min.js 1.42 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.74 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.27 kB
build/widgets/style-rtl.css 1.17 kB
build/widgets/style.css 1.18 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@aaronrobertshaw aaronrobertshaw changed the title Update columns to allow full height stretch when vertically aligned Columns: Update columns to allow full height stretch when vertically aligned Jun 23, 2021
@andrewserong
Copy link
Contributor

andrewserong commented Jul 2, 2021

Thanks for working on this one @aaronrobertshaw, I like this change, and it feels like a better approach for the alignment (we want to align the child items of the column rather than the column itself). Unfortunately it looks like this introduces an issue for horizontal alignment with blocks like the image block.

Before this change, with the image left aligned, the inserter or block to the right of the image will move around the image:

column-flex-item-before.mp4

After this change, the inserter doesn't move relative to the size of the left aligned image, and when I insert a paragraph block, it sits behind the left aligned image:

column-flex-item-after.mp4

I'm guessing that the float-based alignment doesn't play nicely with being a flex item?

Other than that, the change works nicely for retaining the height of the column and the column background while aligning the items within it. I can't quite think of a simple workaround without adding an additional container?

@aaronrobertshaw
Copy link
Contributor Author

Appreciate the detailed review as always @andrewserong 👍

Unfortunately it looks like this introduces an issue for horizontal alignment with blocks like the image block.

Before this change, with the image left aligned, the inserter or block to the right of the image will move around the image:

I actually see different behaviour when I run trunk. The alignment of an image block as an immediate child of the column doesn't work there either.

This is what I experience with the current layout/styles on trunk:

ColumnAlignmentIssuesTrunk

I'm guessing that the float-based alignment doesn't play nicely with being a flex item?

That's my guess as well as to the root cause. The issue on trunk might have similar origins just further up the tree.

I've pushed a comment that forces an auto margin left on an immediate child of the column with the data-align="right" attribute. This pushes it to the right but will not allow wrapping of other content. The wrapping content can still be achieved though by using a group block around the content the user wishes to float and wrap. Essentially, that is the additional container you mentioned.

After applying the new style to force right alignment I get the following behaviour:

ColumnAlignmentIssues4

I suspect we might also have some theme specific issues with this, so it could use further testing on that front. Which theme were you using in your videos? I couldn't replicate the issue with the image's resizable container overlapping the quick inserter.

@aaronrobertshaw
Copy link
Contributor Author

I've found that I can replicate the issue with the inserter being overlapped when using the Maywood theme. I'll test further with that.

@aaronrobertshaw aaronrobertshaw force-pushed the update/columns-vertical-alignment branch from efac62f to dc83d3d Compare July 6, 2021 03:43
@aaronrobertshaw
Copy link
Contributor Author

It appears that the overlapping issue comes from the .wp-block[data-align] element getting a height of 0 via classic.css in the theme. Switching that to height: auto makes it behave more like a theme such as TwentyTwentyOne Blocks.

Looking into this has highlighted the change to flex display also prevents the inserter DOM element getting a width resulting in the inserter icon display off to the left of where it should be. This effects all themes for me.

I've tried switching a few different approaches using flex or grid without a clear winner. A few additional tweaks have been pushed, along with rebasing this one.

Let me know if you have any ideas as to an alternate approach, I'm running out of ideas.

@andrewserong
Copy link
Contributor

Thanks for digging into this one @aaronrobertshaw (and figuring out that I was using the Maywood theme!). It is a tricky one.

The wrapping content can still be achieved though by using a group block around the content the user wishes to float and wrap. Essentially, that is the additional container you mentioned.

As a workaround, that actually sounds quite reasonable to me. Since this PR could introduce a regression for existing layouts that folks might be using with wrapped content, I'm wondering if it'd be worth moving the display: flex to only apply when one of the vertical alignment options is selected? E.g. move it to the &.is-vertically-aligned-top rules, etc? There'd be a bit of duplication adding it to the separate rules, but it might help guard against existing Columns out in the wild being adversely affected?

On my test site it's working nicely using an additional group block for the situation where I might need the text to wrap around the aligned image element: (The unusually large vertical margin is from the Maywood theme's styling):

Left alignment within column Left alignment within group block within column
image image

I've tried switching a few different approaches using flex or grid without a clear winner.

I think this feature is a matter of striking a balance between trade-offs, unfortunately! Being able to have the column background color reach the full height of the columns block unlocks a number of good options for pattern designs (e.g. vertically centered content in a row of columns with striking background colors) that we mightn't be able to achieve otherwise. And with this change, it's still possible to do the floated alignment with wrapped paragraphs if the user adds an additional container block. So, I think if we can see about only setting the column to flex when a vertical alignment is applied, hopefully that'll be a decent enough trade-off.

We'll then want to test this across a number of themes / block combinations to make sure we're happy with the trade-offs?

One other tiny note, it looks like this needs a rebase now after #31816 landed (apologies!)

@aaronrobertshaw aaronrobertshaw force-pushed the update/columns-vertical-alignment branch from dc83d3d to dc82868 Compare July 9, 2021 02:22
@aaronrobertshaw
Copy link
Contributor Author

Since this PR could introduce a regression for existing layouts that folks might be using with wrapped content, I'm wondering if it'd be worth moving the display: flex to only apply when one of the vertical alignment options is selected?

This is actually a thought I had while revisiting this as well. I missed adding the style back in after continuing to experiment, looking for alternative solutions. Thanks for catching this!

I think this feature is a matter of striking a balance between trade-offs, unfortunately!

Agreed. I believe this is good option for the moment as it does, as you say, unlock a lot of design possibilities while still allowing the wrap around effect albeit with the use of the group block.

One other tiny note, it looks like this needs a rebase now after #31816 landed (apologies!)

I rebased this prior to adding back in the style to only apply flex layout when column is aligned vertically.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

This is testing nicely for me @aaronrobertshaw, and in a multi-column layout where a user might want an active vertical alignment setting on one or more columns, while keeping one of the columns without that alignment setting, the floated left/right alignment is working correctly. For example, this kind of layout works (though the Columns blocks' mobile breakpoints don't play that well with it):

image

I think the current implementation in this PR strikes a good balance of trade-offs, enabling the desired styling, while minimising impact for left/right alignment, so this LGTM, and I tested with half a dozen themes across Safari, FF, Chrome, and Edge. But, it might be worth getting another pair of eyes from a designer, too 🙂

@aaronrobertshaw
Copy link
Contributor Author

Appreciate the thorough testing across themes and browsers @andrewserong. 🙇

It is certainly appreciated given the potential impact of such changes. To that end, I agree, it would be handy to get some extra eyes on this.

@jasmussen or @paaljoachim if you have some spare time, would you be able to take a look at this and let me know if there is anything that I've missed. Thanks in advance 👍

@retrofox
Copy link
Contributor

Hi, there. Have you considered adding a Full height aligment option to the toolbar Something that we did for the cover block .

@aaronrobertshaw
Copy link
Contributor Author

Thanks for the suggestion @retrofox 👍

I did consider a similar approach early on. It felt like it was adding extra complexity to the controls and toolbar when the user is already more than likely requesting full height behaviour. The issues @andrewserong highlighted in regards to wrapping inner aligned/floated elements would remain either way.

My understanding of our general approach to these sorts of issues is to err on the side of providing sensible defaults and minimising the need for additional controls. It feels as though full height columns when a background is set is a fairly sensible or expected behaviour that also avoids the need for an extra control.

I'm more than happy to get further opinions on this and update as needed or include the extra control/classes etc.

@aaronrobertshaw aaronrobertshaw added the Needs Design Feedback Needs general design feedback. label Jul 23, 2021
@jasmussen
Copy link
Contributor

Coming back to this after some AFK, thanks for the ping! Thanks for working on this, it's a fix we want. My immediate and only question is this part of the code:

	// Only apply display flex for vertically aligned columns.
	&[class*="is-vertically-aligned-"] {
		display: flex;
		flex-direction: column;
	}

It sounds to me like floats are the primary challenge that makes this be a conditional, correct? Specifically thinking of this comment:

The wrapping content can still be achieved though by using a group block around the content the user wishes to float and wrap. Essentially, that is the additional container you mentioned.

Floats have been challenging in flex containers in the past, and a recent layout related refactor fully embraced and suggested the "group first" approach to floats (something which we can potentially enhance further with patterns and pattern transforms).

Mostly I'm concerned about code complexity and a proliferation of edgecases by changing the display mid-stream like this. Do these concerns make sense or am I missing a beat? Thanks @andrewserong and @aaronrobertshaw

@jasmussen
Copy link
Contributor

jasmussen commented Aug 2, 2021

Here's an adjacent conversation about floats: #33332 (comment):

Could a possible solution involve making the LayoutStyle component less opinionated about which blocks it applies styles to?

That doesn't sound like a great solution because alignments are dependent on their parent, for instance in a "columns" block (flex container), floats are not allowed.

@andrewserong
Copy link
Contributor

It sounds to me like floats are the primary challenge that makes this be a conditional, correct?

Yes, I believe so.

Mostly I'm concerned about code complexity and a proliferation of edgecases by changing the display mid-stream like this. Do these concerns make sense or am I missing a beat?

Those concerns definitely make sense to me! I know what you mean, each time we add edge cases, it makes the CSS harder to read and means we've got additional cases to test whenever we make changes. So good to avoid if possible.

It's a tricky one with the Column block, because I do like the idea of ditching floats altogether and just letting flex work the way it needs to, but we also want to avoid causing regressions for columns out in the wild where folks might have used left or right aligned images as direct children of the column. So, I think the trade-off here is how much backwards compatibility we want to maintain (and whether we're happy with the potential impact of switching the column to flex).

@jasmussen would your preference be for us to keep flex and ditch the rules to support floats, or do you have another approach in mind?

Damian's suggestion of a full height alignment option is also a compelling idea, but could also wind up adding extra complexity, too? 🤔

@jasmussen
Copy link
Contributor

It's a doozy, I see the problem. Each column is display: block; which means if it's aligned using "align-self", then it no longer spans the height. Whereas in this branch, it uses justify-content, to align the insides instead of the block itself, thus requiring flex.

The curious thing here is, in my testing (block themes only), floats don't work at all inside columns even now. Which we either embrace and disable the float button, or fix with column specific float overrides such as this PR adds.

But if we do that, add float overrides, couldn't we just embrace flex for column's (singular column blocks) entirely, and remove the conditional?

@andrewserong
Copy link
Contributor

The curious thing here is, in my testing (block themes only), floats don't work at all inside columns even now. Which we either embrace and disable the float button, or fix with column specific float overrides such as this PR adds.

Interesting! Re-testing on trunk now, I can't reproduce floats working with paragraph text wrapping around floated image blocks within a column block, either. So if that's the current behaviour, then yes, maybe it'd be better to embrace flex entirely. My only reservation is making sure that we don't accidentally introduce regressions for columns that are out in the wild.

But I agree, it'd be nice to embrace flex entirely if we can. We've been focused on some other PRs this week, but I'm happy to do a bit more testing on this next week to see what's feasible!

@aaronrobertshaw
Copy link
Contributor Author

Interesting! Re-testing on trunk now, I can't reproduce floats working with paragraph text wrapping around floated image blocks within a column block, either.

I believe your earlier testing was with the Maywood theme @andrewserong.

On trunk, quickly flicking the theme over to Maywood, you can see an image floats still within a column allowing the following paragraph block to wrap. Other themes out of my limited library that allowed the float wrapping were; Ambitious, Hever, Seedlet, TwentyTwentyOne (non blocks), TwentyTwenty, TwentyNineteen and so on.

Screen Shot 2021-08-06 at 5 44 16 pm

I like the consistency of embracing flex and dropping support for floated elements as immediate children of the column. There should still be the work around of enclosing whatever you want to wrap within a group block.

That still leaves us with the problem of backwards compatibility for all the themes out there that use floats for left/right alignment. The current CSS rule limiting the display of flex to only vertically aligned columns does reduce the potential breakage for columns and themes already out in the wild. As much as I'd like to drop it, I don't think we can.

@andrewserong
Copy link
Contributor

Thanks for the reminder, Aaron, yes I was testing with Maywood.

The current CSS rule limiting the display of flex to only vertically aligned columns does reduce the potential breakage for columns and themes already out in the wild. As much as I'd like to drop it, I don't think we can.

Agreed, it does feel safer to preserve that.

@aaronrobertshaw
Copy link
Contributor Author

That doesn't sound like a great solution because alignments are dependent on their parent, for instance in a "columns" block (flex container), floats are not allowed.

The previous testing of various themes would indicate to me, that comments elsewhere stating floats are not allowed in columns isn't exactly accurate or at least is ambiguous.

Whether columns should be exclusively flex containers and not support float alignments of inner blocks, is perhaps a separate question. I think of this PR as correcting or bringing the behaviour more into line with existing use and expectations, rather than drawing a line in the sand over how columns should be laid out.

Can this land as is, given it does improve the columns block? Would it prevent a more detailed discussion of converting columns to flex only in a separate issue/PR?

@jasmussen
Copy link
Contributor

Can this land as is, given it does improve the columns block? Would it prevent a more detailed discussion of converting columns to flex only in a separate issue/PR?

Since it would be easy to follow up on, nothing beats trying it out in practice. 👍 👍

@aaronrobertshaw aaronrobertshaw force-pushed the update/columns-vertical-alignment branch from dc82868 to 14acfda Compare August 9, 2021 07:05
@apeatling apeatling removed the Needs Design Feedback Needs general design feedback. label Sep 21, 2021
@apeatling
Copy link
Contributor

@aaronrobertshaw Looks like this one could merge, are you waiting on any more feedback?

@aaronrobertshaw
Copy link
Contributor Author

Thanks for checking in @apeatling. I was waiting to see if the work around flex via the layout support might have been adopted for the Columns block.

At this point, if there are no objections to the current approach, I'll rebase it, give it another test then can merge it.

@aaronrobertshaw aaronrobertshaw force-pushed the update/columns-vertical-alignment branch from 14acfda to 67924d9 Compare September 22, 2021 01:56
@aaronrobertshaw aaronrobertshaw force-pushed the update/columns-vertical-alignment branch from 67924d9 to 63d1dc3 Compare September 22, 2021 02:08
@aaronrobertshaw
Copy link
Contributor Author

After some further testing on this I found;

  • the original issue remains a problem on trunk
  • the approach taken in this PR still fixes the column height after a rebase
  • a new issue where a column's immediate child had narrow content it would no longer fill the column width

Screen Shot 2021-09-22 at 11 55 56 am

To address the new issue I've added a :where CSS rule to assign a width of 100% to immediate child .wp-block elements within a vertically aligned column. This solves the problem for me while remaining easy enough to override when needed.

Before (Trunk)

Screen.Recording.2021-09-22.at.10.58.57.am.mp4

After (This PR)

Screen.Recording.2021-09-22.at.11.00.41.am.mp4

@andrewserong
Copy link
Contributor

andrewserong commented Sep 22, 2021

Thanks for following up on this one @aaronrobertshaw! I just took it for a spin, and noticed that with this PR applied, adjusting the vertical alignment also appears to affect the spacing between blocks. Here's a before / after:

Before (trunk) After (this PR)
Kapture 2021-09-22 at 12 35 12 Kapture 2021-09-22 at 12 39 19

I'm testing with TT1-Blocks theme active, but let me know if you need any extra info! Edit: I had Twenty Twenty-One (not TT1-Blocks) active.

@aaronrobertshaw
Copy link
Contributor Author

Appreciate the quick turnaround in testing @andrewserong 👍

adjusting the vertical alignment also appears to affect the spacing between blocks

I don't believe this one will be theme-specific.

We are having to rely on setting a flex layout for the column. As far as I'm aware, flex layouts don't support margin collapsing and it is the lack of margin collapsing that results in the increased spacing between blocks. In other words, all the flex items' margins are actually honored.

I'm not having much luck working around this. So open to fresh ideas if you have any?

@andrewserong
Copy link
Contributor

I'm not having much luck working around this. So open to fresh ideas if you have any?

Thanks for the explanation surrounding margin collapse, that makes sense why it's behaving differently! I just did a bit of hacking around, but unfortunately I haven't been able to come up with a workaround, either. It'd be a pity to mess with the vertical rhythm of an existing theme, but I suppose at least the behaviour is guarded behind having a vertical alignment selected? I think the thing to explore next is whether or not the trade-off is appealing to designers or folks with a bit more experience working with theme development.

Some not particularly useful dead-end ideas:

  • See if we could do padding-top or padding-bottom instead (doesn't really work, because we can't know what value to set it to without some JS).
  • Adding an additional container to the column (kinda works, but goes against the approach for blocks to keep the markup lean).
  • Add a group block within each column block (to an inner blocks template, perhaps?) — works manually, but like adding another container, it adds to the overall nesting which isn't great.

Overall, I like the idea of using flex for the column (and it feels like the right way to go about it), but it'll be interesting to see how much themes are relying on the margin collapse and whether or not it's a deal breaker 🤔

@ramonjd
Copy link
Member

ramonjd commented Sep 22, 2021

Sep-22-2021 15-15-51

Probably highly dodgy, but we could play with row-gap for the above effect.

Here's what I did to get the above effect:

	/**
	* Individual Column Alignment
	*/
	&.is-vertically-aligned-top {
		justify-content: flex-start;
		row-gap: var(--global--spacing-vertical) !important;
	}

	&.is-vertically-aligned-top > * {
		margin-top: 0 !important;
		margin-bottom: 0 !important;
	}

P.S. I used !important only because I was !impatient in my testing 😄

@aaronrobertshaw
Copy link
Contributor Author

Probably highly dodgy, but we could play with row-gap for the above effect.

An interesting idea. My concern would be how that would play with blocks that the user has set manual margins on e.g. via blocks supports, or maybe a theme author by theme.json where the value doesn't match the global.

@ramonjd
Copy link
Member

ramonjd commented Nov 8, 2021

I was testing this again last night and couldn't find a way around the lack of margin-collapsing for flexbox. But it made me think: what if we gave column blocks a display: flex with (potentially) a vertically-aligned value of top by default?

@aaronrobertshaw
Copy link
Contributor Author

I was testing this again last night and couldn't find a way around the lack of margin-collapsing for flexbox

I haven't found the solution yet either.

Once we have increased adoption of block gap or margin support, the extra spacing due to the lack of margin-collapse for flexbox could be configured away. I think this is an acceptable price to pay for users wanting to be able to have the full height background in columns.

Even as it is now, if that extra spacing is a problem, you could wrap contents in a group block and regain that margin-collapse. Obviously, it's difficult to expect users to know that's an option. It is for an edge case and the desire to have full height backgrounds appears to be of more concern.

But it made me think: what if we gave column blocks a display: flex with (potentially) a vertically-aligned value of top by default?

Doing this would potentially introduce a regression on blocks already out in the wild. In particular, those columns that have floated/aligned inner content. #32909 (comment)

@porg
Copy link

porg commented Jun 26, 2023

No workaround for this design need with native blocks

  • To use a group in row layout with vertical alignment "Stretch to fill" achieves the effect of same height blocks.
  • But then there's no responsive wrapping possible (that they get full width on mobile).

PR fix attempt already 3 midsummers old now…

  • Would appreciate that function still.
  • Has the root cause maybe a fix meanwhile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Columns Affects the Columns Block CSS Styling Related to editor and front end styles, CSS-specific issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Columns block: Background color does not stretch full-height with vertical alignment set
7 participants