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

Add flex layout to Buttons block and new layout type. #35819

Merged
merged 9 commits into from Nov 3, 2021

Conversation

tellthemachines
Copy link
Contributor

Description

Partially addresses #34872.

The Buttons block is slightly different to other blocks that have been migrated to layouts, because it has a Vertical variation that behaves in a flex column-like manner, and can be justified (though calling it justification is slightly inaccurate, because behind the scenes we're actually using align-items instead of justify-content to make it work with the column layout).

This means that neither of the current layout options will work here: flow doesn't have flex properties, and flex is optimised for horizontal layouts. So I introduced a new "column" layout variation that uses flex-direction: column and works with justification controls, translating them to use align-items.

I'd love to get some feedback on this approach before I start dealing with deprecations, tests etc. 😄

I left the second part of #34872 (adding flex layout to the Navigation Block) out for now, because though it has a similar Vertical variation, the way styles are applied to the content of the block is much more complex, as we have several nested containers that need to be configured with the orientation and justification/alignment flex properties. Layout currently works by applying styles generically to the top level of the block, so we'll have to think about how to make that work with nested containers. Or if we want to make it work like that at all 😅

How has this been tested?

Add a buttons block to your editor. Check that horizontal and vertical orientation, plus all the relevant justification options, still work as expected.

Screenshots

Types of changes

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).

@github-actions
Copy link

github-actions bot commented Oct 21, 2021

Size Change: +299 B (0%)

Total Size: 1.08 MB

Filename Size Change
build/api-fetch/index.min.js 2.17 kB +33 B (+2%)
build/block-editor/index.min.js 136 kB +301 B (0%)
build/block-editor/style-rtl.css 14.1 kB +18 B (0%)
build/block-editor/style.css 14.1 kB +18 B (0%)
build/block-library/blocks/buttons/editor-rtl.css 292 B -17 B (-6%)
build/block-library/blocks/buttons/editor.css 292 B -17 B (-6%)
build/block-library/blocks/buttons/style-rtl.css 275 B -42 B (-13%) 👏
build/block-library/blocks/buttons/style.css 275 B -42 B (-13%) 👏
build/block-library/blocks/navigation/style-rtl.css 1.72 kB +3 B (0%)
build/block-library/blocks/navigation/style.css 1.7 kB +2 B (0%)
build/block-library/blocks/separator/style-rtl.css 245 B -5 B (-2%)
build/block-library/blocks/separator/style.css 245 B -5 B (-2%)
build/block-library/editor-rtl.css 9.79 kB -8 B (0%)
build/block-library/editor.css 9.79 kB -7 B (0%)
build/block-library/index.min.js 157 kB +126 B (0%)
build/block-library/style-rtl.css 10.5 kB -24 B (0%)
build/block-library/style.css 10.5 kB -26 B (0%)
build/core-data/index.min.js 12.7 kB +160 B (+1%)
build/data/index.min.js 7.15 kB +54 B (+1%)
build/edit-site/index.min.js 30.9 kB +121 B (0%)
build/editor/index.min.js 37.4 kB -344 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/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-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 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 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/columns/style-rtl.css 497 B
build/block-library/blocks/columns/style.css 496 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.17 kB
build/block-library/blocks/cover/style.css 1.17 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 977 B
build/block-library/blocks/gallery/editor.css 982 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 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 502 B
build/block-library/blocks/image/style.css 505 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 493 B
build/block-library/blocks/media-text/style.css 490 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 642 B
build/block-library/blocks/navigation-link/editor.css 642 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 299 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.83 kB
build/block-library/blocks/navigation/editor.css 1.84 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 198 B
build/block-library/blocks/page-list/style.css 198 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/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 347 B
build/block-library/blocks/post-comments-form/style.css 347 B
build/block-library/blocks/post-comments/style-rtl.css 492 B
build/block-library/blocks/post-comments/style.css 493 B
build/block-library/blocks/post-content/style-rtl.css 56 B
build/block-library/blocks/post-content/style.css 56 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 396 B
build/block-library/blocks/post-featured-image/editor.css 397 B
build/block-library/blocks/post-featured-image/style-rtl.css 156 B
build/block-library/blocks/post-featured-image/style.css 156 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 391 B
build/block-library/blocks/post-template/style.css 392 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/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 223 B
build/block-library/blocks/quote/theme.css 226 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 397 B
build/block-library/blocks/search/style.css 398 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/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 770 B
build/block-library/blocks/site-logo/editor.css 770 B
build/block-library/blocks/site-logo/style-rtl.css 165 B
build/block-library/blocks/site-logo/style.css 165 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 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 824 B
build/block-library/blocks/social-links/editor.css 823 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB
build/block-library/blocks/social-links/style.css 1.32 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 560 B
build/block-library/blocks/template-part/editor.css 559 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/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 815 B
build/block-library/common.css 812 B
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/theme-rtl.css 668 B
build/block-library/theme.css 673 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 46 kB
build/components/index.min.js 212 kB
build/components/style-rtl.css 15.4 kB
build/components/style.css 15.4 kB
build/compose/index.min.js 10.9 kB
build/customize-widgets/index.min.js 11.2 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/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.44 kB
build/edit-navigation/index.min.js 15.9 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.4 kB
build/edit-post/style-rtl.css 7.12 kB
build/edit-post/style.css 7.12 kB
build/edit-site/style-rtl.css 5.79 kB
build/edit-site/style.css 5.78 kB
build/edit-widgets/index.min.js 16.4 kB
build/edit-widgets/style-rtl.css 4.17 kB
build/edit-widgets/style.css 4.18 kB
build/editor/style-rtl.css 3.78 kB
build/editor/style.css 3.77 kB
build/element/index.min.js 3.21 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.34 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 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.92 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.19 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.7 kB
build/server-side-render/index.min.js 1.52 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.82 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.11 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@oandregal
Copy link
Member

