[menu] How can the `Popover` be rendered over a disabled `Menu.Item`?
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 |
|---|---|
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.
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
@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
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