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

Alternative approach to the layout outer padding #36214

Closed
wants to merge 6 commits into from

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Nov 4, 2021

Alternative to #35919

Instead of using a dedicated outerPadding property on the layout object. This PR uses padding, so for instance if a user sets a padding to a group block and also add the same time defines content/wide widths, the padding applied to the block is used to compute the negative margins.

That said, when the layout is defined as "inherit: true", the padding control in the container block is hidden and the "padding" defined in the theme.json file (settings.layout.padding) is used instead.

What do you think? It feels a bit better than #35919 because there's no padding conflicts in the UI.

Cons:

  • If a user defines a padding on a group block and then after that triggers the "inherit layout" checkbox, the initially defined padding is going to be ignored ant the control hidden but in order for the styles to apply correctly the padding applied using the layout code has !important
  • The other con is that padding and layout are kind of interconnected with this PR.

@youknowriad youknowriad added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label Nov 4, 2021
@youknowriad youknowriad self-assigned this Nov 4, 2021
@kjellr
Copy link
Contributor

kjellr commented Nov 4, 2021

@youknowriad: @jffng and I are both getting editor errors when we try this PR:

Screen Shot 2021-11-04 at 11 07 47 AM

Error:

save@https://gutenberg.test/wp-content/plugins/gutenberg/build/block-editor/index.min.js?ver=876a1b8ffced55f15985649073f17ad5:3:17985
renderWithHooks@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:15015:29
updateFunctionComponent@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:17386:37
callCallback@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:3942:21
dispatchEvent@[native code]
invokeGuardedCallbackDev@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:3991:31
invokeGuardedCallback@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:4053:38
beginWork$1@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:23994:30
performUnitOfWork@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:22809:25
workLoopSync@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:22737:24
renderRootSync@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:22700:21
performSyncWorkOnRoot@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:22323:34
performSyncWorkOnRoot@[native code]
@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:11357:36
unstable_runWithPriority@https://unpkg.com/react@17.0.1/umd/react.development.js:2942:26
flushSyncCallbackQueueImpl@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:11352:28
flushSyncCallbackQueue@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:11339:31
scheduleUpdateOnFiber@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:21923:33
dispatchAction@https://unpkg.com/react-dom@17.0.1/umd/react-dom.development.js:16169:28
dispatchAction@[native code]
@https://gutenberg.test/wp-content/plugins/gutenberg/build/block-editor/index.min.js?ver=876a1b8ffced55f15985649073f17ad5:52:11374

@youknowriad
Copy link
Contributor Author

yep, should be fixed now. The padding defined in the layout should be something like: "padding": { "left": "var(--wp--custom--spacing--small, 1.25rem)", "right": "var(--wp--custom--spacing--small, 1.25rem)" }

@youknowriad youknowriad force-pushed the update/alternative-approach-outer-padding branch from abc42c4 to bb569ee Compare November 4, 2021 15:20
@github-actions
Copy link

github-actions bot commented Nov 4, 2021

Size Change: +222 B (0%)

Total Size: 1.11 MB