Hey, I'm not sure if I can provide much help here. Riad, Joen, and Andrew Serong have been involved in a lot of this work (probably others too), so they'd probably have some thoughts hore.

@jasmussen
Copy link
Contributor

Thanks for the PR, took it for a spin. Just for comparison, here's a "before" GIF showing horizontal and vertical orientations with the justifications and spacing working:
before

Here's an "after" gif, showing the same but from this branch:

buttons flex

Note one difference, here the justification controls are shown both in the toolbar and the inspector, which is the custom for blocks that opt into the proper flex method. That's good.

So just as a user experience and behavior, this appears to be working as intended 👍 👍

One thing I discovered. which could be due to my local environment, but sharing in case not:

  • In trunk, create a vertical list of buttons
  • Check out this branch, reload
  • Note how the buttons are now horizontal

Here's the markup I tried, and it shows up as horizontal in this branch:

<!-- wp:buttons {"contentJustification":"right","orientation":"vertical","style":{"spacing":{"blockGap":"12px"}}} -->
<div class="wp-block-buttons is-content-justification-right is-vertical"><!-- wp:button /-->

<!-- wp:button /-->

<!-- wp:button /-->

<!-- wp:button /-->

<!-- wp:button /--></div>
<!-- /wp:buttons -->

@andrewserong
Copy link
Contributor

Nice idea @tellthemachines! The general approach sounds good to me, I like that the resulting CSS for the Buttons block is essentially unchanged 👍. There were a bunch of edge cases that @stacimc had to wrangle in #34546, so this looks like it shouldn't affect those changes, which is good.

One thing I discovered. which could be due to my local environment, but sharing in case not:

  • In trunk, create a vertical list of buttons
  • Check out this branch, reload
  • Note how the buttons are now horizontal

I think that sounds like it's because of the removal of the orientation attribute? From the PR description, it looks like @tellthemachines is planning to update the deprecations to handle that migration for existing blocks.

};

export default {
name: 'column',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this layout will have other use-cases aside the "buttons" one?
What happens when we apply this layout type to a group, does it bring any value? Do we want a variation like "Row" added for the group block with this layout?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think of this column layout as a subtype of flex and its usefulness lies on the justification (at least for now).

The default/flow layout is another way to have a vertical list of blocks which now handles the widths of the block and targets grouping blocks.

Could this justification option be integrated with the default layout? Would it make sense? That would mean changing the display of Group (and other blocks that use the default layout) to flex and I'm not sure if there would be implications with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think of this column layout as a subtype of flex and its usefulness lies on the justification (at least for now).

So potentially could also be implemented by introducing an "orientation" config to the "flex" layout itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's another option for sure and that was my first thoughts about that when working with flex layout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've updated to use an "orientation" property on the flex layout. It makes sense because there was a lot of duplicated logic between flex and column.

@tellthemachines
Copy link
Contributor Author

Thanks for the feedback, everyone! I've addressed comments, added a deprecation and updated the fixtures so this should be ready for a more in-depth review now 🙂

@noisysocks noisysocks added this to 👀 Needs review in WordPress 5.9 Must-Haves via automation Oct 29, 2021
@youknowriad
Copy link
Contributor

Took this for a spin. I noticed that when switching between buttons variations, I'm losing the "Justify config". It feels like we should probably keep it. In other words, an orientation config on the "flex" layout would only make sense if the other configs (at least most of them) are kept right? otherwise, maybe a separate layout is better. (Just trying to understand when do we add config to a layout VS when to create a separate layout and define guidelines around it)

It seems there's only "space between" that is not present on the vertical variation, while right now it's true that it doesn't make sense but for me it would still make sense there if we say introduce a "height" control later for the buttons block.

@tellthemachines
Copy link
Contributor Author

Took this for a spin. I noticed that when switching between buttons variations, I'm losing the "Justify config". It feels like we should probably keep it.

Yeah, I looked into this and it's happening because of how we're setting the orientation as a block variation. The block variation defines e.g. layout: { type: 'flex' }, and it overrides the previous layout attribute. I'm thinking it probably makes more sense to set orientation as another Layout option in the block inspector, instead of as a block variation. I'll try that out and see how it works.

It seems there's only "space between" that is not present on the vertical variation, while right now it's true that it doesn't make sense but for me it would still make sense there if we say introduce a "height" control later for the buttons block.

If we do add a height control, then perhaps we could make "space-between" display conditionally on the height being set? Because otherwise it won't have any effect, and the experience will feel broken.

@tellthemachines
Copy link
Contributor Author

I've updated this to set orientation in the Layout section of the block inspector, instead of as a block variation. I also made it so that only blocks that have "orientation" defined in their layout attribute show the orientation controls, because they might not make sense for some blocks (I'm thinking of the Row variation of Group that should specifically be horizontal, but perhaps with this change we could potentially stop using Row altogether?)

@jasmussen
Copy link
Contributor

jasmussen commented Nov 2, 2021

Lovely work as usual. I see this segmented control in the inspector now:

buttons

I'll defer to others including Riad on whether an orientation toggle is the correct one, but I do recall @shaunandrews already suggesting one, which is one vote in favor. He's also brought up that we should mostly avoid segmented controls with only two options.

I think we can do better than the following sketch — pretty sure Shaun actually has a mockup somewhere we can leverage. But in the name of landing the feature in the near term, such a toggle group with two arrows might be a good initial start that we can then polish further:

Screenshot 2021-11-02 at 09 28 30

We might even be able to show the two controls on a single line:

One line

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Regardless of my questioning of the opt-out behavior, this is looking very good.

@@ -39,6 +52,12 @@ export default {
layout={ layout }
onChange={ onChange }
/>
{ layout?.orientation && (
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is interesting. It basically means that if the current layout doesn't have any orientation, do not display the control to switch "orientation". That said one can argue that the "no orientation" is just equivalent to "horizontal orientation" meaning we could just always show the toggle.

The problem with always showing the toggle is that it will show up in other blocks using the "flex" layout like the "Group" block (or its Row variation and potentially others). While one could argue that this is wrong since is a "row" right, conceptually it's not wrong. For instance, what about blocks like "Social Icons" and "Query Pagination" also using the "flex" layout, should we allow them to switch orientation? It might make sense.

So the thing here is that I'm hesitant between:

  • Keep things as they are in the PR: making the "orientation" undefined or not in the default layout value the actual flag that indicates whether to show this control or not.
  • Introduce a dedicated opt-out flag in the layout support config (and potentially only use it in the Group block)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An opt-out flag would be nice, especially if there's only one block where we really don't want to enable vertical orientation. Perhaps something like "allowOrientation": false?

It also occurred to me that if orientation were enabled for all blocks, we wouldn't need Row as a variation of Group at all. But Group is using flow layout; would there be any issues in migrating it to flex with vertical orientation?

Copy link
Member

Choose a reason for hiding this comment

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

Well, a flexbox layout doesn't let children use float, so yes, there would definitely be issues if "flow" did not remain as an option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh good point. I guess we'd better leave it as it is then.

@tellthemachines
Copy link
Contributor Author

I updated the inspector controls and tried switching orientation to opt out; it seems to work well! Any further comments, feedback etc.?

@noisysocks noisysocks merged commit 623829e into trunk Nov 3, 2021
@noisysocks noisysocks deleted the add/buttons-flex-layout branch November 3, 2021 05:22
WordPress 5.9 Must-Haves automation moved this from 👀 Needs review to ✅ Done Nov 3, 2021
@github-actions github-actions bot added this to the Gutenberg 11.9 milestone Nov 3, 2021
Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks so much for your great work here @tellthemachines!

Sorry for being late catching up, but I've left some comments to discuss 😄

} }
/>
</BlockControls>
<BlockControls
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove this, no?

return attributes;
}

