Skip to content

Menu: Align item slots with the first line of the label - #86135

Merged
ciampo merged 7 commits into
WordPress:trunkfrom
Pathan-Amaankhan:fix/ui-menu-submenu-prefix-icon-alignment
Nov 9, 2026
Merged

ciampo merged 7 commits into
WordPress:trunkfrom
Pathan-Amaankhan:fix/ui-menu-submenu-prefix-icon-alignment

Conversation

@Pathan-Amaankhan

@Pathan-Amaankhan Pathan-Amaankhan commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What?

Fixes #86126

Anchors the selection indicator, prefix, suffix, shortcut, and submenu chevron of a Menu item 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 24px chevron from growing the row, but the same misalignment remained wherever a slot other than the label set the row height:

  • Prefix icons larger than 16px sat above the label, on plain, checkbox, and radio items too.
  • A 16px prefix next to a 24px or 32px suffix icon sat above the label.
  • With a wrapped label, the suffix, shortcut, and chevron are centred on the whole label while the prefix follows the first line.

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 baseline on 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-start calculation and the --_wp-ui-menu-prefix-icon-size custom property, so no icon-size math is needed.

The 16px chevron from the earlier commits is reverted, so Menu.SubmenuTrigger is unchanged from trunk.

Things worth a look

  • Wrapped labels: The suffix, shortcut, and chevron now follow the first line of a wrapped label instead of centring on the whole label. This matches the prefix and the selection indicator, which already sit there. Centring them on the whole label instead would need a different layout for those slots, so please flag it if design prefers that.
  • Taller slots grow the row: A 24px prefix gives a 40px row (it was 36px before) and a 32px prefix gives 48px (it was 40px before). Rows with 16px icons, descriptions, and shortcuts keep their height.
  • The chevron stays 24px: .item-trailing keeps 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.
  • Horizontal layout is unchanged: I compared the left offset and width of every slot in 55 combinations before and after, and nothing changed.

The WrappedItems story 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 a 24px prefix, a description, and the height of a submenu trigger versus a plain item.

Testing Instructions

  1. Run npm run storybook:dev, open the Menu Wrapped items story, open the menu, and check that the prefix, suffix, and chevron of the submenu trigger sit on the first line of its label.
  2. Temporarily give a Menu.Item a Menu.PrefixIcon, size={ 32 } and a 32px suffix icon, and check that both are centred on the label.
  3. Run unit tests with 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

Before After
menu-alignment-before-titled menu-alignment-after-titled

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.

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.
@Pathan-Amaankhan
Pathan-Amaankhan requested a review from a team as a code owner November 1, 2026 20:04
@github-actions github-actions Bot added the [Package] UI /packages/ui label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 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, @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.

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Pathan-Amaankhan <akrocks@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: TobiasBg <tobiasbg@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.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 1, 2026

@ciampo ciampo 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.

Thank you for working on this!

It would be good to get @WordPress/gutenberg-design to also take a look

Comment thread packages/ui/src/menu/style.module.css Resolved
@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Nov 1, 2026
@jameskoster

Copy link
Copy Markdown
Contributor

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 chevron-right rather than chevron-right-small.

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.
@Pathan-Amaankhan Pathan-Amaankhan changed the title Menu: Center the prefix icon of a submenu trigger on its label Menu: Align item slots with the first line of the label Nov 8, 2026
@Pathan-Amaankhan

Copy link
Copy Markdown
Contributor Author

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 16px chevron in 32ecdbf. Since #84612 landed, the 24px chevron no longer grows the row, and the new layout keeps it centred on the first line.

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

@jameskoster

Copy link
Copy Markdown
Contributor

shortcut and chevron follow the first line instead of being centred on the whole label

Seems good to me 👍

@Pathan-Amaankhan

Copy link
Copy Markdown
Contributor Author

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

LGTM 🚀

Thank you for working on this 🙏

@ciampo
ciampo merged commit 4100f20 into WordPress:trunk Nov 9, 2026
85 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 9, 2026
@Pathan-Amaankhan
Pathan-Amaankhan deleted the fix/ui-menu-submenu-prefix-icon-alignment branch November 9, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] UI /packages/ui [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu: Vertical alignment of icons of submenu items is off

3 participants