Repository navigation
Dimensions tool: Show an icon for each aspect ratio option - #85812
Conversation
Adds a small icon drawn in the shape of each ratio to the options in the aspect ratio dropdown, and to the selected value in the trigger. Original and custom ratios use the generic aspect ratio icon.
🤖 PR meta 🤖🎉 PropsIf 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 |
|
This is interesting, thanks for contributing! I've pinged a group to see whether this can be landed. |
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR! It's hard to picture the actual shape just from the ratio numbers, so this is a really valuable improvement for me.
If we move this PR forward, we might also want to improve the aspect ratio dropdown in the media editor modal, so the two stay consistent:
However, @wordpress/media-editor doesn't depend on @wordpress/block-editor, so sharing the UI between them would need some extra work, e.g. moving the component to a package both can use. Does anyone have ideas on the best approach?
| trigger={ | ||
| <SelectControl.Trigger> | ||
| { ( item ) => ( | ||
| <span className="block-editor-dimensions-tool__aspect-ratio-option"> | ||
| <AspectRatioIcon ratio={ item.value ?? '' } /> | ||
| { item.label } | ||
| </span> | ||
| ) } | ||
| </SelectControl.Trigger> | ||
| } |
There was a problem hiding this comment.
Because the trigger's child is now a flex span instead of the plain label, the ellipsis no longer applies, and long labels get cut off without "…".
I think there are two options:
- If the icon isn't needed in the trigger: simply remove this custom trigger.
- If the icon is needed in the trigger: we'd need some custom CSS to restore the ellipsis.
Personally, I think having the icon in the trigger is helpful too, but I'd like to hear feedback from others.
There was a problem hiding this comment.
I also prefer the icon in the trigger approach as it's more intuitive. Should I push a fix for it?
There was a problem hiding this comment.
Yes, I agree the icon is useful enough to be worth some custom CSS 👍
| .block-editor-dimensions-tool__aspect-ratio-option { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; |
There was a problem hiding this comment.
| gap: 8px; | |
| gap: $grid-unit-10; |
We could maybe start with a private component in |
mirka
left a comment
There was a problem hiding this comment.
Since there's already a story for the AspectRatioTool, could we add a story to show case this few feature? Right now I can only see "Original".
|
I've tested all of this locally (the ellipsis, custom ratio icons, gap token and the new stories) and will push the changes once we decide on the icon in the trigger. @t-hamano I'd keep it as it's more intuitive, but I'd also like to hear from others. For the media editor dropdown, should we keep that in this PR or do it separately? My suggestion is a follow-up PR that extracts a minimal private |
No strong opinion, feel free to punt the refactor to a follow up. |
Truncate the label in the trigger so that long names end with an ellipsis, draw custom ratios in the trigger with their own shape, use the spacing token for the gap, and add stories for options, a custom ratio and a long label.
|
Thanks @mirka! I've pushed the review changes: the trigger label truncates with an ellipsis again (icon kept), a custom ratio draws its real shape in the trigger, the gap uses Closed control, top to bottom: a long theme preset name, a custom
I'll do the media editor dropdown in a follow-up PR, starting with a minimal private |
…atio-icons # Conflicts: # packages/block-editor/src/components/dimensions-tool/aspect-ratio-tool.tsx
mirka
left a comment
There was a problem hiding this comment.
Can we add an Enhancements entry to packages/block-editor/CHANGELOG.md? The icons show up wherever the package renders the aspect ratio control, and earlier DimensionsTool changes like #80747 have entries. Something like:
- DimensionsTool: Show an icon in the shape of each ratio next to the aspect ratio options and the selected value ([#85812](https://github.com/WordPress/gutenberg/pull/85812)).
Other than that, I think we're good to go 👍
There was a problem hiding this comment.
Thanks @mirka! Added the changelog entry. Pixel snapping for the custom shapes sounds good as a follow-up, I'll include it with the shared AspectRatioIcon work.
There was a problem hiding this comment.
@hbhalodia thanks for picking up #86297 and opening #86344! Both PRs fix the same blur: #86348 includes the same pixel snapping as part of moving the icon into @wordpress/components, which @mirka suggested in the #85812 review. I compared the two approaches, and they draw identical shapes for every preset ratio and other common ones like 21:9, with every edge on the .25/.75 grid.
Since #86348 deletes the file #86344 edits, I'd suggest landing #86348 first. Once it's in, #86344 would only need to be closed, and I'm happy to link #86297 from #86348 so the issue closes with it.
@mirka does that order work for you? If you'd rather land the smaller #86344 first, I'll rebase #86348 on top of it.
There was a problem hiding this comment.
I'm reviewing @hbhalodia's PR right now and it looks like the pixel snapping itself warrants its own review. Let's land that first and do the refactor separately 👍
|
@t-hamano @mirka, #86348 is ready for review. It's now only the move of the icon into I'd also like your thoughts on the open questions in the description:
Thanks! |



Adds a small icon drawn in the shape of each ratio to the options in the aspect ratio dropdown, and to the selected value in the trigger. Original and custom ratios use the generic aspect ratio icon.
What?
Closes #81626
Adds an icon to each option in the Aspect ratio dropdown, and to the selected value shown in the closed dropdown.
Why?
The options are text only, so it's hard to tell at a glance what shape "4:3" or "9:16" gives you. An icon drawn in the shape of each ratio makes the list easier to scan. The issue asked for this, and the maintainer pointed to the new
SelectControlitem and trigger customisation as the way to do it.How?
AspectRatioIconcomponent indimensions-tool. It draws a rounded rectangle in the proportions of the ratio, within a 24×24 viewBox. Extreme ratios are clamped so the icon never collapses to a line.AspectRatioToolrenders the icon and label in eachSelectControl.Item, and inSelectControl.Triggerfor the selected value. Hidden options are filtered out before the items are passed in.aria-hidden, so the accessible name of each option is unchanged.Because the Styles panel in global styles uses the same tool, it gets the icons too.
Testing Instructions
Unit tests:
npm run test:unit -- packages/block-editor/src/components/dimensions-tool packages/block-editor/src/components/global-styles/test/dimensions-panel.jsKeyboard
Keyboard behaviour is unchanged: Enter opens the list, arrow keys move and Enter selects.
Screenshots or screencast
Closed dropdown after choosing 16:9:
Use of AI Tools
I used Claude Code (Anthropic) to help investigate the issue, locate the cause in the code, and draft the fix. I reviewed the changes, ran the tests and verified the behavior in the browser myself, and I take responsibility for them.