Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout child fixed size should not be fixed by default and should always have a value set #46139

Merged
merged 5 commits into from
Dec 4, 2022

Conversation

tellthemachines
Copy link
Contributor

Why?

Fixes #46116 and addresses this discussion

Makes fixed flex child size shrinkable by default, with optional toggle to un-shrink it. Also makes sure that a value for 'fixed' setting exists.

How?

flex-shrink should only be 0 if the block is explicitly set to unshrinkable.

Testing Instructions

  1. Add a Row block to a post and add a couple of child blocks in it;
  2. Select a child block and under "Dimensions" in the sidebar select "Width";
  3. Set width to "fixed", add a fixed size e.g. 500px in the input, save;
  4. Verify that on a small viewport the fixed width block shrinks and doesn't overflow it.
  5. Check the "Allow block to break out of layout" toggle, save;
  6. Verify that now the fixed width block is always the same width independently of viewport size.
  7. Remove fixed width completely from block;
  8. Deselect then reselect the block;
  9. Verify that width toggle has been set back to 'fit'.

Screenshots or screencast

Screenshot 2022-11-29 at 3 13 48 pm

@tellthemachines tellthemachines added [Feature] Layout Layout block support, its UI controls, and style output. [Block] Group Affects the Group Block (and row, stack and grid variants) labels Nov 29, 2022
@github-actions
Copy link

github-actions bot commented Nov 29, 2022

Size Change: +3.04 kB (0%)

Total Size: 1.33 MB

Filename Size Change
build/block-editor/index.min.js 181 kB +1.67 kB (+1%)
build/block-editor/style-rtl.css 14.5 kB -2.02 kB (-12%) 👏
build/block-editor/style.css 14.5 kB -2.02 kB (-12%) 👏
build/block-library/blocks/gallery/editor-rtl.css 1.01 kB +26 B (+3%)
build/block-library/blocks/gallery/editor.css 1.02 kB +24 B (+2%)
build/block-library/blocks/image/editor-rtl.css 861 B -51 B (-6%)
build/block-library/blocks/image/editor.css 859 B -53 B (-6%)
build/block-library/blocks/table/editor-rtl.css 491 B -56 B (-10%) 👏
build/block-library/blocks/table/editor.css 491 B -56 B (-10%) 👏
build/block-library/editor-rtl.css 11.7 kB -19 B (0%)
build/block-library/editor.css 11.7 kB -20 B (0%)
build/block-library/index.min.js 196 kB +1 kB (+1%)
build/blocks/index.min.js 50.4 kB +339 B (+1%)
build/components/index.min.js 203 kB +34 B (0%)
build/components/style-rtl.css 11.7 kB +99 B (+1%)
build/components/style.css 11.7 kB +96 B (+1%)
build/core-data/index.min.js 15.9 kB +296 B (+2%)
build/customize-widgets/index.min.js 11.6 kB +329 B (+3%)
build/edit-navigation/index.min.js 16.2 kB -21 B (0%)
build/edit-navigation/style-rtl.css 4.12 kB +23 B (+1%)
build/edit-navigation/style.css 4.13 kB +23 B (+1%)
build/edit-post/index.min.js 34.5 kB -50 B (0%)
build/edit-post/style-rtl.css 7.45 kB -6 B (0%)
build/edit-post/style.css 7.44 kB -5 B (0%)
build/edit-site/index.min.js 61 kB -95 B (0%)
build/edit-site/style-rtl.css 8.55 kB +38 B (0%)
build/edit-site/style.css 8.55 kB +54 B (+1%)
build/edit-widgets/index.min.js 16.7 kB -47 B (0%)
build/edit-widgets/style-rtl.css 4.48 kB +22 B (0%)
build/edit-widgets/style.css 4.48 kB +24 B (+1%)
build/editor/style-rtl.css 3.69 kB +37 B (+1%)
build/editor/style.css 3.68 kB +35 B (+1%)
build/reusable-blocks/index.min.js 2.26 kB +33 B (+1%)
build/server-side-render/index.min.js 2.19 kB +411 B (+23%) 🚨
build/vendors/react-dom.min.js 41.8 kB +3.26 kB (+8%) 🔍
build/vendors/react.min.js 4.02 kB -317 B (-7%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/annotations/index.min.js 2.78 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 7.16 kB
build/block-directory/style-rtl.css 1.03 kB
build/block-directory/style.css 1.04 kB
build/block-editor/content-rtl.css 2.71 kB
build/block-editor/content.css 2.71 kB
build/block-editor/default-editor-styles-rtl.css 401 B
build/block-editor/default-editor-styles.css 401 B
build/block-library/blocks/archives/editor-rtl.css 107 B
build/block-library/blocks/archives/editor.css 106 B
build/block-library/blocks/archives/style-rtl.css 129 B
build/block-library/blocks/archives/style.css 129 B
build/block-library/blocks/audio/editor-rtl.css 185 B
build/block-library/blocks/audio/editor.css 185 B
build/block-library/blocks/audio/style-rtl.css 158 B
build/block-library/blocks/audio/style.css 158 B
build/block-library/blocks/audio/theme-rtl.css 172 B
build/block-library/blocks/audio/theme.css 172 B
build/block-library/blocks/avatar/editor-rtl.css 154 B
build/block-library/blocks/avatar/editor.css 154 B
build/block-library/blocks/avatar/style-rtl.css 126 B
build/block-library/blocks/avatar/style.css 126 B
build/block-library/blocks/block/editor-rtl.css 338 B
build/block-library/blocks/block/editor.css 338 B
build/block-library/blocks/button/editor-rtl.css 517 B
build/block-library/blocks/button/editor.css 517 B
build/block-library/blocks/button/style-rtl.css 566 B
build/block-library/blocks/button/style.css 566 B
build/block-library/blocks/buttons/editor-rtl.css 373 B
build/block-library/blocks/buttons/editor.css 373 B
build/block-library/blocks/buttons/style-rtl.css 368 B
build/block-library/blocks/buttons/style.css 368 B
build/block-library/blocks/calendar/style-rtl.css 270 B
build/block-library/blocks/calendar/style.css 270 B
build/block-library/blocks/categories/editor-rtl.css 125 B
build/block-library/blocks/categories/editor.css 124 B
build/block-library/blocks/categories/style-rtl.css 138 B
build/block-library/blocks/categories/style.css 138 B
build/block-library/blocks/code/editor-rtl.css 102 B
build/block-library/blocks/code/editor.css 102 B
build/block-library/blocks/code/style-rtl.css 159 B
build/block-library/blocks/code/style.css 159 B
build/block-library/blocks/code/theme-rtl.css 160 B
build/block-library/blocks/code/theme.css 160 B
build/block-library/blocks/columns/editor-rtl.css 147 B
build/block-library/blocks/columns/editor.css 147 B
build/block-library/blocks/columns/style-rtl.css 442 B
build/block-library/blocks/columns/style.css 442 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 163 B
build/block-library/blocks/comment-author-avatar/editor.css 163 B
build/block-library/blocks/comment-content/style-rtl.css 134 B
build/block-library/blocks/comment-content/style.css 134 B
build/block-library/blocks/comment-template/style-rtl.css 237 B
build/block-library/blocks/comment-template/style.css 236 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 159 B
build/block-library/blocks/comments-pagination-numbers/editor.css 157 B
build/block-library/blocks/comments-pagination/editor-rtl.css 258 B
build/block-library/blocks/comments-pagination/editor.css 249 B
build/block-library/blocks/comments-pagination/style-rtl.css 272 B
build/block-library/blocks/comments-pagination/style.css 268 B
build/block-library/blocks/comments-title/editor-rtl.css 118 B
build/block-library/blocks/comments-title/editor.css 118 B
build/block-library/blocks/comments/editor-rtl.css 875 B
build/block-library/blocks/comments/editor.css 874 B
build/block-library/blocks/comments/style-rtl.css 672 B
build/block-library/blocks/comments/style.css 671 B
build/block-library/blocks/cover/editor-rtl.css 646 B
build/block-library/blocks/cover/editor.css 647 B
build/block-library/blocks/cover/style-rtl.css 1.61 kB
build/block-library/blocks/cover/style.css 1.6 kB
build/block-library/blocks/embed/editor-rtl.css 327 B
build/block-library/blocks/embed/editor.css 327 B
build/block-library/blocks/embed/style-rtl.css 446 B
build/block-library/blocks/embed/style.css 446 B
build/block-library/blocks/embed/theme-rtl.css 172 B
build/block-library/blocks/embed/theme.css 172 B
build/block-library/blocks/file/editor-rtl.css 335 B
build/block-library/blocks/file/editor.css 335 B
build/block-library/blocks/file/style-rtl.css 288 B
build/block-library/blocks/file/style.css 288 B
build/block-library/blocks/file/view.min.js 353 B
build/block-library/blocks/freeform/editor-rtl.css 2.47 kB
build/block-library/blocks/freeform/editor.css 2.47 kB
build/block-library/blocks/gallery/style-rtl.css 1.58 kB
build/block-library/blocks/gallery/style.css 1.58 kB
build/block-library/blocks/gallery/theme-rtl.css 157 B
build/block-library/blocks/gallery/theme.css 157 B
build/block-library/blocks/group/editor-rtl.css 687 B
build/block-library/blocks/group/editor.css 687 B
build/block-library/blocks/group/style-rtl.css 105 B
build/block-library/blocks/group/style.css 105 B
build/block-library/blocks/group/theme-rtl.css 125 B
build/block-library/blocks/group/theme.css 125 B
build/block-library/blocks/heading/style-rtl.css 128 B
build/block-library/blocks/heading/style.css 128 B
build/block-library/blocks/html/editor-rtl.css 365 B
build/block-library/blocks/html/editor.css 366 B
build/block-library/blocks/image/style-rtl.css 662 B
build/block-library/blocks/image/style.css 666 B
build/block-library/blocks/image/theme-rtl.css 172 B
build/block-library/blocks/image/theme.css 172 B
build/block-library/blocks/latest-comments/style-rtl.css 333 B
build/block-library/blocks/latest-comments/style.css 333 B
build/block-library/blocks/latest-posts/editor-rtl.css 250 B
build/block-library/blocks/latest-posts/editor.css 249 B
build/block-library/blocks/latest-posts/style-rtl.css 514 B
build/block-library/blocks/latest-posts/style.css 514 B
build/block-library/blocks/list/style-rtl.css 135 B
build/block-library/blocks/list/style.css 135 B
build/block-library/blocks/media-text/editor-rtl.css 300 B
build/block-library/blocks/media-text/editor.css 298 B
build/block-library/blocks/media-text/style-rtl.css 540 B
build/block-library/blocks/media-text/style.css 539 B
build/block-library/blocks/more/editor-rtl.css 465 B
build/block-library/blocks/more/editor.css 465 B
build/block-library/blocks/navigation-link/editor-rtl.css 746 B
build/block-library/blocks/navigation-link/editor.css 744 B
build/block-library/blocks/navigation-link/style-rtl.css 153 B
build/block-library/blocks/navigation-link/style.css 153 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 333 B
build/block-library/blocks/navigation-submenu/editor.css 333 B
build/block-library/blocks/navigation/editor-rtl.css 2.19 kB
build/block-library/blocks/navigation/editor.css 2.19 kB
build/block-library/blocks/navigation/style-rtl.css 2.26 kB
build/block-library/blocks/navigation/style.css 2.25 kB
build/block-library/blocks/navigation/view-modal.min.js 2.81 kB
build/block-library/blocks/navigation/view.min.js 447 B
build/block-library/blocks/nextpage/editor-rtl.css 428 B
build/block-library/blocks/nextpage/editor.css 428 B
build/block-library/blocks/page-list/editor-rtl.css 397 B
build/block-library/blocks/page-list/editor.css 398 B
build/block-library/blocks/page-list/style-rtl.css 212 B
build/block-library/blocks/page-list/style.css 212 B
build/block-library/blocks/paragraph/editor-rtl.css 214 B
build/block-library/blocks/paragraph/editor.css 214 B
build/block-library/blocks/paragraph/style-rtl.css 321 B
build/block-library/blocks/paragraph/style.css 321 B
build/block-library/blocks/post-author/style-rtl.css 212 B
build/block-library/blocks/post-author/style.css 212 B
build/block-library/blocks/post-comments-form/editor-rtl.css 137 B
build/block-library/blocks/post-comments-form/editor.css 137 B
build/block-library/blocks/post-comments-form/style-rtl.css 536 B
build/block-library/blocks/post-comments-form/style.css 537 B
build/block-library/blocks/post-date/style-rtl.css 107 B
build/block-library/blocks/post-date/style.css 107 B
build/block-library/blocks/post-excerpt/editor-rtl.css 119 B
build/block-library/blocks/post-excerpt/editor.css 119 B
build/block-library/blocks/post-excerpt/style-rtl.css 116 B
build/block-library/blocks/post-excerpt/style.css 116 B
build/block-library/blocks/post-featured-image/editor-rtl.css 620 B
build/block-library/blocks/post-featured-image/editor.css 618 B
build/block-library/blocks/post-featured-image/style-rtl.css 349 B
build/block-library/blocks/post-featured-image/style.css 349 B
build/block-library/blocks/post-navigation-link/style-rtl.css 190 B
build/block-library/blocks/post-navigation-link/style.css 189 B
build/block-library/blocks/post-template/editor-rtl.css 140 B
build/block-library/blocks/post-template/editor.css 139 B
build/block-library/blocks/post-template/style-rtl.css 317 B
build/block-library/blocks/post-template/style.css 317 B
build/block-library/blocks/post-terms/style-rtl.css 136 B
build/block-library/blocks/post-terms/style.css 136 B
build/block-library/blocks/post-title/style-rtl.css 138 B
build/block-library/blocks/post-title/style.css 138 B
build/block-library/blocks/preformatted/style-rtl.css 139 B
build/block-library/blocks/preformatted/style.css 139 B
build/block-library/blocks/pullquote/editor-rtl.css 170 B
build/block-library/blocks/pullquote/editor.css 170 B
build/block-library/blocks/pullquote/style-rtl.css 357 B
build/block-library/blocks/pullquote/style.css 357 B
build/block-library/blocks/pullquote/theme-rtl.css 201 B
build/block-library/blocks/pullquote/theme.css 201 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 158 B
build/block-library/blocks/query-pagination-numbers/editor.css 156 B
build/block-library/blocks/query-pagination/editor-rtl.css 258 B
build/block-library/blocks/query-pagination/editor.css 247 B
build/block-library/blocks/query-pagination/style-rtl.css 326 B
build/block-library/blocks/query-pagination/style.css 322 B
build/block-library/blocks/query-title/style-rtl.css 108 B
build/block-library/blocks/query-title/style.css 108 B
build/block-library/blocks/query/editor-rtl.css 475 B
build/block-library/blocks/query/editor.css 477 B
build/block-library/blocks/quote/style-rtl.css 253 B
build/block-library/blocks/quote/style.css 253 B
build/block-library/blocks/quote/theme-rtl.css 255 B
build/block-library/blocks/quote/theme.css 259 B
build/block-library/blocks/read-more/style-rtl.css 168 B
build/block-library/blocks/read-more/style.css 168 B
build/block-library/blocks/rss/editor-rtl.css 239 B
build/block-library/blocks/rss/editor.css 240 B
build/block-library/blocks/rss/style-rtl.css 323 B
build/block-library/blocks/rss/style.css 323 B
build/block-library/blocks/search/editor-rtl.css 205 B
build/block-library/blocks/search/editor.css 205 B
build/block-library/blocks/search/style-rtl.css 441 B
build/block-library/blocks/search/style.css 439 B
build/block-library/blocks/search/theme-rtl.css 149 B
build/block-library/blocks/search/theme.css 149 B
build/block-library/blocks/separator/editor-rtl.css 184 B
build/block-library/blocks/separator/editor.css 184 B
build/block-library/blocks/separator/style-rtl.css 269 B
build/block-library/blocks/separator/style.css 269 B
build/block-library/blocks/separator/theme-rtl.css 229 B
build/block-library/blocks/separator/theme.css 229 B
build/block-library/blocks/shortcode/editor-rtl.css 508 B
build/block-library/blocks/shortcode/editor.css 508 B
build/block-library/blocks/site-logo/editor-rtl.css 522 B
build/block-library/blocks/site-logo/editor.css 522 B
build/block-library/blocks/site-logo/style-rtl.css 238 B
build/block-library/blocks/site-logo/style.css 238 B
build/block-library/blocks/site-tagline/editor-rtl.css 129 B
build/block-library/blocks/site-tagline/editor.css 129 B
build/block-library/blocks/site-title/editor-rtl.css 155 B
build/block-library/blocks/site-title/editor.css 155 B
build/block-library/blocks/site-title/style-rtl.css 101 B
build/block-library/blocks/site-title/style.css 101 B
build/block-library/blocks/social-link/editor-rtl.css 219 B
build/block-library/blocks/social-link/editor.css 219 B
build/block-library/blocks/social-links/editor-rtl.css 709 B
build/block-library/blocks/social-links/editor.css 708 B
build/block-library/blocks/social-links/style-rtl.css 1.43 kB
build/block-library/blocks/social-links/style.css 1.43 kB
build/block-library/blocks/spacer/editor-rtl.css 372 B
build/block-library/blocks/spacer/editor.css 372 B
build/block-library/blocks/spacer/style-rtl.css 96 B
build/block-library/blocks/spacer/style.css 96 B
build/block-library/blocks/table/style-rtl.css 670 B
build/block-library/blocks/table/style.css 669 B
build/block-library/blocks/table/theme-rtl.css 220 B
build/block-library/blocks/table/theme.css 220 B
build/block-library/blocks/tag-cloud/style-rtl.css 287 B
build/block-library/blocks/tag-cloud/style.css 288 B
build/block-library/blocks/template-part/editor-rtl.css 436 B
build/block-library/blocks/template-part/editor.css 436 B
build/block-library/blocks/template-part/theme-rtl.css 139 B
build/block-library/blocks/template-part/theme.css 139 B
build/block-library/blocks/text-columns/editor-rtl.css 135 B
build/block-library/blocks/text-columns/editor.css 135 B
build/block-library/blocks/text-columns/style-rtl.css 198 B
build/block-library/blocks/text-columns/style.css 198 B
build/block-library/blocks/verse/style-rtl.css 130 B
build/block-library/blocks/verse/style.css 130 B
build/block-library/blocks/video/editor-rtl.css 720 B
build/block-library/blocks/video/editor.css 723 B
build/block-library/blocks/video/style-rtl.css 218 B
build/block-library/blocks/video/style.css 218 B
build/block-library/blocks/video/theme-rtl.css 171 B
build/block-library/blocks/video/theme.css 171 B
build/block-library/classic-rtl.css 193 B
build/block-library/classic.css 193 B
build/block-library/common-rtl.css 1.05 kB
build/block-library/common.css 1.05 kB
build/block-library/editor-elements-rtl.css 126 B
build/block-library/editor-elements.css 126 B
build/block-library/elements-rtl.css 105 B
build/block-library/elements.css 105 B
build/block-library/reset-rtl.css 514 B
build/block-library/reset.css 514 B
build/block-library/style-rtl.css 12.4 kB
build/block-library/style.css 12.4 kB
build/block-library/theme-rtl.css 749 B
build/block-library/theme.css 753 B
build/block-serialization-default-parser/index.min.js 1.13 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/compose/index.min.js 12.3 kB
build/customize-widgets/style-rtl.css 1.41 kB
build/customize-widgets/style.css 1.41 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 8.12 kB
build/date/index.min.js 32.1 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.74 kB
build/edit-post/classic-rtl.css 569 B
build/edit-post/classic.css 570 B
build/editor/index.min.js 44 kB
build/element/index.min.js 4.72 kB
build/escape-html/index.min.js 548 B
build/experiments/index.min.js 882 B
build/format-library/index.min.js 6.96 kB
build/format-library/style-rtl.css 596 B
build/format-library/style.css 596 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.79 kB
build/keycodes/index.min.js 1.86 kB
build/list-reusable-blocks/index.min.js 2.13 kB
build/list-reusable-blocks/style-rtl.css 858 B
build/list-reusable-blocks/style.css 857 B
build/media-utils/index.min.js 2.94 kB
build/notices/index.min.js 977 B
build/nux/index.min.js 2.07 kB
build/nux/style-rtl.css 772 B
build/nux/style.css 768 B
build/plugins/index.min.js 1.95 kB
build/preferences-persistence/index.min.js 2.23 kB
build/preferences/index.min.js 1.35 kB
build/primitives/index.min.js 960 B
build/priority-queue/index.min.js 1.59 kB
build/react-i18n/index.min.js 702 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.75 kB
build/reusable-blocks/style-rtl.css 281 B
build/reusable-blocks/style.css 281 B
build/rich-text/index.min.js 10.7 kB
build/shortcode/index.min.js 1.52 kB
build/style-engine/index.min.js 1.51 kB
build/token-list/index.min.js 650 B
build/url/index.min.js 3.7 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/viewport/index.min.js 1.09 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.23 kB
build/widgets/style-rtl.css 1.21 kB
build/widgets/style.css 1.21 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

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.

This is testing nicely for me, and I like the idea of adding the toggle control 👍

Just left a comment about the setAttributes call within useEffect, since I think I remember a similar thing causing performance issues with the Group block in the past, but I can't quite remember why it did, I'm sorry! 😅

const { selfStretch, flexSize } = childLayout;
const { selfStretch, flexSize, breakOutOfLayout = false } = childLayout;

useEffect( () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember we needed to remove the useEffect in the Group block back in #44176. Will adding a useEffect here have similar performance concerns as the earlier Group block useEffect?

I'm wondering if we need to change the attribute via setAttribute or if it'd be possible to use a different temporary variable for determining which control to display, if it's more about which tab is shown when the block is initially selected, rather than changing the attributes for the block 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Offhand I'd think not because this control only loads once the block is selected. I think the perf issues we were seeing with using an effect in the Group edit function were related to the editor content taking longer to load.

In any case, I'm happy to change if there's a better approach! I played around with it a bit but couldn't find another way to tell if the component is rendering for the first time, or just updating as a result of a change of value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Offhand I'd think not because this control only loads once the block is selected.

Ah, good point, yes, the rendering is neatly tucked away inside the DimensionsPanel isn't it — sounds like we can go with this approach for now and revisit if need be 👍

@@ -334,10 +334,11 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$child_layout_styles = array();

if ( 'fixed' === $block['attrs']['style']['layout']['selfStretch'] && isset( $block['attrs']['style']['layout']['flexSize'] ) ) {
$has_shrink = isset( $block['attrs']['style']['layout']['breakOutOfLayout'] ) && $block['attrs']['style']['layout']['breakOutOfLayout'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny style nit (don't worry about updating this if you prefer the explicit approach):

Would it be worth using _wp_array_get here with a default value of false?

E.g. something like _wp_array_get( $block, array( 'attrs', 'style', 'layout', 'breakOutOfLayout' ), false )

@jasmussen
Copy link
Contributor

Thank you for this! It's nice to see this being mainly a "flex-shrink" toggle!

I'd love for us to start with flex-shrink enabled by default, and add the toggle separately. I can sense you're concerned that we won't add such a toggle — I think we should, but I also think it needs the right prominence and placement, and a separate control like this probably isn't the right one.

The thing is, we have this same challenge for fluid typography, this one:

Screenshot 2022-11-29 at 10 35 48

Those 2.25rem in the screenshot are clamp-based fluid, despite being custom and explicit. It would be good for design to think of a universal interface for making these values non-fluid or non-responsive. One basic idea is to have this option live in the unit selector:
Screenshot 2022-11-29 at 10 35 53

Another is an explicit toggle that's integrated into the component-row itself, like "link/unlink". But it needs a little more design work, and it would be good to not hold up the flex-shrink change based on the toggle design. What do you think?

@jameskoster
Copy link
Contributor

jameskoster commented Nov 29, 2022

Thanks for working on this, I agree with everything Joen said re the toggle.

As for the original issue, it still feels a bit buggy that you can select a fixed width and save with the empty input. Could we auto-populate the input with the inherent value instead?

For example here:

Screenshot 2022-11-29 at 11 28 49

The calculated with is 135px, so when I click 'Fixed' in the width control, the input would automatically be populated with 135px. This would also help folks understand exactly what the 'Fixed' option means.

@jasmussen
Copy link
Contributor

I took a stab at where a toggle might live in #46128 (comment)

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.

This is still working well for me after the removal of the toggle, and defaults to no shrink value being applied 👍

The calculated with is 135px, so when I click 'Fixed' in the width control, the input would automatically be populated with 135px. This would also help folks understand exactly what the 'Fixed' option means.

That's a cool idea seeing if we can grab the inherent width and pre-populate it here. It can be challenging to introspect the width of elements reliably from within block controls, though, so I think that sounds like a good thing to look at in a follow-up after this PR lands.

@tellthemachines
Copy link
Contributor Author

Could we auto-populate the input with the inherent value instead?

I've tried doing this in the latest commit. How well it works depends on how many child blocks there are as well as their intrinsic sizes: how the flex container distributes values changes depending on whether the element has an explicit size or not. Weirdly enough, if the block's siblings are able to grow further, setting an explicit value equal to the block's current size can actually cause it to shrink:

smolfix

@tellthemachines
Copy link
Contributor Author

that sounds like a good thing to look at in a follow-up after this PR lands.

Oh whoops, just saw this now. That might have been best, but I just went and did it 😂

@@ -96,7 +108,7 @@ export function ChildLayoutEdit( {
},
} );
} }
value={ flexSize }
value={ flexSize || blockSize }
Copy link
Contributor

@andrewserong andrewserong Nov 30, 2022

Choose a reason for hiding this comment

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

Using the value as a fallback in all cases appears to cause an odd behaviour when editing / removing the fixed value altogether, because it winds up getting a closer to fresh value for the width. Here's a screengrab (initially set to 200px, then after deleting the value and clicking out of the field, it sets it to 95px:

2022-11-30 13 00 34

Would it work to use blockSize within the onChange handler when switching between fit and fixed instead? Edit: ah wait, I see you're already doing that. I guess the question is then, do we need to include the fallback on value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand the question. If we remove the fallback from value the field won't be pre-populated, which I think is a requirement?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we remove the fallback from value the field won't be pre-populated, which I think is a requirement?

Ah, good point, my apologies, I missed that detail of the requirement that James mentioned. I'd been thinking of the Fit -> Fixed selection and not the saved empty Fixed state problem 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries, always worth asking!

Copy link
Contributor

Choose a reason for hiding this comment

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

Just thought I'd hack around a little bit. The only other way I could come up with addressing that requirement while preventing the 95px issue from showing up, would be to add a bit of logic so that when the block is initially selected, it displays as if fit were selected if fixed is selected but flexSize is empty:

	const [ showFit, setShowFit ] = useState();

	useEffect( () => {
		if ( selfStretch === 'fixed' && ! flexSize ) {
			setShowFit( true );
		}
	}, [] );

Then, in the ToggleGroupControl change handler we'd call setShowFit( false ) whenever the value changes. And the bits where we're referring to selfStretch would become the slightly awkward:

				value={ showFit ? 'fit' : selfStretch || 'fit' }
				help={ helpText( showFit ? 'fit' : selfStretch ) }

With that in place, I think we could then remove the blockSize fallback in value={ flexSize || blockSize }, but overall it would be slightly different behaviour than what was asked for.

Feel free to ignore all that, though, I was mostly curious to better understand how it's working! 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't that hide the input altogether when it has no value? I'm not sure we want that; the idea is that if 'fixed' is selected the input should be pre-populated with the current width/height of the block, so we have to pass blockSize as the value unless there's an existing flexSize.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't that hide the input altogether when it has no value?

Yes, it would hide it when initially selected if it doesn't have a flexSize value, and would default to display 'fit' instead. I'm not really advocating for that, but it was the only behaviour I could figure out that avoided accidentally displaying the wrong width value when a user clears out the Fixed input field and then tabs away.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another thought: the issue of the wrong width value only appears when you tab away from the cleared input field, and is correct again if you select another block and then click to re-select the block you were initially working on. Personally, I'd be fine with the idea of merging this PR as-is, and us continue to fix/tweak in follow-ups if need be.

@andrewserong
Copy link
Contributor

Oh whoops, just saw this now. That might have been best, but I just went and did it 😂

No worries! I wasn't sure how hard it'd be to retrieve the value. Good work digging in so quickly!

@jameskoster
Copy link
Contributor

jameskoster commented Nov 30, 2022

setting an explicit value equal to the block's current size can actually cause it to shrink

Could this be a rounding issue?

Going back to my screenshot in #46139 (comment), notice that the paragraph is actually 138.08px wide. In the latest version of this PR I see the shrinking you mentioned, but it seems to be due to the width being set to 138px. Apparently that .08 of a pixel makes a big difference because If I override it manually in the Inspector then there's no shrink.

Could we force values like this to round up to the next pixel? IE 138.00001 becomes 139. That might solve the shrinking problem?

@andrewserong
Copy link
Contributor

Thanks for re-testing @jameskoster!

Could this be a rounding issue? ... Could we force values like this to round up to the next pixel? That might solve the shrinking problem?

It doesn't seem to be a result of rounding, from hacking around locally to get it to round up. It looks like it's to do with what happens when we set an explicit flex-basis value without disabling flex-shrink. Here's a screengrab (in this one, the width is 129.23, and I've hacked it to round up to the nearest pixel value, so the input says 130, but the element still gets shrunk by the flex logic):

2022-12-01 13 30 25

So, I think displaying a value unfortunately highlights the gap between the user entered value and the fuzziness of how flex-basis deals with that value. If we stick we pre-populating the value, I think we'll need to live with there being some kind of jumpiness.

As a workaround, one way to potentially deal with the jumpiness when toggling between Fit and Fixed would be to display the pixel value in the input field, but not actually set it on the block until a user changes the value. However, as soon as they go to change the value, they'd still see the jumpiness.

What do you think?

@jasmussen
Copy link
Contributor

It seems okay that there's a little shift, even if it's curious. Can it be related to the box model? I.e. is it accurate if there's no padding?

@jameskoster
Copy link
Contributor

I agree a little shift is ok, but perhaps its best to force an upwards shift so that we eliminate the extreme text reflow we see in #46139 (comment)? I guess adding a couple of pixels to the calculated value would solve it?

@andrewserong
Copy link
Contributor

Thanks again for taking a look.

Can it be related to the box model? I.e. is it accurate if there's no padding?

It doesn't appear to be, because we're applying box-sizing: border-box to the element in the editor UI when flex-basis is used, and the offsetWidth measurement gets that same measurement.

I guess adding a couple of pixels to the calculated value would solve it?

I did a bit more digging, and the short answer appears to be that no, a couple of pixels won't solve it. I was curious to learn more about why that's the case, so there's a longer explanation below, hope y'all don't mind me sharing the longer version! 🙂


It's a really interesting one, but the issue appears to be with how browsers deal with flex-basis values, and I don't think we can reliably predict or calculate what the browser is going to do with the flex-basis value once it updates the block. In short, whichever calculation we go with will be wrong, because of the fuzzy nature of flex-basis when a flex item is allowed to shrink. Hopefully the following screenshot will help explain the problem a bit better.

In the below screenshot we have a Row block where the left two items are set to "Fit". In this case, we will set the left most block to "Fixed" and use its default value based on the calculation in this PR. Note the reflow, with the value being set to 157px, which we retrieve by getting the offsetWidth from the block prior to setting flex-basis.

In order to get the width of the block to line up to roughly the same width of the original row, we need to set an explicit flex-basis value of around 200px, which is significantly more than tweaking the values a little bit:

image

The reason for this seems to be touched on in the MDN entry for flex-basis:

The demo then changes the flex-basis on the first item. It will then grow and shrink from that flex-basis. This means that, for example, when the flex-basis of the first item is 200px, it will start out at 200px but then shrink to fit the space available with the other items being at least min-content sized.

Examining the block after applying the 200px flex-basis in the above screenshot shows that the width that the browser winds up calculating for that element is 157px, consistent with the shrink behaviour described:

image

So, where does this leave us? I think it means that if we remove flex-shrink (which I agree with), then we also need to accept that the value entered for flex-basis is different to what the browser outputs. This means that examining an existing element within the DOM, and retrieving its final width, is not a reliable indicator of a value to be used in flex-basis.

Based on this, in my view, I think I would probably lean toward abandoning attempting to pre-fill the flex-basis field at all, since the value is not going to be accurate. Alternately, accept that in situations where there is enough room, it'll be pretty close to correct, but as soon as the row is filled with other content, we will see a jump in the UI.

@andrewserong
Copy link
Contributor

Since @tellthemachines isn't around today, and just in case it's desirable to get the flex-shrink removal landed prior to figuring out the desired behaviour for pre-populating the Fixed field, I've copied the flex-shrink removal over to a separate PR over in: #46261 (I'm very happy to close that one out if everyone would prefer to wait until this one can land, of course).

@jameskoster
Copy link
Contributor

Thanks for the digging! Perhaps I am misinterpreting, but it seems like a pretty big problem that setting a width of 200px in the settings doesn't actually result in a block that is 200px wide?

@tellthemachines
Copy link
Contributor Author

Thanks for the detailed description of the problem @andrewserong ! The short of it is that, due to the way flex is implemented in browsers, it's not possible to pre-populate the size input in a reliable manner unless we use flex-shrink. I'll revert the latest commit to this branch, which will leave us with the toggle being reset to fit if the user clicks away from the block without adding and explicit fixed value. This is the same as what happens in other parts of the UI, e.g.: when toggling the font size field to set a custom font size, that input is also not pre-populated.

@tellthemachines
Copy link
Contributor Author

Perhaps I am misinterpreting, but it seems like a pretty big problem that setting a width of 200px in the settings doesn't actually result in a block that is 200px wide?

This is always going to happen if we don't set flex-shrink to 0. No matter what the width of the viewport, there's no guarantee that the item's actual width will be equal to its flex-basis (it would be the same if we set width instead of flex-basis). This is why I thought it important to be able to switch off the "smart" behaviour.

@tellthemachines tellthemachines merged commit f523187 into trunk Dec 4, 2022
@tellthemachines tellthemachines deleted the fix/unfix-fixed-size branch December 4, 2022 23:44
@github-actions github-actions bot added this to the Gutenberg 14.8 milestone Dec 4, 2022
mpkelly pushed a commit to mpkelly/gutenberg that referenced this pull request Dec 7, 2022
…ays have a value set (WordPress#46139)

* Change behaviour of fixed child size to not be fixed by default

* Fix boo-boo

* Remove unshrink control

* Determine fixed size automatically

* Revert "Determine fixed size automatically"

This reverts commit 2ec5ac7.
@femkreations femkreations added the Needs User Documentation Needs new user documentation label Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Group Affects the Group Block (and row, stack and grid variants) [Feature] Layout Layout block support, its UI controls, and style output. Needs User Documentation Needs new user documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It's possible to set a block layout to have a fixed width, but not include a value
5 participants