Filename Size Change
build/block-editor/index.min.js 140 kB +201 B (0%)
build/block-library/blocks/cover/style-rtl.css 1.22 kB -2 B (0%)
build/block-library/blocks/cover/style.css 1.22 kB -2 B (0%)
build/block-library/style-rtl.css 10.7 kB -2 B (0%)
build/block-library/style.css 10.7 kB -2 B (0%)
build/edit-post/index.min.js 29.6 kB +29 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 960 B
build/admin-manifest/index.min.js 1.1 kB
build/annotations/index.min.js 2.75 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.12 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.28 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/style-rtl.css 14.4 kB
build/block-editor/style.css 14.4 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 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/buttons/editor-rtl.css 291 B
build/block-library/blocks/buttons/editor.css 291 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 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 134 B
build/block-library/blocks/code/theme.css 134 B
build/block-library/blocks/columns/editor-rtl.css 210 B
build/block-library/blocks/columns/editor.css 208 B
build/block-library/blocks/columns/style-rtl.css 503 B
build/block-library/blocks/columns/style.css 502 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/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
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 966 B
build/block-library/blocks/gallery/editor.css 970 B
build/block-library/blocks/gallery/style-rtl.css 1.63 kB
build/block-library/blocks/gallery/style.css 1.62 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/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 507 B
build/block-library/blocks/image/style.css 511 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 649 B
build/block-library/blocks/navigation-link/editor.css 650 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/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.89 kB
build/block-library/blocks/navigation/editor.css 1.89 kB
build/block-library/blocks/navigation/style-rtl.css 1.68 kB
build/block-library/blocks/navigation/style.css 1.67 kB
build/block-library/blocks/navigation/view.min.js 2.79 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 172 B
build/block-library/blocks/page-list/style.css 172 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 444 B
build/block-library/blocks/post-comments-form/style.css 444 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-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 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 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 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 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 273 B
build/block-library/blocks/query-pagination/style.css 269 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/style-rtl.css 245 B
build/block-library/blocks/separator/style.css 245 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 772 B
build/block-library/blocks/site-logo/editor.css 772 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 670 B
build/block-library/blocks/social-links/editor.css 669 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 569 B
build/block-library/blocks/video/editor.css 570 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 857 B
build/block-library/common.css 856 B
build/block-library/editor-rtl.css 9.92 kB
build/block-library/editor.css 9.91 kB
build/block-library/index.min.js 162 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/theme-rtl.css 672 B
build/block-library/theme.css 677 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.3 kB
build/components/index.min.js 214 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/core-data/index.min.js 13.2 kB
build/customize-widgets/index.min.js 11.4 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 631 B
build/data/index.min.js 7.47 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 485 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.5 kB
build/edit-navigation/index.min.js 16 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/style-rtl.css 7.1 kB
build/edit-post/style.css 7.09 kB
build/edit-site/index.min.js 34.2 kB
build/edit-site/style-rtl.css 6.58 kB
build/edit-site/style.css 6.58 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.18 kB
build/edit-widgets/style.css 4.18 kB
build/editor/index.min.js 37.8 kB
build/editor/style-rtl.css 3.78 kB
build/editor/style.css 3.77 kB
build/element/index.min.js 3.29 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.57 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.63 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.71 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.8 kB
build/keycodes/index.min.js 1.39 kB
build/list-reusable-blocks/index.min.js 1.72 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 925 B
build/nux/index.min.js 2.08 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.84 kB
build/primitives/index.min.js 924 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.65 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/rich-text/index.min.js 11 kB
build/server-side-render/index.min.js 1.57 kB
build/shortcode/index.min.js 1.49 kB
build/token-list/index.min.js 639 B
build/url/index.min.js 1.9 kB
build/viewport/index.min.js 1.05 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.15 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

@kjellr
Copy link
Contributor

kjellr commented Nov 4, 2021

Alright thanks — I can access the editor again. I drafted up a quick PR in WordPress/twentytwentytwo#209 to test this against.

I'm having trouble understanding how to actually make things go full width though. I'm not seeing negative margins applied anywhere? It sounded like I should be able to (for example) put this in the root of my site editor, and have the image go full-width, right?

<!-- wp:group {"layout":{"inherit":true}} -->
<div class="wp-block-group"><!-- wp:image {"align":"full","sizeSlug":"full"} -->
<figure class="wp-block-image alignfull size-full"><img src="https://cldup.com/NCVsLRzaSd.png" alt=""/></figure>
<!-- /wp:image --></div>
<!-- /wp:group -->

EDIT: Nevermind, the suggestion in WordPress/twentytwentytwo#209 (comment) got this working!

@kjellr
Copy link
Contributor

kjellr commented Nov 4, 2021

This works pretty well! The only major hesitation I have is this part:

That said, when the layout is defined as "inherit: true", the padding control in the container block is hidden and the "padding" defined in the theme.json file (settings.layout.padding) is used instead.

Here's a visual representation of this:

Screen Shot 2021-11-04 at 12 03 00 PM

The theme has left/right padding and no top padding, so that's what's applied to the block when inherit layout is true. There's no way to modify that padding at all. I feel like we should be able to still access padding controls, and if we edit those, the negative margins should just shut off automatically. Is that possible?

@youknowriad
Copy link
Contributor Author

The theme has left/right padding and no top padding, so that's what's applied to the block when inherit layout is true. There's no way to modify that padding at all. I feel like we should be able to still access padding controls, and if we edit those, the negative margins should just shut off automatically. Is that possible?

I'l reluctant because this is not how it works with the layout styles (widths). When you inherit, you ignore values defined in the block itself. So if we change it for padding, I wonder if we should be consistent.

So: if block specific value is defined use it, otherwise use the inherited value. Also, the question here is do you think we should prefill the padding control with the layout inherited value? Also, how do you clear the value? Right now clearing a value means making it undefined which would revert to the inherited value, it could become confusing.

@kjellr
Copy link
Contributor

kjellr commented Nov 5, 2021

Yeah, that makes sense. This is a complicated problem. 😅

I'm thinking that we're probably not ready to merge this for the feature freeze — it doesn't feel quite ready. Since it's really just an iteration on existing functionality we can probably keep thinking through it through Beta anyway? I'm not sure.

@youknowriad
Copy link
Contributor Author

I agree that there's no need to rush it 👍 .

@richtabor
Copy link
Member

I feel like we should be able to still access padding controls, and if we edit those, the negative margins should just shut off automatically. Is that possible?