const { contentJustification, orientation } = attributes;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove these attributes here and keep only the rest. You can also see them appear in the fixtures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand. These are used here to migrate any legacy settings to the new layout, e.g. if there's a deprecated block with "orientation" set we use that value in layout when we update the block. Or is there another way of doing it?

In the fixtures these attributes only appear in the deprecated versions of Buttons. That should be expected, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wait, you mean I should be removing them from the updated attributes?

Copy link
Contributor

Choose a reason for hiding this comment

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

I should be removing them from the updated attributes?

Yes. We extract them here and use them for the layout but since the current version doesn't contain them, these attributes shouldn't exist at the final migrated version of the block.

},
},
},
isEligible: ( { layout } ) => ! layout,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should have isEligible here. The thing is that when this function is checked it gets the attributes for this deprecation. This ends up having a newly created buttons block (using its default layout) and then in migrate the orientation:horizontal exists and applies the defaults from the migration.

You can check this by adding a different default in buttons block.json like:

"default": {
	"type": "flex",
	"orientation": "vertical",
	"justifyContent": "right"
}

Add a Buttons block, save and then reload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh, interesting. How does it work in the Social Links deprecation?

I can't remove isEligible altogether or the deprecation won't work, but I'll change the check to explicitly look for the contentJustification and orientation attributes, as these are the only ones we need to migrate. If they don't exist we can leave the block as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All feedback has now been addressed in #36192. Thanks for the review!

Copy link
Contributor

Choose a reason for hiding this comment

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

How does it work in the Social Links deprecation?

Because:

The specific handling by className below is needed because itemsJustification
was introduced in https://github.com/WordPress/gutenberg/pull/28980/files and wasn't
declared in block.json.

So I didn't remove any attributes there.

@shaunandrews
Copy link
Contributor

shaunandrews commented Nov 3, 2021

Ha, @jasmussen here's the mockup I had from a few months back:

image

The biggest difference from what you posted about is the language. I find "Direction" and "Alignment" to be more easily understandable than "Orientation" and "Justification," which feel more like jargon.

--

What I see in trunk is this:

image

I feel like the Orientation should be shown first, with the Justification settings after — and that these two controls are connected; If I change the Orientation to vertical, the Justification icons should rotate and their descriptions should update to use top and bottom instead of left and right. Similarly, I'm not sure if the "multiple lines" toggle makes much sense when the Orientation is set to vertical.

Why doesn't the vertical orientation support space-between? I guess it would require the container to have a defined height?

Here's how I would expect it to look:

image

@tellthemachines
Copy link
Contributor Author

One question: can we now remove the legacy alignment styles for Buttons or should they remain for back-compat purposes?

@jasmussen
Copy link
Contributor

One question: can we now remove the legacy alignment styles for Buttons or should they remain for back-compat purposes?

I think we've tried a few times (@kjellr is so busy these days he might not have time to respond here), and we've always come back to not being able to. We might be in the future, but if you're able to keep them for the time being, it's probably for the best.

@kjellr
Copy link
Contributor

kjellr commented Nov 4, 2021

Yeah, we've tried to remove those in the past, but they've broken existing content. I'd avoid it here if we can.

@TJBriggs
Copy link

Is it still possible to define contentJustification in our block templates? Did the syntax change? When I try to center a button within my code like this:

['core/buttons', { className: 'hero__buttons', contentJustification: 'center' }, [ ['core/button', { className: 'hero__button', text: 'Button Text' }], ]],

The blocks load initially but after publishing and refreshing the page in the admin, the buttons block breaks and I get the following error in the console:

Error: Minified React error #185; visit https://reactjs.org/docs/error-decoder.html?invariant=185 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

@tellthemachines
Copy link
Contributor Author

The syntax for content justification did change; instead of {contentJustification: 'center' } it is now { layout: {type: 'flex', justifyContent: 'center' } }. That said, there shouldn't be any errors with using the old syntax because there's a deprecation in place to handle it.

Could you share some reproduction steps and the version of Gutenberg you're on?

@youknowriad
Copy link
Contributor

@tellthemachines unfortunately deprecations don't work for templates, this has always been the case in Gutenberg. It's not really clear what the solution forward for this is. It might require some structural or API changes ultimately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Buttons Affects the Buttons Block [Type] Enhancement A suggestion for improvement.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet