Skip to content

Correct behaviour of flex child fixed width and introduce max width option#79073

Merged
tellthemachines merged 6 commits into
trunkfrom
fix/flex-child-width
Jun 15, 2026
Merged

Correct behaviour of flex child fixed width and introduce max width option#79073
tellthemachines merged 6 commits into
trunkfrom
fix/flex-child-width

Conversation

@tellthemachines

Copy link
Copy Markdown
Contributor

What?

Closes #53766.

The existing "fixed" option in flex child layouts in reality works as "max width", because it doesn't prevent shrinkage of the blocks it's applied to. This has caused confusion and there have been multiple requests for a "fixed" option that is actually fixed.

This PR solves the issue by renaming the existing "fixed" behaviour "max width", and allowing "fixed" to be unshrinkable by adding flex-shrink: 0 to fixed blocks.

There should be no back compat issues; blocks currently set to "fixed" will automatically become "max width", using the same fixed attribute value as before. The new "fixed" behaviour uses a new attribute value fixedNoShrink 😄

Testing Instructions

  1. Create a Row block with children and set one to "fixed" size on trunk;
  2. Switch to this PR; the "fixed" block should now be max width and its behaviour unchanged;
  3. Try setting another Row child to "fixed" and check that its size doesn't go under the stipulated size when the screen resizes.

Screenshots or screencast

Screenshot 2026-06-10 at 3 52 44 pm

The options are starting to look a little tight, but I'm not sure if there's a better component to use here. Suggestions welcome!

Use of AI Tools

Used codex/gpt 5.5

@tellthemachines tellthemachines self-assigned this Jun 10, 2026
@tellthemachines tellthemachines added [Type] Enhancement A suggestion for improvement. [Feature] Layout Layout block support, its UI controls, and style output. labels Jun 10, 2026
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Jun 10, 2026
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

Size Change: +251 B (0%)

Total Size: 8.59 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 380 kB +251 B (+0.07%)

compressed-size-action

@Marc-pi

Marc-pi commented Jun 10, 2026

Copy link
Copy Markdown

the frequent need is to display a row block for a title within a cover, with a background to hightlight the text ahead of the background image...
i do use a custom css with "width: fit-content;" to minimize the text background width...
this PR does not cover this especially, but it is a strong need...

image

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @porg.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: porg.

Co-authored-by: tellthemachines <[email protected]>
Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: Marc-pi <[email protected]>
Co-authored-by: talldan <[email protected]>
Co-authored-by: tresorama <[email protected]>
Co-authored-by: iamtakashi <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@andrewserong

Copy link
Copy Markdown
Contributor

Just a drive-by comment (ran out of time to review this week), but for this:

The options are starting to look a little tight, but I'm not sure if there's a better component to use here. Suggestions welcome!

Would changing the label to Max help? We already know it's about width due to the label above, so that might help it sneak into the available space?

@talldan

talldan commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

blocks currently set to "fixed" will automatically become "max width", using the same fixed attribute value as before. The new "fixed" behaviour uses a new attribute value fixedNoShrink 😄

Yeah, it's kinda not great and I expect it will be confusing for other contributors, but I guess that's WordPress and the back compat policy 🤷

I don't have any alternative suggestions on a better solution, at least none that don't trade user experience for sensible reading code. (e.g. keeping 'Fixed' as the option and then 'Yeah, but like really fixed' as an extra checkbox. 😄 )

Code quality wise we could potentially use enum style config objects for defining the values to make it self-documenting:

// Note: max used to be called 'Fixed' in the UI but was renamed and replaced by 'fixedNoShrink'.
const WIDTH_VALUES = { fit: 'fit', grow: 'grow', max: 'fixed', fixed: 'fixedNoShrink' }

then whenever the value is check used at least it somewhat makes sense to the reader:

if ( value === WIDTH_VALUES.max )

Also adding comments wherever 'fixed' is referenced as a string could be a nice touch.

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up

It's testing well for me in the default viewport, but the fixed override may need to explicitly emit something like flex-shrink: 1 (assuming I'm grokking the responsive overrides correctly).

then whenever the value is check used at least it somewhat makes sense to the reader:
Code quality wise we could potentially use enum style config objects for defining the values to make it self-documenting

+1 to this. It might make repeated string checks for 'fixed' and 'fixedNoShrink' easier and less prone to misread later. Something like FLEX_CHILD_SIZE.max = 'fixed' and FLEX_CHILD_SIZE.fixed = 'fixedNoShrink' perhaps?

Then the backwards compat check could be abstracted, e.g.,

export function isFlexChildSizingWithSize( value ) {
	return value === FLEX_CHILD_SIZING.MAX || value === FLEX_CHILD_SIZING.FIXED;
}

) {
declarations[ 'flex-basis' ] = flexSize;
if ( selfStretch === 'fixedNoShrink' ) {
declarations[ 'flex-shrink' ] = '0';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I noticed one thing while testing with responsive styles, if a responsive override switches to max width and the default is fixed, the responsive rule only includes flex-basis and it doesn’t reset flex-shrink.

I guess we need to explicitly include flex-shrink: 1;?

Is that something to look at in this PR or a follow up?

@media (width <= 480px) {
    .wp-container-content-067f0074 {
        flex-basis: 244px;
        // inherits  flex-shrink: 0; from default/desktop
    }
}

.wp-container-content-067f0074 {
    flex-basis: 260px;
    flex-shrink: 0;
}

Maybe some tests could cover the final cascade behavior

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Should be fixed now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. I can see flex-shrink: unset; now. 🌮

function maxSizeLabel( parentLayout ) {
const { orientation = 'horizontal' } = parentLayout ?? {};
return orientation === 'horizontal'
? _x( 'Max width', 'Block with maximum width in flex layout' )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like Andrew’s suggestion of "Max" too as a space saving measure. The help text elaborates "Specify a maximum width." anyway

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. It looks much better, thanks both for the suggestion!

Screenshot 2026-06-15 at 10 17 46 am

@github-actions

Copy link
Copy Markdown

Flaky tests detected in d151ee3.
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/27516815341
📝 Reported issues:

@tellthemachines

Copy link
Copy Markdown
Contributor Author

'Yeah, but like really fixed' as an extra checkbox

This would be a great April fools joke though

@tellthemachines

Copy link
Copy Markdown
Contributor Author

Ok I think all the feedback has been addressed and suggestions implemented! This should be ready for a final review.

@andrewserong andrewserong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is testing great for me, and nice work getting back to implementing this, I recall it being a request a long time ago (checks the linked issue: 2023!). While the internal naming might be slightly awkward, I think this is the right approach to preserving back-compat while enabling the feature.

Also, looks like Ramon's case of the base rule being "Fixed" and a mobile viewport settings a block to "Max" is working now 👍

LGTM 🚀

Comment thread schemas/json/block.json Outdated
Co-authored-by: Andrew Serong <[email protected]>
@tellthemachines tellthemachines merged commit 94137f7 into trunk Jun 15, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Layout Layout block support, its UI controls, and style output. [Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Row / Group block child offers dimension width "fixed" which in reality is "proportional" (flex-basis)

5 participants