Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Bug Fixes

- `Button`: Show the pressed state of neutral minimal buttons in forced colors mode ([#85948](https://github.com/WordPress/gutenberg/pull/85948)).
- `Menu`: Align the selection indicator, prefix, suffix, shortcut, and submenu chevron with the first line of the label. Prefix icons larger than 16px and tall suffixes no longer sit above the label, and the row grows around them. The suffix, shortcut, and chevron of an item with a wrapped label now follow the first line instead of centering on the whole label ([#86135](https://github.com/WordPress/gutenberg/pull/86135)).

## 0.26.0 (2026-11-04)

Expand Down
16 changes: 12 additions & 4 deletions packages/ui/src/menu/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,26 @@ function ItemContent( {
variant="body-sm"
className={ styles[ 'item-suffix' ] }
>
{ suffix }
<span className={ styles[ 'accessory-content' ] }>
{ suffix }
</span>
</Text>
) }
{ shortcut && (
<Text
variant="body-sm"
className={ styles[ 'item-shortcut' ] }
>
<KeyboardShortcutDisplay shortcut={ shortcut } />
<span className={ styles[ 'accessory-content' ] }>
<KeyboardShortcutDisplay shortcut={ shortcut } />
</span>
</Text>
) }
{ hasTrailing && (
<span className={ styles[ 'item-trailing' ] }>
{ trailing }
<span className={ styles[ 'accessory-content' ] }>
{ trailing }
</span>
</span>
) }
</span>
Expand All @@ -144,7 +150,9 @@ function ItemContent( {
) }
{ hasPrefix && (
<span aria-hidden="true" className={ styles[ 'item-prefix' ] }>
{ prefix }
<span className={ styles[ 'accessory-content' ] }>
{ prefix }
</span>
</span>
) }
{ shortcut && shortcutDescriptionId && (
Expand Down
9 changes: 1 addition & 8 deletions packages/ui/src/menu/prefix-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import clsx from 'clsx';
import { forwardRef } from '@wordpress/element';
import type { CSSProperties } from 'react';
import { Icon } from '../icon';
import type { PrefixIconProps } from './types';
import styles from './style.module.css';
Expand All @@ -18,19 +17,13 @@ import styles from './style.module.css';
* description in the same item.
*/
export const PrefixIcon = forwardRef< SVGSVGElement, PrefixIconProps >(
function MenuPrefixIcon( { className, size = 16, style, ...props }, ref ) {
function MenuPrefixIcon( { className, size = 16, ...props }, ref ) {
return (
<Icon
{ ...props }
ref={ ref }
size={ size }
className={ clsx( styles[ 'prefix-icon' ], className ) }
style={
{
...style,
'--_wp-ui-menu-prefix-icon-size': `${ size }px`,
} as CSSProperties
}
/>
);
}
Expand Down
18 changes: 17 additions & 1 deletion packages/ui/src/menu/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const WrappedItems: Story = {
parameters: {
docs: {
description: {
story: 'Uses long text to demonstrate wrapping, multiple descriptions, and disabled items. Keep product menu labels short and descriptions rare.',
story: 'Uses long text to demonstrate wrapping, multiple descriptions, and disabled items. The prefix, suffix, shortcut, and submenu chevron stay aligned with the first line of a wrapped label. Keep product menu labels short and descriptions rare.',
},
},
},
Expand All @@ -297,6 +297,22 @@ export const WrappedItems: Story = {
shortcut.
</Menu.ItemDescription>
</Menu.Item>
<Menu.SubmenuRoot>
<Menu.SubmenuTrigger
prefix={ <Menu.PrefixIcon icon={ moveTo } /> }
suffix="Recent"
>
<Menu.ItemLabel>
A submenu trigger with a long label that wraps
onto multiple lines
</Menu.ItemLabel>
</Menu.SubmenuTrigger>
<Menu.Popup>
<Menu.Item>
<Menu.ItemLabel>Archive</Menu.ItemLabel>
</Menu.Item>
</Menu.Popup>
</Menu.SubmenuRoot>
<Menu.Item>
<Menu.ItemLabel>
An item with more than one description
Expand Down
76 changes: 55 additions & 21 deletions packages/ui/src/menu/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,11 @@
[item-padding-end];
column-gap: 0;
row-gap: var(--wpds-dimension-gap-xs);
/* Keep leading content at the top of the content row. */
align-items: start;
/*
* Anchor the slots to the first line of the label. The row grows
* around that line when a slot is taller than it.
*/
align-items: first baseline;
/* Center a single line without shifting wrapped content. */
align-content: center;
justify-content: stretch;
Expand Down Expand Up @@ -231,14 +234,45 @@
grid-row: 1;
}

/*
* The slots beside the label (selection indicator, prefix, suffix,
* shortcut and trailing content) share the center of the label's first
* line as their vertical anchor. Each slot stacks an invisible,
* zero-width line with the label's typography over its content in a
* single grid cell. That line gives the slot a text baseline, so the
* `first baseline` alignment of the item lines it up with the first
* line of the label, whatever the size of the content. The content stays
* centered in the cell, and a taller slot grows the row around the line.
*/
.item-selection-indicator,
.item-prefix,
.item-suffix,
.item-shortcut,
.item-trailing {
display: grid;
align-items: center;

&::before {
content: "\200b";
grid-area: 1 / 1;
font-family: var(--wpds-typography-font-family-body);
font-size: var(--wpds-typography-font-size-md);
line-height: var(--_wp-ui-menu-item-label-line-height);
}
}

.accessory-content {
grid-area: 1 / 1;
display: flex;
align-items: center;
gap: var(--wpds-dimension-gap-xs);
}

.item-selection-indicator {
grid-column: selection-start / selection-end;
justify-self: center;
display: flex;
align-items: center;
justify-content: center;
justify-items: center;
width: var(--wp-ui-menu-selection-indicator-size);
height: var(--_wp-ui-menu-item-label-line-height);
/* Separate the indicator from the label without widening its track. */
margin-inline-end: var(--wpds-dimension-gap-xs);
color: var(--wpds-color-foreground-content-neutral-weak);
Expand All @@ -249,6 +283,11 @@
}
}

.checkbox-selection-icon,
.radio-selection-icon {
grid-area: 1 / 1;
}

.checkbox-selection-icon {
/* Optical alignment with the item label. */
translate: 0 1px;
Expand All @@ -262,18 +301,12 @@

.item-prefix {
grid-column: prefix-start / prefix-end;
display: flex;
align-items: center;
justify-content: center;
gap: var(--wpds-dimension-gap-xs);
min-width: 0;
}

.prefix-icon {
flex-shrink: 0;
/* Center a known-size icon on a label line at the top of the row. */
align-self: flex-start;
margin-block-start: calc((var(--_wp-ui-menu-item-label-line-height) - var(--_wp-ui-menu-prefix-icon-size)) / 2);
}

/*
Expand All @@ -282,8 +315,8 @@
*/
.item-content {
grid-column: prefix-start / content-end;
/* Include the height of leading content when centering these slots. */
align-self: stretch;
/* Line the label up with the slots around it. */
align-self: first baseline;
/* Everything after the prefix is laid out independently per item. */
display: grid;
grid-template-columns:
Expand All @@ -292,7 +325,8 @@
[suffix-end shortcut-start] auto
[shortcut-end trailing-start] auto
[trailing-end];
align-items: center;
/* Anchor the suffix, shortcut and chevron to the first line of the label. */
align-items: first baseline;
box-sizing: border-box;
min-width: 0;
/* Keep clicks on presentational labels and suffixes routed to the menu item. */
Expand All @@ -310,6 +344,7 @@
.item-descriptions {
grid-row: 2;
grid-column: prefix-start / content-end;
align-self: start;
display: flex;
flex-direction: column;
gap: var(--wpds-dimension-gap-xs);
Expand All @@ -336,10 +371,7 @@
/* Outrank the `Text` margin reset, whose stylesheet may load after this one. */
.item-content > .item-suffix {
grid-column: suffix-start / suffix-end;
display: flex;
align-items: center;
margin-inline-start: var(--wpds-dimension-gap-md);
gap: var(--wpds-dimension-gap-xs);
color: var(--wpds-color-foreground-content-neutral-weak);
}

Expand All @@ -351,10 +383,12 @@

.item-trailing {
grid-column: trailing-start / trailing-end;
display: flex;
align-items: center;
/* A 24px chevron overflows evenly instead of growing the row. */
/*
* A 24px chevron overflows evenly instead of growing the row.
* Centering its track keeps the slot's baseline on the label line.
*/
height: var(--_wp-ui-menu-item-label-line-height);
align-content: center;
margin-inline-start: var(--wpds-dimension-gap-md);
color: var(--wpds-color-foreground-content-neutral-weak);
}
Expand Down
Loading
Loading