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

Core CSS support for root padding and alignfull blocks #42085

Merged
merged 37 commits into from
Jul 15, 2022

Conversation

tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Jul 1, 2022

What?

Fixes #35607; alternative to #42034.

Why?

Because root padding doesn't always make sense applied only to the root element (e.g. body). As explained in #35607, we should be able to apply it instead to full-width blocks at any level of nesting.

How?

  • Use of this implementation is optional for themes; opt-in via a setting in theme.json.
  • Attaches custom properties with root padding values to the root element (body in the front end, .editor-styles-wrapper in the editor);
  • Applies right and left padding to all blocks with content width set (whether default theme widths or custom values)
  • Applies negative margins to alignfull children of blocks with root padding set.
  • Fixes bug whereby alignfull children of blocks with custom padding wouldn't extend to full width of their container.

UPDATE: As of 02fb1dd, this PR no longer adds the root padding toggle to blocks without content width. This part of the work will be dealt with separately, as suggested here

Testing Instructions

  1. Add "useRootPaddingAwareAlignments": true to the settings of your theme's theme.json to enable these changes.
  2. Add a Group block to the post and the site editor and set a content width on it.
  3. Add an Image block inside the Group and set it to full width.
  4. Change root padding value in the site editor by going to Global Styles > Layout > Padding
  5. Check that new padding value works in both editors and front end.
  6. Check that removing "useRootPaddingAwareAlignments": true from theme.json reverts to the previous behaviour (root padding is applied only at the root level, so no blocks extend to full viewport width)

Screenshots or screencast

Trunk:

Screen Shot 2022-07-05 at 3 17 39 pm

This branch without "useRootVariables" enabled in the theme:

Screen Shot 2022-07-05 at 3 04 36 pm

This branch with "useRootVariables" enabled in the theme:

Screen Shot 2022-07-05 at 3 04 06 pm

@github-actions
Copy link

github-actions bot commented Jul 1, 2022

Size Change: +5.52 kB (0%)

Total Size: 1.26 MB

Filename Size Change
build/block-editor/index.min.js 153 kB +555 B (0%)
build/block-editor/style-rtl.css 14.6 kB +39 B (0%)
build/block-editor/style.css 14.6 kB +39 B (0%)
build/block-library/blocks/cover/style-rtl.css 1.55 kB -1 B (0%)
build/block-library/blocks/cover/style.css 1.55 kB -1 B (0%)
build/block-library/blocks/gallery/style-rtl.css 1.53 kB +36 B (+2%)
build/block-library/blocks/gallery/style.css 1.53 kB +37 B (+2%)
build/block-library/blocks/image/editor-rtl.css 736 B -2 B (0%)
build/block-library/blocks/image/style-rtl.css 627 B +103 B (+20%) 🚨
build/block-library/blocks/image/style.css 630 B +100 B (+19%) ⚠️
build/block-library/blocks/social-links/style-rtl.css 1.39 kB +20 B (+1%)
build/block-library/blocks/social-links/style.css 1.38 kB +21 B (+2%)
build/block-library/blocks/template-part/editor-rtl.css 178 B +29 B (+19%) ⚠️
build/block-library/blocks/template-part/editor.css 178 B +29 B (+19%) ⚠️
build/block-library/editor-rtl.css 10.2 kB +22 B (0%)
build/block-library/editor.css 10.2 kB +21 B (0%)
build/block-library/index.min.js 184 kB +1.37 kB (+1%)
build/block-library/style-rtl.css 11.7 kB +128 B (+1%)
build/block-library/style.css 11.7 kB +129 B (+1%)
build/blocks/index.min.js 47.1 kB +109 B (0%)
build/components/index.min.js 230 kB +180 B (0%)
build/components/style-rtl.css 14 kB +11 B (0%)
build/components/style.css 14.1 kB +11 B (0%)
build/core-data/index.min.js 14.7 kB -4 B (0%)
build/customize-widgets/index.min.js 11.2 kB +26 B (0%)
build/data/index.min.js 7.99 kB +34 B (0%)
build/dom/index.min.js 4.69 kB +32 B (+1%)
build/edit-post/index.min.js 30.5 kB +25 B (0%)
build/edit-site/index.min.js 53.6 kB +531 B (+1%)
build/edit-widgets/index.min.js 16.5 kB +28 B (0%)
build/editor/index.min.js 41.3 kB +1.85 kB (+5%) 🔍
build/format-library/index.min.js 6.75 kB +6 B (0%)
build/rich-text/index.min.js 11.1 kB +3 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 982 B
build/annotations/index.min.js 2.76 kB
build/api-fetch/index.min.js 2.26 kB
build/autop/index.min.js 2.14 kB
build/blob/index.min.js 475 B
build/block-directory/index.min.js 6.58 kB
build/block-directory/style-rtl.css 990 B
build/block-directory/style.css 991 B
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 103 B
build/block-library/blocks/audio/style.css 103 B
build/block-library/blocks/audio/theme-rtl.css 110 B
build/block-library/blocks/audio/theme.css 110 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 441 B
build/block-library/blocks/button/editor.css 441 B
build/block-library/blocks/button/style-rtl.css 543 B
build/block-library/blocks/button/style.css 543 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 187 B
build/block-library/blocks/comment-template/style.css 185 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 615 B
build/block-library/blocks/cover/editor.css 616 B
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 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 110 B
build/block-library/blocks/embed/theme.css 110 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 253 B
build/block-library/blocks/file/style.css 254 B
build/block-library/blocks/file/view.min.js 346 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 948 B
build/block-library/blocks/gallery/editor.css 950 B
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 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 327 B
build/block-library/blocks/html/editor.css 329 B
build/block-library/blocks/image/editor.css 737 B
build/block-library/blocks/image/theme-rtl.css 110 B
build/block-library/blocks/image/theme.css 110 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 705 B
build/block-library/blocks/navigation-link/editor.css 703 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 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation-submenu/view.min.js 423 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.96 kB
build/block-library/blocks/navigation/style.css 1.95 kB
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB
build/block-library/blocks/navigation/view.min.js 443 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 96 B
build/block-library/blocks/post-comments-form/editor.css 96 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 632 B
build/block-library/blocks/post-comments/style.css 630 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 605 B
build/block-library/blocks/post-featured-image/editor.css 605 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 282 B
build/block-library/blocks/post-template/style.css 282 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 365 B
build/block-library/blocks/query/editor.css 364 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 385 B
build/block-library/blocks/search/style.css 386 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 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 464 B
build/block-library/blocks/shortcode/editor.css 464 B
build/block-library/blocks/site-logo/editor-rtl.css 708 B
build/block-library/blocks/site-logo/editor.css 708 B
build/block-library/blocks/site-logo/style-rtl.css 192 B
build/block-library/blocks/site-logo/style.css 192 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/spacer/editor-rtl.css 322 B
build/block-library/blocks/spacer/editor.css 322 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 494 B
build/block-library/blocks/table/editor.css 494 B
build/block-library/blocks/table/style-rtl.css 611 B
build/block-library/blocks/table/style.css 609 B
build/block-library/blocks/table/theme-rtl.css 175 B
build/block-library/blocks/table/theme.css 175 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/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 561 B
build/block-library/blocks/video/editor.css 563 B
build/block-library/blocks/video/style-rtl.css 159 B
build/block-library/blocks/video/style.css 159 B
build/block-library/blocks/video/theme-rtl.css 110 B
build/block-library/blocks/video/theme.css 110 B
build/block-library/common-rtl.css 987 B
build/block-library/common.css 984 B
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/theme-rtl.css 695 B
build/block-library/theme.css 700 B
build/block-serialization-default-parser/index.min.js 1.11 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/compose/index.min.js 11.7 kB
build/customize-widgets/style-rtl.css 1.4 kB
build/customize-widgets/style.css 1.4 kB
build/data-controls/index.min.js 653 B
build/date/index.min.js 32 kB
build/deprecated/index.min.js 507 B
build/dom-ready/index.min.js 324 B
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 4.02 kB
build/edit-navigation/style.css 4.03 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/style-rtl.css 6.97 kB
build/edit-post/style.css 6.97 kB
build/edit-site/style-rtl.css 8.23 kB
build/edit-site/style.css 8.22 kB
build/edit-widgets/style-rtl.css 4.35 kB
build/edit-widgets/style.css 4.35 kB
build/editor/style-rtl.css 3.65 kB
build/editor/style.css 3.65 kB
build/element/index.min.js 4.27 kB
build/escape-html/index.min.js 537 B
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.64 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.77 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.78 kB
build/keycodes/index.min.js 1.38 kB
build/list-reusable-blocks/index.min.js 1.74 kB
build/list-reusable-blocks/style-rtl.css 835 B
build/list-reusable-blocks/style.css 835 B
build/media-utils/index.min.js 2.93 kB
build/notices/index.min.js 953 B
build/nux/index.min.js 2.05 kB
build/nux/style-rtl.css 732 B
build/nux/style.css 728 B
build/plugins/index.min.js 1.94 kB
build/preferences-persistence/index.min.js 2.22 kB
build/preferences/index.min.js 1.3 kB
build/primitives/index.min.js 933 B
build/priority-queue/index.min.js 612 B
build/react-i18n/index.min.js 696 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.68 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.53 kB
build/token-list/index.min.js 644 B
build/url/index.min.js 3.61 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 268 B
build/widgets/index.min.js 7.19 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

@tellthemachines tellthemachines changed the title Apply root padding only on blocks with content width Core CSS support for root padding and alignfull blocks Jul 5, 2022
@tellthemachines tellthemachines marked this pull request as ready for review July 5, 2022 05:22
@tellthemachines tellthemachines added [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Jul 5, 2022
@tellthemachines
Copy link
Contributor Author

Would be good to get some feedback from @WordPress/gutenberg-design too!

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.

Thanks for the ping @tellthemachines. This is testing well for me at the root level, but I didn't quite follow how it's meant to work for nested blocks. Apologies, I quite possibly missed something obvious while testing at the end of the day!

I ran into an issue with trying to use the Use global padding toggle within the editor. It appeared that the toggle doesn't seem to be doing anything (tested with emptytheme and TwentyTwentyTwo):

2022-07-05 17 04 47

My understanding is that the idea of that toggle, is that if the theme has global padding set, that it then applies that padding to the current group block?

Possibly unrelated to this PR, but I also found it tricky to work out when I could or couldn't have children of the Group block be set to full width. It looks like the container Group block needs to be set to Full width, in order for children to be able to be set to Full width?

Happy to do more testing tomorrow!

@@ -64,6 +65,17 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
$style .= "$selector .alignfull { max-width: none; }";
}

// Handle negative margins for alignfull children of blocks with custom padding set.
// They're added separately because padding might only be set on one side.
if ( isset( $block_padding['right'] ) ) {
Copy link
Contributor

@andrewserong andrewserong Jul 5, 2022

Choose a reason for hiding this comment

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

With this rule, is it only useful when the block uses inherit? Without setting inherit I wasn't able to access the full alignment on nested child blocks. If so, I was wondering if we might be able to make this rule a little more conditional, to potentially reduce the amount of times we need to output these additional rules?

Update: I think that might have been because my container Group block wasn't also set to full width 🤔. If so, (that it's conditional on state), then maybe that's another potential conditional to use so that we only output these styles when needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should work whenever a block has content width set, whether it's through inherit or setting an explicit content width on the block. Theoretically it's already being output only when needed, because blocks without content width won't even go through this layout logic. We shouldn't need them to be full width either, but I'll re-test tomorrow to see if I missed anything!

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're right, this bit will always run even if the block has no content width. Makes sense to put in a condition then.

@@ -101,6 +105,17 @@ export default {
'Customize the width for all elements that are assigned to the center or wide columns.'
) }
</p>

<ToggleControl
label={ __( 'Use global padding' ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the toggle for this one be displayed conditionally? (E.g. if there is no global padding, do we disable the option to opt-in to using it?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooooh good point, I'll look into it!

Copy link
Contributor

@andrewserong andrewserong Jul 7, 2022

Choose a reason for hiding this comment

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

Oh, just having a second look at this one, I suppose the conditional needs to be that the root variables exist (or useRootVariables is true) and that the value is non-zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is going to be tricky. We should be able to get useRootVariables from the block editor settings, but I'm not sure how to access the actual value of the padding from here. Root padding value is set on the root element, which behaves as if it were any other block for most purposes. I'm not sure we'd want to get the value from editor-styles-wrapper with a DOM query 😅 but I can't think of any better way to do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we'd want to get the value from editor-styles-wrapper with a DOM query 😅 but I can't think of any better way to do it.

In that case, maybe it isn't worth the trouble to check the padding value directly. Perhaps it's enough that if a theme is opting in to useRootVariables, we can assume that they're most likely going to use a non-zero value (🤞)! 🙂

@tellthemachines
Copy link
Contributor Author

Thanks for the review @andrewserong !

My understanding is that the idea of that toggle, is that if the theme has global padding set, that it then applies that padding to the current group block?

Yup, that's the idea. For it to work, we have to set "useRootVariables": true in the settings section in the theme's theme.json. Optionally, we can also set a root padding value in styles > spacing > padding in the same theme.json file, but if we don't, setting it in the global styles interface (under Layout > Dimensions) should also work!

Possibly unrelated to this PR, but I also found it tricky to work out when I could or couldn't have children of the Group block be set to full width. It looks like the container Group block needs to be set to Full width, in order for children to be able to be set to Full width?

This is a very good question; it took me a while to work it out too 😅

So for children of a block (Group or any other that has layout capabilities) to display the full width control, the parent block has to have a content width set. So, either it inherits the theme content width, or it has a custom width set in the sidebar under "Layout". If we want the child block to stretch to full viewport width (as opposed to just the full width of its parent block), then the parent block also has to be set to full width (as well as any other blocks with content width it may be nested inside!)

It doesn't feel super intuitive, but the idea is that if a container block doesn't have a content width set, its children naturally take up its full width, so there's no need for explicit full width controls. And full width is considered to be the full width of the container block, which may not always be full viewport width.

@jameskoster
Copy link
Contributor

Forgive my ignorance, but why don't we just add the padding control, and let design tokens do the heavy lifting?

IE if my 'global padding' is set to 'medium', I just apply that same value to whatever block I'm working with.

@tellthemachines
Copy link
Contributor Author

@jameskoster we want to avoid having to set the same padding manually on all the blocks we'd likely want to use it on - which in most cases would be all blocks that extend full width of the viewport, and contain other blocks within them.

There's an extensive discussion regarding how root padding should behave in #35607, if you would like to know more!

@andrewserong andrewserong force-pushed the try/setting-layout-class-names-in-theme-json-for-blockgap-support-at-block-level branch from e33cc4e to 0438461 Compare July 6, 2022 03:18
@andrewserong
Copy link
Contributor

Thanks for the extra info @tellthemachines!

For it to work, we have to set "useRootVariables": true in the settings section in the theme's theme.json. Optionally, we can also set a root padding value in styles > spacing > padding in the same theme.json file, but if we don't, setting it in the global styles interface (under Layout > Dimensions) should also work!

Ah, I can see now that with the Use global padding flag set to true, the has-global-padding class gets added to the Group block's wrapper 👍. For some reason on my test site, the styling rules attached to has-global-padding don't appear to be output for me, so I'm not seeing any styling change in the editor or on the front end of the site. The root variables are being output with the correct value, it just seems to be the .has-global-padding rule that's missing 🤔

Now that I'm having a play with it again, and following on from James mentioning design tokens, there's an interesting feature that @glendaviesnz landed in #41990 which extended the style engine to support the spacing presets CSS variables. I wondered if another option for storing the desired padding value could be to use the root padding CSS variable in the style.spacing.padding attribute (with the var: form), instead of storing the useGlobalPadding boolean in the layout object? We could then potentially have the global padding value be one of many spacing options a user can select from within the Dimensions > Padding section of the inspector panel, so that all padding controls are grouped into the one area, rather than exposing it separately in the Layout panel? That said, it looks like the design idea for the padding spacing size presets is to use a slider (#39371 (comment)), so not sure how well that would work in practice. Just a thought!

Happy to do more detailed testing once this has been rebased — thanks again for your patience with all the changes in the other Layout PR! 🙇

@tellthemachines tellthemachines force-pushed the try/another-root-padding branch from afbe6af to 3b2ee09 Compare July 6, 2022 05:49
@andrewserong
Copy link
Contributor

the styling rules attached to has-global-padding don't appear to be output for me, so I'm not seeing any styling change in the editor or on the front end of the site.

After re-checking out this branch after the rebase, and working through the testing steps again, this is working for me now! I'm 99% sure I must have just missed a step in my earlier testing. 🙂

@tellthemachines
Copy link
Contributor Author

After re-checking out this branch after the rebase, and working through the testing steps again, this is working for me now! I'm 99% sure I must have just missed a step in my earlier testing.

Thanks, good to know! I was wondering what might have gone wrong 😅

I wondered if another option for storing the desired padding value could be to use the root padding CSS variable in the style.spacing.padding attribute (with the var: form), instead of storing the useGlobalPadding boolean in the layout object? We could then potentially have the global padding value be one of many spacing options a user can select from within the Dimensions > Padding section of the inspector panel, so that all padding controls are grouped into the one area, rather than exposing it separately in the Layout panel

Hmm, would be good to have some design input on that! From the user perspective, it would probably make more sense to have the padding controls together, but on the other hand root padding only exists for blocks with flow layout, so will it be confusing if it only appears for some of the blocks with padding controls? I don't think there are any core blocks with layout that don't have padding, but it's always possible third party blocks might exist, so we also have to think about what that might look like.

(Or should Dimensions and Layout be grouped as a single section? In my mind at least spacing is hard to separate from layout.)

From a dev perspective, because the root padding logic is so tied with layout, it's certainly cleaner to have the setting in the layout object. But I'm sure we can find workarounds if it's for the sake of better UX 😄

there's an interesting feature that @glendaviesnz landed in #41990 which extended the style engine to support the spacing presets CSS variables

Thanks for pointing me towards that PR, I'll have a look at it!

@jameskoster
Copy link
Contributor

we want to avoid having to set the same padding manually on all the blocks we'd likely want to use it on - which in most cases would be all blocks that extend full width of the viewport, and contain other blocks within them.

So what would happen if I toggle "Use global padding" on, then set a different value in the dedicated Padding control? How do those options interact?

@tellthemachines
Copy link
Contributor Author

So what would happen if I toggle "Use global padding" on, then set a different value in the dedicated Padding control? How do those options interact?

The custom padding control overrides the root padding value. If you then remove custom padding, root padding will apply again.

It's worth pointing out that root padding is only applied on the left and right sides of the block, because its main aim is to provide a consistent distance from the edges of the viewport for blocks that go full width. Top and bottom root padding values are only applied to the root container, or body element.

The other thing worth taking into account is that a root padding value can be set by the theme, and overridden in the global styles panel by the user, or it can be set in global styles if the theme doesn't provide it, but the behaviour implemented in this PR, where root padding can be applied to nested containers, has to be enabled at the theme level. This was considered necessary for back compat, so that behaviour doesn't change for existing themes, otherwise I think it would make more sense to have it enabled by default.

@Gierand
Copy link

Gierand commented Aug 3, 2022

Please check #42913

@jasmussen
Copy link
Contributor

jasmussen commented Sep 7, 2022

I've found a potential issue with the padding visualizer and useRootPaddingAwareAlignments while tinkering with TT3, and I'd love your insights into what that might be. It's quite curious and I'm not sure whether the cause is TT3 or the padding visualizer component, but visualizer is exactly 60px offset when using root padding aware alignments, as shown in this GIF:

without 60px

If I remove useRootPaddingAwareAlignments, or add the following hack to the stylesheet, the problem disappears:

.block-editor__padding-visualizer {
	margin-top: -60px !important;
}

as shown in this GIF:

60px applied

The curious part here is, it's always 60px and it's only when useRootPaddingAwareAlignments is leveraged. So it seems like there's some math positioning the popover somewhere that's contextually wrong. Any insights?

Edit: this issue furthermore appears to be site editor only! And since the top header is exactly 60px tall, one might assume the issue could be with the positioning assuming the header is to be compensated for, even if it sits inside the site editors iframe which negates it. The curious thing is that this math is correct in the site editor, if useRootPaddingAwareAlignments is not present in theme.json.

pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Sep 14, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.


git-svn-id: https://develop.svn.wordpress.org/trunk@54159 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Sep 14, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54159


git-svn-id: http://core.svn.wordpress.org/trunk@53718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to gilzow/wordpress-performance that referenced this pull request Sep 14, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54159


git-svn-id: https://core.svn.wordpress.org/trunk@53718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
whereiscodedude pushed a commit to whereiscodedude/wpss that referenced this pull request Sep 18, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.

Built from https://develop.svn.wordpress.org/trunk@54159
@tellthemachines tellthemachines mentioned this pull request Sep 21, 2022
89 tasks
@bph bph added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Sep 22, 2022
@femkreations femkreations removed the Needs User Documentation Needs new user documentation label Sep 25, 2022
ootwch pushed a commit to ootwch/wordpress-develop that referenced this pull request Nov 4, 2022
This change backports the following changes from Gutenberg repository:

- [WordPress/gutenberg#40875 gutenberg#40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42087 gutenberg#42087] Theme.json: Add block support feature level selectors for blocks gutenberg#42087
- [WordPress/gutenberg#43792 gutenberg#43792] Global Styles: Split root layout rules into a different function gutenberg#43792
- [WordPress/gutenberg#42544 gutenberg#42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg#42544
- [WordPress/gutenberg#42665 gutenberg#42665] Layout: Reduce specificity of fallback blockGap styles gutenberg#42665
- [WordPress/gutenberg#42085 gutenberg#42085] Core CSS support for root padding and alignfull blocks gutenberg#42085

Note that it doesn't entirely port over PR40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`.

Props andrewserong, aaronrobertshaw, isabel_brison.
See #56467.


git-svn-id: https://develop.svn.wordpress.org/trunk@54159 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider a root-level site padding solution that still lets some items go full-width
9 participants