Whew, this is a complicated one. So you're thinking that if the padding control is modified, then the negative margins wouldn't work any longer?

Other question, this doesn't solve the fullwidth/negative margins for any other alignfull blocks, correct?

@kjellr
Copy link
Contributor

kjellr commented Nov 8, 2021

So you're thinking that if the padding control is modified, then the negative margins wouldn't work any longer?

That's right. My general thinking is that if you've added padding to a specific block this way, you're overriding the defaults and choosing to have that padding surround every interior block. That generally works for my mental model, but I'm not sure how universal it is. Like you said, this is a complicated issue!

Other question, this doesn't solve the fullwidth/negative margins for any other alignfull blocks, correct?

The PR currently works for any alignfull block whose direct parent inherits the default layout.

@kjellr
Copy link
Contributor

kjellr commented Nov 23, 2021

Here's an example of where I found the automatically-added padding confusing: In the post/page editor, I have a Group block that's wide-aligned. I've activated "Inherit default layout" because I'd like this block to contain one wide-width block, and one standard-width text block. Here's how that looks today:

Screen Shot 2021-11-23 at 7 54 50 AM

This is as I'd expect it to be. The Group block parent takes up the full "wide" width of the page, and so does the wide-width child. The standard-aligned block is smaller than that. The site padding exists, but it's on the left and right of the entire block (as expected).

But with this PR active, the Group block parent gets extra padding, so it displays like this:

Screen Shot 2021-11-23 at 7 48 14 AM

There's no need to double-up on the padding here. The "site padding" is already present outside of this block. And there's no way for me to remove it currently.

@youknowriad
Copy link
Contributor Author

There's no need to double-up on the padding here. The "site padding" is already present outside of this block. And there's no way for me to remove it currently.

For me the issue here is that you should have never used "inherit layout" on that group block, instead you should have defined a custom layout (custom widths), the reason is simple: the page canvas is full width, meaning a layout that is suitable there (the default layout) is not something you should apply to a "wide" block because it breaks there (regardless of padding).

Example: the theme defines: 1000px/800px as widths for the default layout, it doesn't really make sense to use the same layout for a block that is maximum 1000px for me (wide group), because a wide and full width will have similar behavior there.

In other words for me: inherit layout only makes sense for blocks who's width is the full window size. these can be nested or top level (which makes this rule hard to enforce) but applying "inherit" is not suitable in any other situation for me.

@kjellr
Copy link
Contributor

kjellr commented Nov 23, 2021

In other words for me: inherit layout only makes sense for blocks who's width is the full window size. these can be nested or top level (which makes this rule hard to enforce) but applying "inherit" is not suitable in any other situation for me.

What's the benefit to us having this control available on blocks that are not full-width then? Can/should we filter that out? The majority of blocks the user sees these controls on do not fit that criteria.

@youknowriad
Copy link
Contributor Author

@kjellr Think of it as a preset for theme authors, so they don't have to redefine the same layout over and over across blocks and templates.

I'd love to find a way to hide it in the situations where it makes less sense but it's very hard to know statically. For instance it makes sense in a query loop inside a group inside a group inside a group inside a template part if the top level is full width.

@youknowriad youknowriad force-pushed the update/alternative-approach-outer-padding branch from 8f1048b to d241ae2 Compare December 6, 2021 07:45
@kjellr
Copy link
Contributor

kjellr commented Dec 8, 2021

Where are we at with this one? I think it's probably close, but I still think having the option to clear these paddings for child blocks is important. If that's something we'd consider trying to add, do we need Design to help figure out answers for these questions?

Also, the question here is do you think we should prefill the padding control with the layout inherited value? Also, how do you clear the value? Right now clearing a value means making it undefined which would revert to the inherited value, it could become confusing.

@youknowriad
Copy link
Contributor Author

I'm personally not confident about showing the padding control or allowing overriding the "default inherited one" because it creates a precedent without how the inherited layout properties work.

  • Why not keep the wide/full widths either?
  • Why not prefill these with the values from theme.json?
  • Why don't we prefill the values for other styles either, think all of the fontsizes, colors... where the default values are defined in theme.json

I don't think it's something to be done specifically for this PR but more something to be thought of holistically and not something we can do properly for 5.9.

@youknowriad
Copy link
Contributor Author

I'm personally happy to ship this as is if folks thinks it's a decent compromise. I can't think of a better one for now that won't have bigger impacts.

@kjellr
Copy link
Contributor

kjellr commented Dec 13, 2021

I'm still pretty uncomfortable with because it takes an already complex control (Layout) and adds additional complicated behavior to it. Here are a few of my concerns:


  1. In general, it's very confusing for a user to lose all their custom paddings when they flip the layout toggle:

spacings

