Correct behaviour of flex child fixed width and introduce max width option#79073
Conversation
|
Size Change: +251 B (0%) Total Size: 8.59 MB 📦 View Changed
|
|
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 Unlinked AccountsThe 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. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Just a drive-by comment (ran out of time to review this week), but for this:
Would changing the label to |
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 |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Good catch! Should be fixed now.
There was a problem hiding this comment.
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' ) |
There was a problem hiding this comment.
I like Andrew’s suggestion of "Max" too as a space saving measure. The help text elaborates "Specify a maximum width." anyway
1009a8c to
eec7c1a
Compare
|
Flaky tests detected in d151ee3. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27516815341
|
This would be a great April fools joke though |
|
Ok I think all the feedback has been addressed and suggestions implemented! This should be ready for a final review. |
There was a problem hiding this comment.
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 🚀
Co-authored-by: Andrew Serong <[email protected]>


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: 0to fixed blocks.There should be no back compat issues; blocks currently set to "fixed" will automatically become "max width", using the same
fixedattribute value as before. The new "fixed" behaviour uses a new attribute valuefixedNoShrink😄Testing Instructions
Screenshots or screencast
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