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

Dimensions: Add Aspect Ratio block support #56897

Merged
merged 14 commits into from Jan 24, 2024

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Dec 8, 2023

What?

Fixes: #54032

This PR explores adding aspect ratio to the Cover and Group blocks by including it as part of the dimensions block supports.

It supports aspect ratio at the individual block level, and within global styles. Note that the override for the Cover block that switches off its min-height value only works at the individual block level, and not in global styles.

Why?

We currently only have minHeight controls, which doesn't allow for easily creating particular proportions. It'd be helpful for many different kinds of site designs to be able to set container blocks like Cover and Group to a particular aspect ratio.

How it works (and potential limitations)

This PR tries to let the CSS aspect-ratio work the way that it works, with minimal interference. To achieve this, and to avoid overflow issues, when an aspect-ratio is set, we unset any value for min-height. Similarly, if a min-height is set at the block level, we output an aspect-ratio: unset rule to override any aspect ratio set in global styles. These unset rules should only be output for blocks that opt-in to aspect ratio, and are not saved to post content.

For folks wanting to reduce the width of their container to less than the full width of the container, a good way to do it is to wrap the block in a Row block, and use the child width controls, as the flex-basis rules for fixed width appear to play nicely here.

How?

  • Add aspectRatio to dimensions block support
  • Opt the Cover block into that support (note: Group block support was removed in Aspect ratio: remove support on the Group block for now #58414)
  • Add a min-height: unset rule that gets applied when aspect ratio is in use — this is necessary because setting a min-height interferes with aspect-ratio behaviour by not allowing content to expand the area of a block beyond the defined aspect ratio. In order to ensure that longer content flows correctly in narrower viewports, we unset min-height when aspect ratio it applied.
  • This PR also uses server-rendering instead of saving the aspect-ratio rule into post content. This is because the aspect ratio rule depends on other CSS values, so it's safer if we don't serialize the value for now. This also allows us to explore other options in the future for output, like using has-4-3-aspect-ratio classnames that apply the aspect ratio instead of inline styles. And finally, it allows us to add aspect-ratio and unset rules without having to deprecate any legacy markup.
  • Update global styles output to also output a min-height: unset rule when outputting aspect-ratio — this is a little hacky, but ensures that rules like the Cover block's default min-height don't interfere with the aspect ratio.
  • Note: for now, the Group block's aspect ratio controls are disabled in global styles, to prevent users from unexpectedly setting aspect ratio for all of the group block's variations

Testing Instructions

  1. Add Cover and Group blocks to a post or page.
  2. Set background images and colors on the blocks.
  3. Try selecting from a range of aspect ratios under the Dimensions panel.
  4. Try playing around with adding minHeight, too — notice that minHeight will clear out any aspect ratio applied.
  5. To reduce the overall size of the block, try wrapping in a Row block, and use the Fixed width controls to reduce the size of the block.
  6. Also, try playing around with aspect ratio at the block level in global styles.

In testing, how do these controls feel to use? Is it close enough to desired behaviour to be useful, or does it feel limiting? Try adding a variety of content within the Group and Cover blocks to get a feel for it, too.

Screenshots or screencast

2023-12-12.12.18.34.mp4

@andrewserong andrewserong added [Block] Cover Affects the Cover Block - used to display content laid over a background image [Block] Group Affects the Group Block [Type] Experimental Experimental feature or API. [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Dec 8, 2023
@andrewserong andrewserong self-assigned this Dec 8, 2023
Copy link

github-actions bot commented Dec 8, 2023

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/block-supports/dimensions.php
❔ lib/class-wp-theme-json-gutenberg.php

Copy link

github-actions bot commented Dec 8, 2023

Size Change: +539 B (0%)

Total Size: 1.7 MB

Filename Size Change
build/block-editor/index.min.js 249 kB +404 B (0%)
build/block-library/blocks/cover/style-rtl.css 1.7 kB -4 B (0%)
build/block-library/blocks/cover/style.css 1.69 kB -5 B (0%)
build/block-library/index.min.js 215 kB +79 B (0%)
build/block-library/style-rtl.css 14.7 kB -3 B (0%)
build/block-library/style.css 14.7 kB +1 B (0%)
build/blocks/index.min.js 51.6 kB +19 B (0%)
build/edit-site/index.min.js 197 kB +31 B (0%)
build/style-engine/index.min.js 2.07 kB +17 B (+1%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 964 B
build/annotations/index.min.js 2.71 kB
build/api-fetch/index.min.js 2.33 kB
build/autop/index.min.js 2.11 kB
build/blob/index.min.js 590 B
build/block-directory/index.min.js 7.25 kB
build/block-directory/style-rtl.css 1.04 kB
build/block-directory/style.css 1.04 kB
build/block-editor/content-rtl.css 4.42 kB
build/block-editor/content.css 4.42 kB
build/block-editor/default-editor-styles-rtl.css 403 B
build/block-editor/default-editor-styles.css 403 B
build/block-editor/style-rtl.css 15.4 kB
build/block-editor/style.css 15.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 90 B
build/block-library/blocks/archives/style.css 90 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 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 138 B
build/block-library/blocks/audio/theme.css 138 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 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 419 B
build/block-library/blocks/button/editor.css 417 B
build/block-library/blocks/button/style-rtl.css 632 B
build/block-library/blocks/button/style.css 631 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 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 421 B
build/block-library/blocks/columns/style.css 421 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 199 B
build/block-library/blocks/comment-template/style.css 198 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 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 98 B
build/block-library/blocks/details/style.css 98 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 138 B
build/block-library/blocks/embed/theme.css 138 B
build/block-library/blocks/file/editor-rtl.css 316 B
build/block-library/blocks/file/editor.css 316 B
build/block-library/blocks/file/style-rtl.css 280 B
build/block-library/blocks/file/style.css 281 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/form-input/editor-rtl.css 229 B
build/block-library/blocks/form-input/editor.css 228 B
build/block-library/blocks/form-input/style-rtl.css 343 B
build/block-library/blocks/form-input/style.css 343 B
build/block-library/blocks/form-submission-notification/editor-rtl.css 343 B
build/block-library/blocks/form-submission-notification/editor.css 342 B
build/block-library/blocks/form-submit-button/style-rtl.css 69 B
build/block-library/blocks/form-submit-button/style.css 69 B
build/block-library/blocks/form/view.min.js 452 B
build/block-library/blocks/freeform/editor-rtl.css 2.61 kB
build/block-library/blocks/freeform/editor.css 2.61 kB
build/block-library/blocks/gallery/editor-rtl.css 957 B
build/block-library/blocks/gallery/editor.css 962 B
build/block-library/blocks/gallery/style-rtl.css 1.75 kB
build/block-library/blocks/gallery/style.css 1.75 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 654 B
build/block-library/blocks/group/editor.css 654 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 189 B
build/block-library/blocks/heading/style.css 189 B
build/block-library/blocks/html/editor-rtl.css 340 B
build/block-library/blocks/html/editor.css 341 B
build/block-library/blocks/image/editor-rtl.css 834 B
build/block-library/blocks/image/editor.css 833 B
build/block-library/blocks/image/style-rtl.css 1.61 kB
build/block-library/blocks/image/style.css 1.6 kB
build/block-library/blocks/image/theme-rtl.css 137 B
build/block-library/blocks/image/theme.css 137 B
build/block-library/blocks/image/view.min.js 2.02 kB
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 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 505 B
build/block-library/blocks/media-text/style.css 503 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 671 B
build/block-library/blocks/navigation-link/editor.css 672 B
build/block-library/blocks/navigation-link/style-rtl.css 103 B
build/block-library/blocks/navigation-link/style.css 103 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/editor-rtl.css 2.26 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.25 kB
build/block-library/blocks/navigation/style.css 2.23 kB
build/block-library/blocks/navigation/view.min.js 1.1 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 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 235 B
build/block-library/blocks/paragraph/editor.css 235 B
build/block-library/blocks/paragraph/style-rtl.css 335 B
build/block-library/blocks/paragraph/style.css 335 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 508 B
build/block-library/blocks/post-comments-form/style.css 508 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 666 B
build/block-library/blocks/post-featured-image/editor.css 662 B
build/block-library/blocks/post-featured-image/style-rtl.css 345 B
build/block-library/blocks/post-featured-image/style.css 345 B
build/block-library/blocks/post-navigation-link/style-rtl.css 215 B
build/block-library/blocks/post-navigation-link/style.css 214 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 409 B
build/block-library/blocks/post-template/style.css 408 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 125 B
build/block-library/blocks/preformatted/style.css 125 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 354 B
build/block-library/blocks/pullquote/style.css 354 B
build/block-library/blocks/pullquote/theme-rtl.css 168 B
build/block-library/blocks/pullquote/theme.css 168 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 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 486 B
build/block-library/blocks/query/editor.css 486 B
build/block-library/blocks/query/style-rtl.css 312 B
build/block-library/blocks/query/style.css 308 B
build/block-library/blocks/query/view.min.js 647 B
build/block-library/blocks/quote/style-rtl.css 237 B
build/block-library/blocks/quote/style.css 237 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 140 B
build/block-library/blocks/read-more/style.css 140 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 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 184 B
build/block-library/blocks/search/editor.css 184 B
build/block-library/blocks/search/style-rtl.css 602 B
build/block-library/blocks/search/style.css 602 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/search/view.min.js 475 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 234 B
build/block-library/blocks/separator/style.css 234 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 329 B
build/block-library/blocks/shortcode/editor.css 329 B
build/block-library/blocks/site-logo/editor-rtl.css 760 B
build/block-library/blocks/site-logo/editor.css 760 B
build/block-library/blocks/site-logo/style-rtl.css 204 B
build/block-library/blocks/site-logo/style.css 204 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 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 682 B
build/block-library/blocks/social-links/editor.css 681 B
build/block-library/blocks/social-links/style-rtl.css 1.49 kB
build/block-library/blocks/social-links/style.css 1.49 kB
build/block-library/blocks/spacer/editor-rtl.css 359 B
build/block-library/blocks/spacer/editor.css 359 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 395 B
build/block-library/blocks/table/editor.css 395 B
build/block-library/blocks/table/style-rtl.css 646 B
build/block-library/blocks/table/style.css 645 B
build/block-library/blocks/table/theme-rtl.css 157 B
build/block-library/blocks/table/theme.css 157 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 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 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 191 B
build/block-library/blocks/video/style.css 191 B
build/block-library/blocks/video/theme-rtl.css 139 B
build/block-library/blocks/video/theme.css 139 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.11 kB
build/block-library/common.css 1.11 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.3 kB
build/block-library/editor.css 12.3 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 472 B
build/block-library/reset.css 472 B
build/block-library/theme-rtl.css 700 B
build/block-library/theme.css 705 B
build/block-serialization-default-parser/index.min.js 1.13 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/commands/index.min.js 15.5 kB
build/commands/style-rtl.css 947 B
build/commands/style.css 942 B
build/components/index.min.js 235 kB
build/components/style-rtl.css 12.1 kB
build/components/style.css 12.1 kB
build/compose/index.min.js 12.6 kB
build/core-commands/index.min.js 2.73 kB
build/core-data/index.min.js 72.7 kB
build/customize-widgets/index.min.js 12.1 kB
build/customize-widgets/style-rtl.css 1.36 kB
build/customize-widgets/style.css 1.36 kB
build/data-controls/index.min.js 651 B
build/data/index.min.js 8.96 kB
build/date/index.min.js 17.9 kB
build/deprecated/index.min.js 462 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.69 kB
build/edit-post/classic-rtl.css 571 B
build/edit-post/classic.css 571 B
build/edit-post/index.min.js 24.9 kB
build/edit-post/style-rtl.css 5.68 kB
build/edit-post/style.css 5.68 kB
build/edit-site/style-rtl.css 15.3 kB
build/edit-site/style.css 15.3 kB
build/edit-widgets/index.min.js 17.4 kB
build/edit-widgets/style-rtl.css 4.44 kB
build/edit-widgets/style.css 4.43 kB
build/editor/index.min.js 61.7 kB
build/editor/style-rtl.css 5.48 kB
build/editor/style.css 5.48 kB
build/element/index.min.js 4.88 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 7.99 kB
build/format-library/style-rtl.css 500 B
build/format-library/style.css 500 B
build/hooks/index.min.js 1.57 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.61 kB
build/interactivity/file.min.js 442 B
build/interactivity/image.min.js 2.15 kB
build/interactivity/index.min.js 13.3 kB
build/interactivity/navigation.min.js 1.23 kB
build/interactivity/query.min.js 791 B
build/interactivity/search.min.js 610 B
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.76 kB
build/keycodes/index.min.js 1.49 kB
build/list-reusable-blocks/index.min.js 2.11 kB
build/list-reusable-blocks/style-rtl.css 865 B
build/list-reusable-blocks/style.css 865 B
build/media-utils/index.min.js 2.92 kB
build/modules/importmap-polyfill.min.js 12.2 kB
build/notices/index.min.js 964 B
build/nux/index.min.js 2.01 kB
build/nux/style-rtl.css 775 B
build/nux/style.css 771 B
build/patterns/index.min.js 5.43 kB
build/patterns/style-rtl.css 564 B
build/patterns/style.css 564 B
build/plugins/index.min.js 1.81 kB
build/preferences-persistence/index.min.js 2.08 kB
build/preferences/index.min.js 2.82 kB
build/preferences/style-rtl.css 725 B
build/preferences/style.css 728 B
build/primitives/index.min.js 994 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 1.02 kB
build/react-i18n/index.min.js 631 B
build/react-refresh-entry/index.min.js 9.46 kB
build/react-refresh-runtime/index.min.js 6.78 kB
build/redux-routine/index.min.js 2.71 kB
build/reusable-blocks/index.min.js 2.74 kB
build/reusable-blocks/style-rtl.css 265 B
build/reusable-blocks/style.css 265 B
build/rich-text/index.min.js 10.4 kB
build/router/index.min.js 1.79 kB
build/server-side-render/index.min.js 1.96 kB
build/shortcode/index.min.js 1.4 kB
build/token-list/index.min.js 587 B
build/url/index.min.js 3.83 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 967 B
build/warning/index.min.js 259 B
build/widgets/index.min.js 7.22 kB
build/widgets/style-rtl.css 1.18 kB
build/widgets/style.css 1.18 kB
build/wordcount/index.min.js 1.03 kB

compressed-size-action

Copy link

github-actions bot commented Dec 8, 2023

Flaky tests detected in 2c9107d.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7579532565
📝 Reported issues:

@andrewserong andrewserong force-pushed the try/dimensions-aspect-ratio-block-support branch from 2525ba0 to bf39d96 Compare December 11, 2023 06:01
@andrewserong
Copy link
Contributor Author

Note to self: for some reason the has-aspect-ratio classname only appears to be output when other things like border color is set... weirdly it doesn't appear to be enough for it to update the classname in the editor on its own. I'll dig into this further.

Also, I had to add a width: 100% rule for the aspect ratio to not break out of its container, and for it to respect flex basis rules. I'll do some more testing on that, too.

Comment on lines 56 to 67
// May be set to undefined, so check if the property is set!
if (
propsA?.hasOwnProperty( 'className' ) &&
propsB?.hasOwnProperty( 'className' )
) {
newProps.className = classnames( propsA.className, propsB.className );
}
if ( propsA?.style && propsB?.style ) {

if (
propsA?.hasOwnProperty( 'style' ) &&
propsB?.hasOwnProperty( 'style' )
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This merges in a fix that will land in #56912 to ensure classnames are output correctly. Just including it here for now so that this PR will work properly in manual testing 🙂

Comment on lines 25 to 27
&:where(.has-aspect-ratio) {
width: 100%;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll likely need to put this rule somewhere else as I think we'll always want this applied when .has-aspect-ratio is active.


if ( ! empty( $styles['classnames'] ) ) {
foreach ( explode( ' ', $styles['classnames'] ) as $class_name ) {
$tags->add_class( $class_name );
Copy link
Member

@ramonjd ramonjd Dec 12, 2023

Choose a reason for hiding this comment

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

Mainly interested... so $tags->add_class( 'a-class b-class' ) should work too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment I'm calling explode so that we add them one-by-one... I looked up the add_class method and it does look like we should be able to call it with a full classname string that contains multiple classes, I just wasn't sure if it's guaranteed to 🤔. Happy to switch it over to the simpler add_class with the full single string, though 🙂

Thanks for giving this PR an early look! 🙇

Copy link
Member

Choose a reason for hiding this comment

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

I gave it a try and it works 😄 No biggie, I was just wondering.
Screenshot 2023-12-12 at 4 43 30 pm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice one! I can switch it over 😀

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah if it's not explicitly indicated in the docs it might not be officially supported even though it currently works. We were using similar logic to fetch a bunch of classes from an element in one go in the layout support, but this change broke that ability. The refactor of layout in #54075 to fix that has more info.

Copy link
Member

Choose a reason for hiding this comment

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

Agree - might be a nice feature though to have an add_classes method that accepts an array or something.

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 folks, good points! Related to what you've linked to in #54075, I just did a quick test of what happens if the class string includes multiple classes, and it seems it gets treated as a single classname so the de-duping logic in add_class gets skipped, resulting in potential duplicates:

image

I'll stick with the foreach for now 🙂

@ramonjd
Copy link
Member

ramonjd commented Dec 12, 2023

Awesome stuff! I know it's early days, but it's working a treat so far. Looking forward to testing it again

2023-12-12.16.29.36.mp4

@andrewserong andrewserong added the Needs Design Feedback Needs general design feedback. label Dec 12, 2023
@jasmussen
Copy link
Contributor

This is fantastic. Functionally it is working exactly as I had hoped/expected. Here's a GIF showing the new aspect ratio control, with frontend preview, fully functional:

cover

The main question is where to put this control, where in this PR you've put it in the Dimensions panel:

Screenshot 2023-12-19 at 10 34 50

This is arguably the correct way to place it, and follows a pattern established by the Featured Image block as well:

Screenshot 2023-12-19 at 10 35 22

The odd one out is the Image block, which puts it in Settings:

Screenshot 2023-12-19 at 10 33 53

A soft ping to @WordPress/gutenberg-design for input here; what do we see as the unified end-state for this control? Would it make sense to (separately) move the dimensions controls from the Image settings tab to the style tab, and what would then happen to the Alt text?

On a separate note, I would expect the Cover block to eventually also get width controls on every block (#25973), so in principle we can move towars this design for the Cover block height control even today:

Screenshot 2023-12-19 at 10 38 41

We can just call it "Max height" instead of "Height". "Maximum height of Cover" is unusually verbose and slightly redundant. Not a blocker here, but simply thinking ahead.

Nice work, thank you!

@jameskoster
Copy link
Contributor

jameskoster commented Dec 19, 2023

I would expect the Cover block to eventually also get width controls on every block

That feels like an important consideration. There's already something a little awkward about the contradiction that can occur between min-height and aspect ratio. If you can define static height / width, how does the interplay with aspect ratio work?

For this PR specifically, is it intended that content becomes invisible if it is too 'tall' for the container? Should there be overflow: auto or similar?

@jasmussen
Copy link
Contributor

If you can define static height / width, how does the interplay with aspect ratio work?

If you have both an aspect ratio, and a min-height, the aspect ratio will define the height until it reaches the min-height, which is what I'd expect.

For this PR specifically, is it intended that content becomes invisible if it is too 'tall' for the container? Should there be overflow: auto or similar?

What are you seeing here?

@jameskoster
Copy link
Contributor

If you have both an aspect ratio, and a min-height, the aspect ratio will define the height until it reaches the min-height, which is what I'd expect.

That's not how it works though? If I set aspect ratio to 1:1 and min-height to 1000000px then the aspect ratio will never be respected because there's not enough horizontal space to do so.

What are you seeing here?

If the height of the contents inside the Cover greater than the aspect ratio allows for the Cover height then the content gets cut off at the top and bottom. Hopefully this video explains better:

cover.mp4

@jasmussen
Copy link
Contributor

That's not how it works though? If I set aspect ratio to 1:1 and min-height to 1000000px then the aspect ratio will never be respected because there's not enough horizontal space to do so.

Right, apologies, I miswrote my sentence, I meant "reaches" in the scaling down kind of way. A different way to say it is: min-height is always min-height, so if the height as inferred by the aspect ratio is smaller than the min-height, the min-height will serve s the floor value. Which is what I'd expect, it remains the minimum value.

If the height of the contents inside the Cover greater than the aspect ratio allows for the Cover height then the content gets cut off at the top and bottom. Hopefully this video explains better:

Right, yes, thank you for clarifying.

Honestly I think we can explore an overflow design tool as a separate thing, and leave it to an editorial responsibility to ensure things look good here.

@andrewserong andrewserong force-pushed the try/dimensions-aspect-ratio-block-support branch from c52cd77 to c071b77 Compare December 20, 2023 01:27
@andrewserong andrewserong changed the title [WIP] Try: Dimensions Aspect Ratio block support Dimensions: Add Aspect Ratio block support Dec 20, 2023
@andrewserong andrewserong marked this pull request as ready for review December 20, 2023 03:52
cbravobernal pushed a commit that referenced this pull request Jan 25, 2024
* Try: Dimensions Aspect Ratio block support

* Try server-rendering output

* Try outputting has-aspect-ratio classname

* Ensure block support is checked properly

* Try adding global styles support

* Update docs, add appropriate checks

* Try unsetting minHeight

* Try unsetting min-height when applying aspect ratio and vice versa

* Allow Cover block to expand when the content extends beyond the boundaries of the aspect-ratio

* Hide cover block resize handle when aspect ratio is set, clear aspect ratio when updating cover block min height

* Clear aspect-ratio if minHeight is set on the site frontend

* Attempt to get unset rules playing nicely in the editor with global styles

* Hide aspectRatio control from global styles for the group block

* Skip output of has-aspect-ratio if value isn't set
@cbravobernal
Copy link
Contributor

I just cherry-picked this PR to the release/17.6 branch to get it included in the next release: bcc44ac

@cbravobernal cbravobernal removed the Backport to Gutenberg RC Pull request that needs to be backported to a Gutenberg release candidate (RC) label Jan 25, 2024
@youknowriad
Copy link
Contributor

Let's add this to the #57959 issue as it requires some manual php backports and please consider opening a core trac ticket and backport. Thank you.

cbravobernal pushed a commit that referenced this pull request Jan 25, 2024
* Try: Dimensions Aspect Ratio block support

* Try server-rendering output

* Try outputting has-aspect-ratio classname

* Ensure block support is checked properly

* Try adding global styles support

* Update docs, add appropriate checks

* Try unsetting minHeight

* Try unsetting min-height when applying aspect ratio and vice versa

* Allow Cover block to expand when the content extends beyond the boundaries of the aspect-ratio

* Hide cover block resize handle when aspect ratio is set, clear aspect ratio when updating cover block min height

* Clear aspect-ratio if minHeight is set on the site frontend

* Attempt to get unset rules playing nicely in the editor with global styles

* Hide aspectRatio control from global styles for the group block

* Skip output of has-aspect-ratio if value isn't set
@richtabor
Copy link
Member

We all seem to agree that hiding the Group block from getting aspect ratio in global styles is a good thing (done in 39873bf)

I'm noticing the aspect ratio support still on the group block:

CleanShot 2024-01-25 at 08 30 31

@djcowan
Copy link

djcowan commented Jan 25, 2024

G. O. L. D.

@getdave
Copy link
Contributor

getdave commented Jan 26, 2024

I noticed this PR was merged after I raised the PHP Sync Tracking Issue for WP 6.5 and has changed PHP files that may need backporting to WP Core.

I've now added it to the Tracking Issue.

justintadlock added a commit to x3p0-dev/x3p0-ideas that referenced this pull request Jan 27, 2024
This will be a WordPress 6.5 feature as it only landed in Gutenberg 17.6. See: WordPress/gutenberg#56897
@andrewserong
Copy link
Contributor Author

Thanks folks, I'll work on backports this week.

I'm noticing the aspect ratio support still on the group block:

@richtabor it's only hidden at the global styles level for the Group block. At the individual block level it's supported as it's still useful there. The main thing we wanted to avoid was folks accidentally setting all Group blocks to a particular aspect ratio and then breaking site layouts.

@andrewserong
Copy link
Contributor Author

I noticed this PR was merged after I raised the #57959 and has changed PHP files that may need backporting to WP Core.

Update: I've opened a trac ticket and a backport PR over here: WordPress/wordpress-develop#5963, and updated the backports tracking issue with links to those two 🙂

@richtabor
Copy link
Member

@richtabor it's only hidden at the global styles level for the Group block. At the individual block level it's supported as it's still useful there

How is aspect ratio on a group block helpful? If we don't have the cover block's position controls, it feels unresponsive if the group block has more than a couple blocks, or is fullwidth. I think there's too many variables where a group block is used differently from a cover block, where it doesn't make as much sense to include.

aspect-ratio-group.mp4

@andrewserong
Copy link
Contributor Author

How is aspect ratio on a group block helpful?

That's a good point. It's hard to use with the Group block as it only really feels at home with a Row or Stack block where the content is small enough for it to be useful and where we have the justification controls. That makes it a bit of a niche feature. Here's an example of using it with the Row variation:

2024-01-30.08.10.08.mp4

In its current form, I agree the aspect ratio controls are likely too prominent on the Group block for something that'll likely be used very rarely. I'm in favour of removing support on the Group block for now, and leaving it just on the Cover block for WP 6.5. We can then revisit for subsequent releases if we think it feels missing not having it on the Group block.

I have a PR up to remove support on the Group block over in #58414

@andrewserong
Copy link
Contributor Author

Update: #58414 has been merged, so support is only for the Cover block for now.

@paaljoachim
Copy link
Contributor

As a result of adding the aspect ratio to the Cover block...
This makes it possible for WooCommerce to switch the Featured Image block (Product image block) to use the Cover block. It will keep the product images the same size. woocommerce/woocommerce#44387

@andrewserong
Copy link
Contributor Author

andrewserong commented Feb 19, 2024

Draft dev note:


Aspect ratio block support

In WordPress 6.5, a new aspect ratio block support has been added, with the Cover block opted-in by default. For themes using the appearanceTools feature in theme.json, the control will be available in the inspector controls, under Dimensions.

The feature allows users to set an aspect ratio for the Cover block, and is mutually exclusive with min-height rules. If an aspect ratio is set, then min-height is unset to ensure that height rules do not conflict with the aspect ratio. The aspect ratio rules will be output at render-time for the block via an inline style applied to the block's wrapper.

Note that themes or blocks that add width or height rules to a block will need to take care in testing compatibility with aspect-ratio if they are to opt-in to aspect ratio support. Aspect ratio tends to work most flexibly when width or height rules are not set.

How to add aspectRatio support to a theme

There are two ways to add support for aspectRatio to a block theme. The simplest is to opt in to the appearanceTools setting, which automatically enables a number of design tools (read more in the developer handbook).

For themes that wish to have more granular control over which UI tools are enabled, the aspectRatio support can be opted into by setting settings.dimensions.aspectRatio to true in theme.json. For example:

{
	"settings": {
		"dimensions": {
			"aspectRatio": true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Block] Cover Affects the Cover Block - used to display content laid over a background image [Block] Group Affects the Group Block [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi has dev note when dev note is done (for upcoming WordPress release) Needs Design Feedback Needs general design feedback. [Type] Experimental Experimental feature or API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add aspect ratio selector to Cover Block