Repository navigation
Image: Allow removing custom width and height inside Row, Stack and Grid - #85779
DANNER5472 wants to merge 3 commits into
Conversation
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @DANNER5472! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsUnlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jamanca@gmail.com, @ravigojiya. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
b1d5e5d to
b7f9ca7
Compare
ramonjd
left a comment
There was a problem hiding this comment.
Thanks for starting this PR!
Left some comments after manual testing.
| width: activeWidth, | ||
| height: activeHeight, |
There was a problem hiding this comment.
I wonder if we rather need a custom toolpanel item here under 'Image size'.
Reason being, if I set a height and a width on an image, then put the image inside a Row/Stack, you can only reset the width in a row and the height in a stack.
| Stack | Row |
|---|---|
![]() |
![]() |
E.g.,
{ hasCustomSize && (
<ToolsPanelItem
label={ __( 'Image size' ) }
isShownByDefault
hasValue={ () => hasCustomSize }
onDeselect={ () =>
setDimensionAttributes( {
width: undefined,
height: undefined,
} )
}
panelId={ clientId }
>
{ /* A line of read-only text showing the saved size. */ }
</ToolsPanelItem>
) }There was a problem hiding this comment.
Another thing I noticed is that there are now 2 x width fields for Row, and 2 x height fields for stack.
2026-10-28.17.25.05.mp4
The reset menu contains only a single "height" or "width" but it's not clear which resets which.
Possibly the suggestion above to have a single "Image size" item might mitigate it?
|
Thanks for the review and for the screenshots, @ramonjd, and sorry for the delay! That makes sense: I hadn't noticed that Row and Stack already have their own Width/Height flex option, so the new tool duplicates it, and the reset menu doesn't say which field it clears. I'll rework it as a single "Image size" tools panel item with one reset that clears both width and height, shown only when the block has a saved size. I'll update the PR and rebase on trunk. |
b7f9ca7 to
222391f
Compare
|
I reworked the PR following the review, @ramonjd. Thanks for the suggestion and the screenshots. The Dimensions panel no longer gets the extra Width/Height fields inside Row, Stack and Grid, so there is no duplicated field anymore. Instead, when the image has a saved width or height, a single "Image size" item appears in the Dimensions options menu, showing the saved size. Its reset clears width and height together, so it no longer matters whether the layout is a Row or a Stack. When there is no saved size, nothing changes. I tested it locally with a saved width of 250 (Row), and with a saved width and height (250 x 100) moved into a Row: the item shows up and Reset restores the natural size and removes both values. I also rebased on trunk. |
ramonjd
left a comment
There was a problem hiding this comment.
Thanks for making those changes. 🙇🏻
Maybe we could add some test coverage too, e.g., an image with a width in a Row set to Grow, reset "Image size", then check the width is gone, Grow is kept, and focus stays in the menu etc etc
| { `${ activeWidth ?? 'auto' } × ${ | ||
| activeHeight ?? 'auto' | ||
| }` } |
There was a problem hiding this comment.
We should translate auto, e.g., __( 'Auto' ) like the Width/Height fields do. Also the saved values when they're "auto".
In fact the entire string should be translatable, even the x.
{ sprintf(
// translators: 1: Width. 2: Height.
_x( '%1$s × %2$s', 'image dimensions' ),
activeWidth && activeWidth !== 'auto'
? activeWidth
: __( 'Auto' ),
activeHeight && activeHeight !== 'auto'
? activeHeight
: __( 'Auto' )
) }
| { showDimensionsControls && | ||
| SIZED_LAYOUTS.includes( parentLayoutType ) && | ||
| hasCustomSize && ( | ||
| <ToolsPanelItem |
There was a problem hiding this comment.
ToolsPanelItem doesn't display its label, so the panel shows a bare "250px × auto" under Aspect ratio with no heading, and a screen reader reads just the numbers.
Maybe we could wrap the text in a labelled element.
For example, a small "Image size" heading with "250px × auto" under it.
Also I don't think we should show "auto × auto", e.g.,
{ hasCustomSize && (
<Stack direction="column" gap="xs">
<Field.VisualLabel>
{ __( 'Image size' ) }
</Field.VisualLabel>
{ sprintf(
// translators: 1: Width. 2: Height.
_x( '%1$s × %2$s', 'image dimensions' ),
activeWidth && activeWidth !== 'auto'
? activeWidth
: __( 'Auto' ),
activeHeight && activeHeight !== 'auto'
? activeHeight
: __( 'Auto' )
) }
</Stack>
) }
| { dimensionsControl } | ||
| { showDimensionsControls && | ||
| SIZED_LAYOUTS.includes( parentLayoutType ) && | ||
| hasCustomSize && ( |
There was a problem hiding this comment.
Keyboard focus is lost after Reset
2026-11-24.19.58.18.mp4
Not sure... maybe we should keep the item registered in Row, Stack and Grid and only hide the size text when there's no custom size
2026-11-24.20.00.08.mp4
222391f to
37dae41
Compare
|
thanks for the detailed review, @ramonjd! I pushed an update: The size text is now translatable (sprintf with _x), and "Auto" is translated and used for the sides that have no saved value. |
|
Regarding the test coverage you suggested: I tried to run the e2e suite locally (Windows, 8 GB of RAM) and the test web server didn't start in time, so I can't verify a new e2e test before pushing it. The existing image.spec.js has no coverage of the Dimensions panel inside a Row or Stack, so a new test would need to live there. Would you prefer that I still add one for CI to run, or are you okay with merging this as it is and adding the test in a follow-up? Happy to go with whichever you prefer. |
ramonjd
left a comment
There was a problem hiding this comment.
Thanks for the fast updates @DANNER5472
From a code perspective this is ready to ship IMO
I tested the same code locally in a Row, Stack and Grid.
Reset clears the saved size, keeps the Row's "Grow", and keyboard focus now stays in the menu. 🎉
The size text reads well too, for example "Auto × 100px".
I'll just give a soft ping as a general heads up to @WordPress/gutenberg-design because it does add a static label and value to the image block inspector.
I think it's okay, and probably better than disabled control fields (less code and confusion for users)
Another thing: every image in a Row, Stack or Grid now shows "Image size ✓" in the menu, even with no saved size.
That matches how the Row's own "Width" item behaves, but It's still a visible change, so it's worth a quick look from design.
One thing that would help for folks looking back at this PR, would be to update the description to reflect the latest changes. It still describes the earlier behaviour.
For example, "Image size" now always appears in the Dimensions menu for an image in a Row, Stack or Grid.




What?
Closes #84689
Lets users remove a custom width/height from an Image block that sits directly inside a Row, Stack or Grid, through a single "Image size" item in the Dimensions panel that only appears while the block has a saved size.
Why?
Since #68666 the Image block hides its Width/Height controls when its parent uses a flex or grid layout. That is intentional (see the discussion in #69997), so this PR does not bring those controls back.
However, a width/height saved earlier (for example while the image was inside a regular Group that was later switched to Row or Stack) stays applied with no way to see or remove it: the fields are hidden and "Reset all" is disabled. In my testing the saved width also keeps overriding the flex Width option (choosing "Grow" did not stretch the image).
How?
In
packages/block-library/src/image/image.jsx:hasCustomSizeis true when the block has a saved width or height other thanauto.SIZED_LAYOUTS) andhasCustomSizeis true, a newToolsPanelItemlabeled "Image size" is added to the dimensions group. It shows the saved size as text (for example250px × auto).widthandheighttogether throughsetDimensionAttributes, so it works the same in a Row (where the Width option already exists) and in a Stack.The
DimensionsToolof the flex/grid branch is unchanged, so no Width/Height fields are duplicated. When there is no saved size, nothing changes and the controls stay hidden as before. The non-flex branch and the saved markup are unchanged, so no deprecation is needed.The existing lint issues in this file are untouched. I did not add an automated test.
Testing Instructions
250in the Dimensions panel.250px × auto.widthorheight.250and100) while the image is in a regular Group, then switch the Group to Row or Stack. A single Reset clears both values.Testing Instructions for Keyboard
Use of AI Tools
I used Claude (Anthropic, Claude Sonnet 5.5) to help me read the code, propose the change, rework it after the review and explain the contribution process. I applied the change myself, reviewed it, built it locally with wp-env, tested it manually in the editor and ran ESLint on the file.