base-ui icon indicating copy to clipboard operation
base-ui copied to clipboard

[menu] How can the `Popover` be rendered over a disabled `Menu.Item`?

Open oleksandr-danylchenko opened this issue 1 year ago • 3 comments

Get help

Question

What is a recommended method to handle rendering of the Popover over a disabled Menu.Item? (including the Item sub-types like the CheckboxItem.

Issue

I need to render a Menu, where the first item appears as "disabled" with a Popover explaining the reason for it. The popover should appear both on click and hover.

Menu Popover
Image Image

With the following layout, the popover appears on click, but not on Spacebar press:

<Popover.Trigger
  className={styles.IconButton}
  render={<div data-disabled="true">{addToLibraryItem}</div>}
/>

IIUC, that happens because when the menu is opened with the keyboard, focus lands on the inner menu item. The latter isn't the trigger for the Popover.

Demo

https://codesandbox.io/p/sandbox/popover-over-disabled-menu-item-r7k9fh

Relations

I believe that the https://github.com/mui/base-ui/issues/2143 is related. There, @KingSora asked how the initial focus can be placed not on the menu item button, but simply on the 1st element.

oleksandr-danylchenko avatar Sep 08 '25 14:09 oleksandr-danylchenko

I think the limitation for this is same as the linked issue(s), only the components with menuitem* roles are supported as interactive elements inside a menu

mj12albert avatar Sep 24 '25 12:09 mj12albert

@oleksandr-danylchenko this seems to work, for your case, havent checked other item types but for normal menu item, it works:


<Popover.Trigger
  openOnHover
  render={(props) => (
    <Button focusableWhenDisabled {...props}>
      Add to Library
    </Button>
  )}
/>;


https://stackblitz.com/edit/wsejcgky?file=src%2FApp.tsx

CiscoFran10 avatar Jan 29 '26 17:01 CiscoFran10

Hello, @CiscoFran10 👋🏻 Unfortunately, it doesn't seem to work when I open the menu using the keyboard:

https://github.com/user-attachments/assets/38d52a9a-e389-435f-82b6-b75dbe5bad38

oleksandr-danylchenko avatar Jan 29 '26 17:01 oleksandr-danylchenko