Skip to content

Image: Allow removing custom width and height inside Row, Stack and Grid - #85779

Open
DANNER5472 wants to merge 3 commits into
WordPress:trunkfrom
DANNER5472:fix/84689-image-reset-size
Open

DANNER5472 wants to merge 3 commits into
WordPress:trunkfrom
DANNER5472:fix/84689-image-reset-size

Conversation

@DANNER5472

@DANNER5472 DANNER5472 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • hasCustomSize is true when the block has a saved width or height other than auto.
  • When the image sits in a flex or grid layout (SIZED_LAYOUTS) and hasCustomSize is true, a new ToolsPanelItem labeled "Image size" is added to the dimensions group. It shows the saved size as text (for example 250px × auto).
  • Its reset clears width and height together through setDimensionAttributes, so it works the same in a Row (where the Width option already exists) and in a Stack.

The DimensionsTool of 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

  1. Create a post, insert an Image block and set Width to 250 in the Dimensions panel.
  2. Group the image, then change that Group's variation to Row (or Stack).
  3. Select the image. The Dimensions panel shows the flex Width option once, and the text 250px × auto.
  4. Open the Dimensions options menu (the three dots). It lists "Image size" with a Reset button, and "Reset all" is enabled.
  5. Click "Reset" next to "Image size". The image goes back to its natural size, the text disappears and "Image size" is no longer listed. In the Code editor, the block has no width or height.
  6. Repeat with both Width and Height set (for example 250 and 100) while the image is in a regular Group, then switch the Group to Row or Stack. A single Reset clears both values.
  7. Insert a new image directly inside a Row without setting a size: nothing is shown, as before.
  8. Regression check: an image inside a regular Group still shows Width/Height as before.

Testing Instructions for Keyboard

  1. Select the image block that has a saved width (steps 1 to 3 above).
  2. Using only the keyboard, move focus to the Dimensions panel in the sidebar and open its options menu with Enter.
  3. Move to "Image size" with the arrow keys and activate "Reset" with Enter. The image and the panel update as described in the steps above.

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.

@github-actions github-actions Bot added [Package] Block library /packages/block-library First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository labels Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

👋 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.

🎉 Props

Unlinked Accounts

The 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.

Unlinked contributors: jamanca@gmail.com, ravigojiya.

Co-authored-by: DANNER5472 <dannerjamanca@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: Sourav61 <sourav08@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@DANNER5472
DANNER5472 force-pushed the fix/84689-image-reset-size branch from b1d5e5d to b7f9ca7 Compare October 28, 2026 00:32
@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. [Block] Image Affects the Image Block labels Oct 28, 2026

@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 starting this PR!

Left some comments after manual testing.

Comment on lines +734 to +735
width: activeWidth,
height: activeHeight,

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 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
Image Image

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>
			) }

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.

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?

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.

Just to illustrate what I was babbling about above:

Screenshot 2026-10-29 at 11 03 13 am

@ramonjd
ramonjd requested a balanced review from Copilot October 28, 2026 06:30

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@DANNER5472

Copy link
Copy Markdown
Contributor Author

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.

@DANNER5472
DANNER5472 force-pushed the fix/84689-image-reset-size branch from b7f9ca7 to 222391f Compare November 24, 2026 01:07
@DANNER5472

Copy link
Copy Markdown
Contributor Author

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 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 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

Comment on lines +1103 to +1105
{ `${ activeWidth ?? 'auto' } × ${
activeHeight ?? 'auto'
}` }

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.

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

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.

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.

Screenshot 2026-11-24 at 8 13 39 pm

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 && (

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.

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

@DANNER5472
DANNER5472 force-pushed the fix/84689-image-reset-size branch from 222391f to 37dae41 Compare November 25, 2026 02:55
@DANNER5472

Copy link
Copy Markdown
Contributor Author

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.
It now sits under a visible "Image size" label, so screen readers announce it with the numbers.
The item stays registered in Row, Stack and Grid, and only the size text is hidden when there is no custom size. I tested resetting it with the keyboard and focus now stays inside the options menu.

@DANNER5472

Copy link
Copy Markdown
Contributor Author

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 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 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)

Screenshot 2026-11-25 at 5 31 36 pm Screenshot 2026-11-25 at 5 30 41 pm

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.

Screenshot 2026-11-25 at 5 36 31 pm

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.

@jasmussen

Copy link
Copy Markdown
Contributor

it does add a static label and value to the image block inspector.

You're referring to this?

image

I'm not against it, but why is it at the bottom when it's related to the image size? If it's already ternery to the segmented control, couldn't it sit right under, with no separate label? I.e. "Fit contents. Image size: 359px x Auto", or something in that vein.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Image Affects the Image Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image block: custom width/height can't be removed after the parent Group is switched to Row/Stack

4 participants