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
3 changes: 1 addition & 2 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

### Breaking Changes

- `PluginMoreMenuItem`, `PluginSidebarMoreMenuItem`: Items render with the `Menu` component of `@wordpress/ui` instead of `MenuItem`. A link item honors only `target="_blank"` ([#81564](https://github.com/WordPress/gutenberg/pull/81564)).
- `PluginMoreMenuItem`, `PluginSidebarMoreMenuItem`, `PluginPreviewMenuItem`: Items render with the `Menu` component of `@wordpress/ui` instead of `MenuItem` ([#81564](https://github.com/WordPress/gutenberg/pull/81564), [#82321](https://github.com/WordPress/gutenberg/pull/82321), [#82428](https://github.com/WordPress/gutenberg/pull/82428)).

### Deprecations

- `PluginMoreMenuItem`, `PluginSidebarMoreMenuItem`, `PluginPreviewMenuItem`: Deprecate the `as` prop, which reached the item only because these components forward every extra prop. The menu now renders the item itself, so the prop is ignored ([#82319](https://github.com/WordPress/gutenberg/pull/82319)).
- `PluginPreviewMenuItem`: The View menu renders with the `Menu` component of `@wordpress/ui`, so a link item honors only `target="_blank"`, as in the Options menu ([#82321](https://github.com/WordPress/gutenberg/pull/82321)).

### Enhancements

Expand Down
16 changes: 14 additions & 2 deletions packages/editor/src/components/more-menu/more-menu-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type MoreMenuItemProps = Omit<
*/
children?: ReactNode;

/**
* Whether the item is disabled.
*/
disabled?: boolean;

/**
* Address the item navigates to, which turns it into a link.
*/
Expand Down Expand Up @@ -109,6 +114,7 @@ function UnforwardedMoreMenuItem(
'aria-checked': ariaChecked,
'aria-label': ariaLabel,
children,
disabled,
href,
icon,
info,
Expand Down Expand Up @@ -145,6 +151,7 @@ function UnforwardedMoreMenuItem(
aria-label={ itemAriaLabel }
checked={ checked }
closeOnClick
disabled={ disabled }
onClick={ onClick }
prefix={ prefix }
shortcut={ itemShortcut }
Expand All @@ -156,15 +163,19 @@ function UnforwardedMoreMenuItem(
);
}

if ( href !== undefined ) {
// A link item has no disabled state: it would still render an active
// anchor. A disabled one falls through to an inert `Menu.Item`, the way
// `PostPreviewMenuItem` renders it.
if ( href !== undefined && ! disabled ) {
return (
<Menu.LinkItem
ref={ ref }
aria-label={ itemAriaLabel }
closeOnClick
href={ href }
prefix={ prefix }
shortcut={ itemShortcut }
openInNewTab={ target === '_blank' }
target={ target }
onClick={ onClick }
{ ...props }
>
Expand All @@ -186,6 +197,7 @@ function UnforwardedMoreMenuItem(
<Menu.Item
ref={ ref }
aria-label={ itemAriaLabel }
disabled={ disabled }
prefix={ prefix }
shortcut={ itemShortcut }
onClick={ onClick }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ describe( 'MoreMenuItem', () => {
'_blank'
);
} );

it( 'renders a disabled link as an inert item', async () => {
const user = userEvent.setup();
renderMenu(
<MoreMenuItem href="/help" disabled>
Help
</MoreMenuItem>
);
await openMenu( user );

const item = screen.getByRole( 'menuitem', { name: 'Help' } );

expect( item ).not.toHaveAttribute( 'href' );
expect( item ).toHaveAttribute( 'aria-disabled', 'true' );
} );
} );

describe( 'the legacy label', () => {
Expand Down
Loading