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

Layout: Add default fallback gap value in block.json, and set to 2em for Columns blocks #41098

Merged
merged 6 commits into from
May 20, 2022

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented May 17, 2022

What?

This is an exploration into a potential fix for the gap regression in #40952 (it doesn't address the tablet breakpoint change raised in that issue).

In this PR we look at:

  • Adding a setting in block.json where blocks can declaratively provide a default fallback value for properties of the spacing block support. This PR only implements support for the blockGap property.
  • In the Layout block support, look up the block's definition, and see if it provides its own fallback value for blockGap, and use it if available.
  • For the Columns block we set the default fallback blockGap value to 2em to be consistent with backwards compatibility.
  • If no default value is provided we use the fallback value of 0.5em.

The idea here is that this new fallback value isn't in theme.json because it's a part of the block's styles — not the theme's, and is intended to form part of the base styling of the block, upon which themes can make their own changes.

Kudos @ramonjd for collaborating on the idea in this PR!

Why?

In #40952 it was flagged that the Columns block used to have a default gap value of 2em. This PR explores seeing whether we can declaratively set the fallback value for blocks in their block.json file — outside of the concept of theming. The gap of 2em was originally removed in #37436 when the Columns block was updated to opt-in to the Layout block support — it's the Layout block support that provides the default value of 0.5em, so this PR gives the Layout support a little more power to look up and output a fallback value that is suitable for the block being rendered.

How?

  • Add a default prop to the features of the spacing object in block.json to specify a default fallback value. E.g. spacing.blockGap.default.
  • Add a default value of 2em to the Columns block, with a default fallback of 0.5em.
  • Use this default value in the Layout block support.

Testing Instructions

  1. Using a classic theme like TwentyTwentyOne, add a columns block to a post or page.
  2. Notice that prior to this PR, the gap between columns is 0.5em. With this PR applied it should be 2em in both the editor and on the front end of the site.
  3. Using a blocks-based theme, check that the block spacing support still functions as expected (E.g. you can set a block spacing value in the post editor when editing a columns block). Note that block-level block spacing in global styles / theme.json is not yet supported, but the issue is raised in Layout blockGap / spacing: Add support for gap set at the block level in theme.json and global styles #39789

Screenshots or screencast

Before After
image image

@andrewserong andrewserong self-assigned this May 17, 2022
@andrewserong andrewserong added the [Type] Bug An existing feature does not function as intended label May 17, 2022
@andrewserong andrewserong changed the title Layout: Try adding a default fallback gap value in block.json [WIP] Layout: Try adding a default fallback gap value in block.json May 17, 2022
@andrewserong andrewserong added the [Block] Columns Affects the Columns Block label May 17, 2022
@github-actions
Copy link

github-actions bot commented May 17, 2022

Size Change: -2.25 kB (0%)

Total Size: 1.24 MB

Filename Size Change
build/block-editor/index.min.js 150 kB -307 B (0%)
build/block-editor/style-rtl.css 14.5 kB -402 B (-3%)
build/block-editor/style.css 14.5 kB -400 B (-3%)
build/block-library/blocks/image/editor-rtl.css 738 B +7 B (+1%)
build/block-library/blocks/image/editor.css 737 B +7 B (+1%)
build/block-library/blocks/video/editor-rtl.css 561 B -10 B (-2%)
build/block-library/blocks/video/editor.css 563 B -9 B (-2%)
build/block-library/editor-rtl.css 10.2 kB -2 B (0%)
build/block-library/editor.css 10.3 kB -1 B (0%)
build/block-library/index.min.js 181 kB +110 B (0%)
build/blocks/index.min.js 47.1 kB +7 B (0%)
build/components/index.min.js 227 kB +87 B (0%)
build/components/style-rtl.css 14.5 kB -556 B (-4%)
build/components/style.css 14.5 kB -553 B (-4%)
build/compose/index.min.js 11.7 kB +9 B (0%)
build/edit-navigation/style-rtl.css 4.05 kB -3 B (0%)
build/edit-navigation/style.css 4.05 kB -2 B (0%)
build/edit-post/index.min.js 30.4 kB +2 B (0%)
build/edit-post/style-rtl.css 7.08 kB -8 B (0%)
build/edit-post/style.css 7.08 kB -9 B (0%)
build/edit-site/index.min.js 47.9 kB +275 B (+1%)
build/edit-site/style-rtl.css 7.73 kB -238 B (-3%)
build/edit-site/style.css 7.71 kB -238 B (-3%)
build/edit-widgets/style-rtl.css 4.4 kB -3 B (0%)
build/edit-widgets/style.css 4.4 kB -2 B (0%)
build/editor/index.min.js 38.5 kB +64 B (0%)
build/editor/style-rtl.css 3.71 kB -4 B (0%)
build/editor/style.css 3.7 kB -4 B (0%)
build/list-reusable-blocks/style-rtl.css 835 B -3 B (0%)
build/list-reusable-blocks/style.css 835 B -3 B (0%)
build/media-utils/index.min.js 2.9 kB -39 B (-1%)
build/nux/index.min.js 2.1 kB -7 B (0%)
build/nux/style-rtl.css 744 B -7 B (-1%)
build/nux/style.css 741 B -8 B (-1%)
build/widgets/index.min.js 7.2 kB -4 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.77 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 6.51 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 150 B
build/block-library/blocks/audio/editor.css 150 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/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 59 B
build/block-library/blocks/avatar/style.css 59 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 445 B
build/block-library/blocks/button/editor.css 445 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 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 103 B
build/block-library/blocks/code/style.css 103 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 95 B
build/block-library/blocks/comments/editor.css 95 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.53 kB
build/block-library/blocks/cover/style.css 1.53 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 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 353 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 961 B
build/block-library/blocks/gallery/editor.css 964 B
build/block-library/blocks/gallery/style-rtl.css 1.51 kB
build/block-library/blocks/gallery/style.css 1.51 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 333 B
build/block-library/blocks/group/editor.css 333 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 76 B
build/block-library/blocks/heading/style.css 76 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/style-rtl.css 529 B
build/block-library/blocks/image/style.css 535 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 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 463 B
build/block-library/blocks/latest-posts/style.css 462 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 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 708 B
build/block-library/blocks/navigation-link/editor.css 706 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 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/view.min.js 375 B
build/block-library/blocks/navigation/editor-rtl.css 2.03 kB
build/block-library/blocks/navigation/editor.css 2.04 kB
build/block-library/blocks/navigation/style-rtl.css 1.95 kB
build/block-library/blocks/navigation/style.css 1.94 kB
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB
build/block-library/blocks/navigation/view.min.js 395 B
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 363 B
build/block-library/blocks/page-list/editor.css 363 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 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 260 B
build/block-library/blocks/paragraph/style.css 260 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/editor-rtl.css 69 B
build/block-library/blocks/post-comments-form/editor.css 69 B
build/block-library/blocks/post-comments-form/style-rtl.css 495 B
build/block-library/blocks/post-comments-form/style.css 495 B
build/block-library/blocks/post-comments/editor-rtl.css 77 B
build/block-library/blocks/post-comments/editor.css 77 B
build/block-library/blocks/post-comments/style-rtl.css 628 B
build/block-library/blocks/post-comments/style.css 628 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 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 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 323 B
build/block-library/blocks/post-template/style.css 323 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 80 B
build/block-library/blocks/post-title/style.css 80 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 370 B
build/block-library/blocks/pullquote/style.css 370 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 221 B
build/block-library/blocks/query-pagination/editor.css 211 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 369 B
build/block-library/blocks/query/editor.css 369 B
build/block-library/blocks/quote/style-rtl.css 213 B
build/block-library/blocks/quote/style.css 213 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 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 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 233 B
build/block-library/blocks/separator/style.css 233 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 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 759 B
build/block-library/blocks/site-logo/editor.css 759 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 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 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 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 504 B
build/block-library/blocks/table/editor.css 504 B
build/block-library/blocks/table/style-rtl.css 625 B
build/block-library/blocks/table/style.css 625 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 226 B
build/block-library/blocks/tag-cloud/style.css 227 B
build/block-library/blocks/template-part/editor-rtl.css 149 B
build/block-library/blocks/template-part/editor.css 149 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/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 993 B
build/block-library/common.css 990 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 11.5 kB
build/block-library/style.css 11.6 kB
build/block-library/theme-rtl.css 689 B
build/block-library/theme.css 694 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/core-data/index.min.js 14.6 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.39 kB
build/customize-widgets/style.css 1.39 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 7.98 kB
build/date/index.min.js 32 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.69 kB
build/edit-navigation/index.min.js 16 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-widgets/index.min.js 16.4 kB
build/element/index.min.js 4.3 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 6.62 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.83 kB
build/keycodes/index.min.js 1.41 kB
build/list-reusable-blocks/index.min.js 1.75 kB
build/notices/index.min.js 957 B
build/plugins/index.min.js 1.98 kB
build/preferences-persistence/index.min.js 2.23 kB
build/preferences/index.min.js 1.32 kB
build/primitives/index.min.js 949 B
build/priority-queue/index.min.js 628 B
build/react-i18n/index.min.js 704 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.69 kB
build/reusable-blocks/index.min.js 2.24 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11.2 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.52 kB
build/token-list/index.min.js 668 B
build/url/index.min.js 1.99 kB
build/vendors/react-dom.min.js 38.5 kB
build/vendors/react.min.js 4.34 kB
build/viewport/index.min.js 1.08 kB
build/warning/index.min.js 280 B
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.07 kB

compressed-size-action

@andrewserong andrewserong changed the title [WIP] Layout: Try adding a default fallback gap value in block.json Layout: Add default fallback gap value in block.json, and set to 2em for Columns blocks May 17, 2022
@andrewserong andrewserong marked this pull request as ready for review May 17, 2022 06:20
@@ -33,6 +33,9 @@
"padding": true,
"__experimentalDefaultControls": {
"padding": true
},
"__experimentalDefaultValues": {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it makes sense to use the proposed block.json changes from https://github.com/WordPress/gutenberg/pull/34180/files#diff-dba084b81a05295345ce9149af1a17ab073ddef43a393e851bcd3bdae85d3f32R81 for default values. (PR: Prototype: merge block CSS with theme.json styles #34180)

I don't know how far that particular investigation will go, but it could save some lines to "join forces"
cc @oandregal

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, neat idea!

There's quite a lot of similarity here — for the case of blockGap we only want to use the value as a fallback value if none is set anywhere else, rather than always outputting it, so that might be a subtle difference between a default / fallback value and a value set in blockStyles. But keen for feedback or ideas on how to combine things if you have any @oandregal!

I suppose the caveat here is that this PR will likely need to be backported to 6.0 RC whereas it looks like #34180 is a bit more forward-looking and something potentially for 6.1?

Copy link
Member

Choose a reason for hiding this comment

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

I suppose the caveat here is that this PR will likely need to be backported to 6.0 RC whereas it looks like #34180 is a bit more forward-looking and something potentially for 6.1?

Ah, very good point.

__experimentalDefaultValues does also do what it says on the tin as you say.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just blockGap: { default: "something" } instead of blockGap: true? (We do these object configs for a lot of block supports already)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The individual feature properties of the spacing support are currently boolean | array and the array is treated as a list of sides that are opted into, with logic like the following function (and the below useIsDimensionsSupportValid:

export function useCustomSides( blockName, feature ) {

It'd be a more complex change to refactor those props to also support an object (with a nested sides key), so I thought using a parallel object to set default values might make for a cleaner change given that this PR could be backported. There's a precedent in the Layout support, too, which has a default object and then within it, it specifies the properties:

We could always rename this from __experimentalDefaultValues to default, and it'd look like the following:

		"spacing": {
			"blockGap": true,
			"margin": [ "top", "bottom" ],
			"padding": true,
			"__experimentalDefaultControls": {
				"padding": true
			},
			"default": {
				"blockGap": "2em"
			}
		},

What do you think?

Copy link
Member

@ramonjd ramonjd May 17, 2022

Choose a reason for hiding this comment

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

Also we'd have to find a model to define default side values too, right? Well, maybe not initially. Still that would involve some data massaging I suppose.

"margin": [ "top", "bottom" ]

To something like

"margin": { default: { "top": "1em", ... } }

🤷

The individual feature properties of the spacing support are currently boolean | array and the array is treated as a list of sides that are opted into

It's possibly not the cleanest way, but I guess we could check for the existence of a default key (?) if we had to?

	if (
		! support ||
		typeof support[ feature ] === 'boolean' ||
		!! support?.[ feature ]?.default
	) {
		return;
	}

I'm not saying it's pretty, and I kinda also wonder if the complexity is worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a precedent in the Layout support, too, which has a default object and then within it, it specifies the properties:

Yeah, that's the one I was thinking about, since you can also do. __experimentalLayout: true (a defined object is the same thing as "true"). I don't think we should bother changing the others (padding, margin) now, but would be good to decide on an approach. I'd vote for the object approach personally but wouldn't mind the alternative used here.

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 here! It turns out it wasn't as complex to deal with as I'd thought given that we only appear to look up which sides are opted into in the one place (useCustomSides).

In a2cc158, I've gone with the approach of:

		"spacing": {
			"blockGap": {
				"default": "2em"
			},

And we can also specify a sides key, too, in that object if we need to.

@ramonjd
Copy link
Member

ramonjd commented May 17, 2022

In #40952 it was flagged that the Columns block used to have a default gap value of 2em. This PR explores seeing whether we can declaratively set the fallback value for blocks in their block.json file — outside of the concept of theming.

I'm trying think of other use cases for which this change would be useful. Basically, I'm keen on this PR and want to shore up my confirmation bias 🥴 but I can't right now 🤔

We're trying to set a style fallback value for a block; a value that can be referenced across the application where no other exists.

Right now, it's the layout implementation that needs to know a particular block's gap value before it arbitrarily sets it own.

The way the styles are output means that we can't solve this using CSS alone, e.g., by adding gap: 2em to .wp-columns since it will always be overwritten by the layout styles regardless of whether there's a gap value set or not.

We want layout to overwrite such style when a gap value has been set by the user, but not necessarily when no gap value has been set by the user.

It's this maze that has brought us here. So discounting a total refactor of [insert unknown code here], what this PR proposes seems to be the most straight forward approach.

The main attraction for me is that we'll have a place to store Gutenberg block style fallbacks outside CSS files, removing the need for complex CSS overrides if we ever need to change other values in the future.

I guess my only hesitation would be to extend the block API with something that is intended to address a special case.

cc @gziolo asking you because I've seen your handle all over the block.json metadata 😄

@@ -11,6 +11,7 @@ import {
arrowDown,
Copy link
Contributor

Choose a reason for hiding this comment

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

what about flow.js? no fallback support there?

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 noticed that too when I went to work on this feature — the Flow layout currently doesn't use any fallback value at all, so I didn't inject one where there isn't one already (both in layout.php and flow.js). From looking over the code again, it appears that blockGap styles in the Flow layout are only ever output if the blockGap has been opted into, in which case there'll always be a value, so a fallback value will never be reached. E.g. in the following block:

if ( hasBlockGapStylesSupport ) {

It was the Flex layout that currently has a 0.5em hard-coded fallback, and where I think this feature is useful based on the current implementations.

But, please do let me know if I missed something here! 🙂

@andrewserong
Copy link
Contributor Author

Thanks for you thoughts @ramonjd!

I guess my only hesitation would be to extend the block API with something that is intended to address a special case.

Yes, that's my main hesitation too — whether or not it's useful beyond this special case. I guess that's also one of the reasons I leaned toward listing it as an __experimental prop, so that we could keep it in while we need the feature, and as we continue to explore options for refactoring the Layout support (like the presets-based approaches and so on), we could then remove it altogether when it's no longer useful. But, of course, I know it's hard to remove things once we've added them! 😅

@ramonjd
Copy link
Member

ramonjd commented May 18, 2022

This is working pretty well for me:

Classic theme
Screen Shot 2022-05-18 at 9 59 34 am

Block theme
Screen Shot 2022-05-18 at 9 57 29 am

so that we could keep it in while we need the feature, and as we continue to explore options for refactoring the Layout support (like the presets-based approaches and so on),

I can't fault that logic. In some situations we need the freedom to explore ideas, which was part of the point of __experimental I believe

@peterwilsoncc
Copy link
Contributor

I did some testing manually and this appears to be working nicely.

I know some people have strong feelings about putting __experimental items in to Core but it's an ongoing discussion so let's not call it a blocker.

@ndiego
Copy link
Member

ndiego commented May 18, 2022

Are we still trying to get this into 6.0, or are we looking at 6.0.1? This is basically the last item on the 6.0 Project Board, but since RC3 is already out, I was planning to move to the 6.0.1 board. However given the impact of the original issue and all the activity here, I'm second guessing myself. 😅 Just let me know either way, thanks!

@gziolo
Copy link
Member

gziolo commented May 18, 2022

@peterwilsoncc highlighted this issue as one of the bug fixes we want to get into WP 6.0 RC 4 which will probably happen on Friday. See https://wordpress.slack.com/archives/C035NHLFUSY/p1652848301916789 (link requires registration at https://make.wordpress.org/chat).

@ndiego
Copy link
Member

ndiego commented May 18, 2022

Perfect, thanks @gziolo!

@gziolo
Copy link
Member

gziolo commented May 18, 2022

@andrewserong, do you plan to apply any feedback from the review or is it good enough as a temporary solution to ship in WordPress 6.0 next week? From my perspective, this PR can target directly wp/6.0 branch and contain minimal changes that are scoped to the Columns block and have even specific flag in block support like supports.__experimentalFallbackDefaultGap: "2em". This way, you can work on the more general API separately that will get tested in the Gutenberg plugin first before landing in WordPress core.

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

I've tested this in block themes, core classic themes going back to 2011, and a few custom themes e.g., Techine, OceanWP, Neve, Livro, Conceptly

Screen Shot 2022-05-19 at 9 51 36 am

this PR can target directly wp/6.0 branch and contain minimal changes that are scoped to the Columns block and have even specific flag in block support like supports.__experimentalFallbackDefaultGap: "2em".

This is interesting! So we'd add these changes for the wp-6.0 branch only?

Sounds like a neat way to give us some breathing room and finesse the API for 6.1. 👍

I suppose it'd make implementation in this PR simpler if we had a single block.json property __experimentalFallbackDefaultGap for columns block.json only, but would it make much a difference @andrewserong ?

@andrewserong
Copy link
Contributor Author

Thanks for the feedback, folks!

I've updated the PR in a2cc158 to go with Riad's suggestion of moving the default value to be an object property of spacing.blockGap, as this feels more consistent with other approaches (e.g. layout) and seems to neaten things up a little bit.

From my perspective, this PR can target directly wp/6.0 branch

I think the way it's implemented now, if folks agree, could happily merge into trunk and then we could cherry pick it into that branch? Ideally it'd be nice to have the feature work the same in trunk and wp/6.0 so that we don't unexpectedly have different behaviour.

If there isn't consensus on landing the PR in its current shape, though, I'm happy to open up a separate PR targeting wp/6.0 tomorrow morning, scoping it to just the columns block.

Thanks again! 🙇

@andrewserong
Copy link
Contributor Author

I'm wrapping up for the week now, but feel free to merge this in, anyone, if the approach (and __experimental prefix) looks viable. Thanks for all the feedback!

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Let's get this one in for WordPress 6.0 RC 4.

As discussed in the comment, we use __experimentalDefault to avoid introducing a new API just before the major WordPress release. However, it feels like it should be perfectly fine to make this API stable in a follow-up PR together with all the necessary documentation changes.

@gziolo gziolo merged commit 51db4bf into trunk May 20, 2022
@gziolo gziolo deleted the try/provide-default-fallback-gap-values-in-block-json branch May 20, 2022 08:22
@gziolo gziolo added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label May 20, 2022
@github-actions github-actions bot added this to the Gutenberg 13.4 milestone May 20, 2022
adamziel added a commit that referenced this pull request May 20, 2022
…for Columns blocks (#41098)

* Layout: Try adding a default fallback gap value in block.json

* Implement in the editor, too

* Try moving the default value to sit under the blockGap key in spacing, updated useCustomSides to support an object

* Update doc comment

* Add explanatory comments

* Add __experimental prefix to default property.

Co-authored-by: Adam Zielinski <adam@adamziel.com>

Co-authored-by: Adam Zielinski <adam@adamziel.com>
@adamziel
Copy link
Contributor

I just cherry-picked this PR to the wp/6.0 branch to get it included in the next release: 497c7ec

@adamziel adamziel removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label May 20, 2022
@andrewserong
Copy link
Contributor Author

Thanks so much @gziolo and @adamziel, much appreciated! 🙇

@carasmo
Copy link

carasmo commented May 25, 2022

Please, can someone summarize what I should do to fix this issue? It's horrible to not be able to rely on Gutenberg ... now, if the sites auto update on Flywheel, they will look bonkers.

@ramonjd
Copy link
Member

ramonjd commented May 25, 2022

Please, can someone summarize what I should do to fix this issue? It's horrible to not be able to rely on Gutenberg ... now, if the sites auto update on Flywheel, they will look bonkers

Hi @carasmo!

Do you mean the columns gap? This PR made it into WordPress 6.0 so the previous default of 2em for columns should be there.

@carasmo
Copy link

carasmo commented May 25, 2022

Thanks for the reply! I'm using 6.0 and there's no gap between columns.

@ramonjd
Copy link
Member

ramonjd commented May 26, 2022

I'm using 6.0 and there's no gap between columns.

Hmm, I just took a look. I was testing WordPress 6.0 running Twenty Twenty-Two theme (latest version of Gutenberg plug not activated) and it looks like the new columns gap value is there:

Screen Shot 2022-05-26 at 9 59 31 am

Here's where the value is specified: https://github.com/WordPress/wordpress-develop/blob/6.0/src/wp-includes/blocks/columns/block.json#L32

With the Gutenberg plugin activated however, and running WordPress 6.1-alpha-53448 and Twenty Twenty-Two theme (using this repo's wp-env), the default columns gap value isn't coming through however 🤔

@ramonjd
Copy link
Member

ramonjd commented May 26, 2022

With the Gutenberg plugin activated however, and running WordPress 6.1-alpha-53448 and Twenty Twenty-Two theme (using this repo's wp-env), the default columns gap value isn't coming through however 🤔

Withdraw that comment. I hadn't built the plugin properly (npm run dev died on me)

So it looks fine to me @carasmo

Which theme and version of the Gutenberg plugin (if any) are you running? Or is it WordPress 6.0 only?

@carasmo
Copy link

carasmo commented May 26, 2022

I'm running a custom theme with 6.0 only.

@ramonjd
Copy link
Member

ramonjd commented May 26, 2022

I'm running a custom theme with 6.0 only.

Sorry, I can't reproduce this 🤔

I'd be great if you could create a new issue with a description of how to reproduce, plus a screenshot of what you're seeing and the name of the theme you're using.

We can then move the discussion to a dedicated place seeing as this PR is merged.

Here's a link to create a new issue: https://github.com/WordPress/gutenberg/issues/new/choose

Thank you!

@carasmo
Copy link

carasmo commented May 26, 2022

Note: I don't have a class .wp-container-... anywhere. I use a group, then I make columns. The the gap between columns is gone as of 6.0 (figure A). In 5.9.3, there was a margin on the .wp-block-columns class (figure B).

Figure A (WP 6):
Screen Shot 2022-05-26 at 5 55 52 AM

Figure B (WP 5.9.3):
Screen Shot 2022-05-26 at 6 08 22 AM

@pbiron
Copy link

pbiron commented May 26, 2022

I just ran into this problem as well (while testing several sites before updating to them to 6.0). These sites use a custom classic (non-block) theme and have a couple of custom dynamic blocks which output markup such as

<div class='wp-block-columns custom-class'>
  <div class='wp-block-column another-custom-class'>
     ...
  </div>
  <div class='wp-block-column another-custom-class'>
     ...
  </div>
  <div class='wp-block-column another-custom-class'>
     ...
  </div>
</div>

where the custom block relies on the styles that WP < 6.0 included in wp-includes/css/dist/block-library/style.css.

My current plan is to update the theme to include

@media (min-width: 782px) {
	.wp-block-columns:not( .is-not-stacked-on-mobile ) > .wp-block-column:not( :first-child ) {
		margin-left: var( --wp--style--block-gap, 2em );
	}
}

as a short-term workaround so that I can get the sites updated to 6.0.

@carasmo
Copy link

carasmo commented May 27, 2022

Yes, I'm going to have to go into many sites and add something in the additional css to address this. In the current site I'm working on, I'm doing the following. Soon I'm going to make my own column block and avoid these time suckers.

.theme-body-class .wp-block-columns {
	column-gap: var( --column-gap-svp );
} 

@media ( min-width: $col-collapse-min-width ) {

	.theme-body-class .wp-block-columns {
		column-gap: var( --column-gap-lvp );
	} 
	
}

@mburridge
Copy link
Contributor

Added the Needs Dev Note label in case this needs a dev note for the 6.1 release.

@andrewserong andrewserong added the [Feature] Layout Layout block support, its UI controls, and style output. label Sep 29, 2022
@bph bph mentioned this pull request Oct 3, 2022
89 tasks
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 [Feature] Layout Layout block support, its UI controls, and style output. Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Bug An existing feature does not function as intended
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.