We could adjust the label to say "Inherit default layout and padding", but the layout control is already pretty opaque to the user (cc #36675), and I'm not sure if that helps or adds complexity.


  1. In general, I think there's a conceptual difference between the "site" padding and the padding that I'd want to add to individual layout-enabled blocks on the site. It's quite likely that many themes will want to have their top padding set to 0 to allow header images/colors to reach the top of the screen. But I don't think the same applies to layout-enabled blocks elsewhere in the site. They're totally different contexts.

  1. In practice, this PR makes a common layout like this Twenty Twenty-Two pattern more difficult to achieve:

Screen Shot 2021-12-13 at 1 34 48 PM

This content in the middle of this block is wide-aligned, and sits inside of a full-width gray Group block. The padding on all four sides is defined on the parent Group block. It's generally pretty easy to create.

With this PR though, this pattern looks like this by default:

Screen Shot 2021-12-13 at 1 36 06 PM

I can't override that 0 top padding on the Group block since I can't override padding for a block that needs default/wide-width children. Instead, I have to create another group block to house the children, and add top/bottom margin to that:

layout

Most users won't figure out how to make that happen — it's far less intuitive than just editing the padding for the Gray Group block.

@jasmussen
Copy link
Contributor

It feels worth adding that for TT2 we did discuss whether we couldn't handle the challenge in CSS. It has its own tradeoff, but it could buy some time to figure out a better solution, potentially.

@youknowriad
Copy link
Contributor Author

The CSS solutions that I saw so far will solve some use-cases but create issues for others, I don't believe there's a perfect CSS solution for this.

What makes this hard is that ideally, there shouldn't be any user or theme author interactions, the premise is simple:

Applying a full width alignment to a block should ignore the padding of its container, the reality is that we can't write a CSS rule to achieve that in a generic way.

@kjellr
Copy link
Contributor

kjellr commented Dec 14, 2021

What makes this hard is that ideally, there shouldn't be any user or theme author interactions, the premise is simple:

Applying a full width alignment to a block should ignore the padding of its container, the reality is that we can't write a CSS rule to achieve that in a generic way.

That's a good summary! This is truly difficult. 😅

At the moment, I'm primarily trying to consider the best-case scenario for 5.9... Since we don't have a solution we all feel solid about, I think anything we land at this stage needs to be relatively minimal and mostly harmless: Something automatic, that can be stripped out and replaced if need be. It would be good to get something into today's Beta, since it's the last (confirmed) beta before the holidays.

I lean towards the fix in WordPress/twentytwentytwo#291 because it mostly works, and is just a handful of CSS rules. I think the main thing going for it is is that it's replaceable without setting precedent, and it buys us a bit more time. For now, I think we should just try putting that in and seeing how it tests during the next beta cycle.

@youknowriad
Copy link
Contributor Author

I lean towards the fix in WordPress/twentytwentytwo#291 because it mostly works, and is just a handful of CSS rules. I think the main thing going for it is is that it's replaceable without setting precedent, and it buys us a bit more time. For now, I think we should just try putting that in and seeing how it tests during the next beta cycle.

I can be onboard with that but let's keep it to the real CSS minimum override and also add a clarifying comment that block themes shouldn't rely on it too much as it might break or become unnecessary in the future. Themes will consider 2022 as the theme to copy for everything.

@kjellr
Copy link
Contributor

kjellr commented Dec 14, 2021

I can be onboard with that but let's keep it to the real CSS minimum override and also add a clarifying comment that block themes shouldn't rely on it too much as it might break or become unnecessary in the future. Themes will consider 2022 as the theme to copy for everything.

Fully agreed. 👍

@MaggieCabrera
Copy link
Contributor

Themes will consider 2022 as the theme to copy for everything.

That's why it's important that the fix is in the editor, so future themes don't include these extra rules that will potentially be obsolete in the near future in favor of a better solution. I think the TT2 styles on WordPress/twentytwentytwo#291 with the variable for controlling the padding amount via theme.json should be a good starting point to make it opt-in.

@glendaviesnz
Copy link
Contributor

FYI - the number of changes in layout, etc. made a rebase a bit messy, so have cherry-picked the changes onto a fresh branch off trunk over here so we can do some more exploration with this.

@youknowriad
Copy link
Contributor Author

Interesting @glendaviesnz I'm closing this now

@youknowriad youknowriad deleted the update/alternative-approach-outer-padding branch March 30, 2022 06:31
tellthemachines pushed a commit that referenced this pull request Apr 8, 2022
ramonjd pushed a commit that referenced this pull request May 25, 2022
scruffian pushed a commit that referenced this pull request May 25, 2022
scruffian pushed a commit that referenced this pull request Jun 30, 2022
scruffian pushed a commit that referenced this pull request Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants