Repository navigation
Conversation
The submenu chevron is 24px, taller than the 20px label line, so it made the first row taller than the label line. The prefix icon is placed from the top of the row with a margin based on the label line, so it ended up 2px above the label. Trim the chevron's layout box to the label line height with a negative block margin, so it no longer affects the row. Wrapped labels and rows without a submenu are unchanged. Add a browser test that checks the icon and label are centered. Fixes WordPress#86126
The test added for the submenu trigger prefix icon alignment could not pass: - It looked the icon up by accessible name, but the icon is hidden from assistive technology, so it has no name. Find it by its role instead. - It did not load the design tokens, so the CSS variables the layout depends on were undefined and the measured offset was wrong. Import design-tokens.css, as the other layout tests in the package do. Without the CSS fix the test now fails with a 2px offset, and it passes with the fix.
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Pathan-Amaankhan! 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. 🎉 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 |
ciampo
left a comment
There was a problem hiding this comment.
Thank you for working on this!
It would be good to get @WordPress/gutenberg-design to also take a look
|
Without diving into a more comprehensive solution, would making the chevron icon 16px (matching the decorative icon) fix the immediate issue? If necessary we can use |
A 16px chevron no longer makes the first row taller than the label line, so the prefix icon stays centred on the label without extra margin. Use `chevron-right` at 16px with a 2.25 stroke width, which keeps the 1.5px stroke the 24px small chevron has. Remove the chevron's block margin and reduce its negative inline-end margin to keep its position.
…x/ui-menu-submenu-prefix-icon-alignment
|
Pushed the rework in 32ecdbf around the shared first-line anchor suggested in the review. Self-tested the change in Chromium, Safari and Firefox browsers. Things are working as expected ✅. @ciampo, the browser test now covers the problem areas from your table: larger prefixes, tall suffix icons, a wrapped label with a chevron, a radio indicator and a description. @jameskoster, thanks for the suggestion. I reverted the One visible change to check by the design team, i.e. on wrapped labels, the suffix, shortcut and chevron follow the first line instead of being centred on the whole label (before/after in the description). |
Seems good to me 👍 |
|
One more thing (not related to the current task): I have identified a minor color contrast accessibility issue during testing and have opened a separate PR to address it.
As this is a single-line code change, could someone please take a look when possible so we can merge it alongside the current changes? Thank you for your time and review. |
ciampo
left a comment
There was a problem hiding this comment.
LGTM 🚀
Thank you for working on this 🙏
What?
Fixes #86126
Anchors the selection indicator, prefix, suffix, shortcut, and submenu chevron of a
Menuitem to the vertical centre of the label's first line, regardless of the size of the content.Why?
#86126 reported that the prefix icon of a submenu trigger sat above its label.
#84612 fixed that case by keeping the
24pxchevron from growing the row, but the same misalignment remained wherever a slot other than the label set the row height:16pxsat above the label, on plain, checkbox, and radio items too.16pxprefix next to a24pxor32pxsuffix icon sat above the label.Current PR follows the approach suggested in the review (#86135 (comment)): one shared anchor for every slot, instead of compensating for each taller element separately.
How?
Each slot beside the label stacks an invisible, zero-width line with the label's typography over its content in one grid cell.
That line gives the slot a text baseline, so
align-items: first baselineon the item and its content grid lines every slot up with the first line of the label.The content stays centred in its cell, and a taller slot grows the row evenly around that line.
This replaces the prefix's
margin-block-startcalculation and the--_wp-ui-menu-prefix-icon-sizecustom property, so no icon-size math is needed.The
16pxchevron from the earlier commits is reverted, soMenu.SubmenuTriggeris unchanged from trunk.Things worth a look
24pxprefix gives a40pxrow (it was36pxbefore) and a32pxprefix gives48px(it was40pxbefore). Rows with16pxicons, descriptions, and shortcuts keep their height.24px:.item-trailingkeeps its fixed line-height box from UI: Tighten item label, description line-height, and spacing #84612 and now also centres its content, so the chevron overflows evenly and does not make submenu rows taller than plain items.The
WrappedItemsstory now includes a wrapped submenu trigger, and the browser test covers larger prefixes and suffix icons, a wrapped label with a suffix icon, shortcut, and chevron, a radio indicator with a24pxprefix, a description, and the height of a submenu trigger versus a plain item.Testing Instructions
npm run storybook:dev, open the MenuWrapped itemsstory, open the menu, and check that the prefix, suffix, and chevron of the submenu trigger sit on the first line of its label.Menu.ItemaMenu.PrefixIcon,size={ 32 }and a32pxsuffix icon, and check that both are centred on the label.npm run test:unit -- packages/ui/src/menu.Testing Instructions for Keyboard
Not applicable: this is a layout change with no new interaction.
Screenshots or screencast
Blue is the centre of the label's first line, orange is the prefix icon, green is a suffix icon, and purple is the chevron.