[menu] `Menu.SubmenuTrigger` that renders a disabled button is still enabled
Bug report
Current behavior
There is an inconsistency between Menu.Trigger and Menu.SubmenuTrigger:
<Menu.Trigger render={<button type="button" disabled>Open menu</button> />doesn't open the menu when clicked, thanks to thedisabledattribute on the rendered<button>.<Menu.SubmenuTrigger nativeButton={true} render={<button type="button" disabled>Open submenu</button> />still opens the submenu when clicked, despite thedisabledattribute.
Expected behavior
A Menu.SubmenuTrigger that renders a disabled button should not open the submenu when clicked.
Reproducible example
https://stackblitz.com/edit/aktrg8j2?file=src%2FApp.tsx
Base UI version
v1.1.0
Which browser are you using?
Chrome/Safari/Firefox
Which OS are you using?
macOS
Which assistive tech are you using (if applicable)?
None
Additional context
Related to #1976
There is currently a workaround for this case: instead of relying on the disabled attribute on the rendered <button>, you can pass disabled directly to Menu.SubmenuTrigger itself, and then style the trigger using the data-disabled attribute that Base UI applies.
Example:
Demo: https://stackblitz.com/edit/aktrg8j2-zzhknf6y?file=src%2FApp.tsx
<Menu.SubmenuTrigger
nativeButton
disabled
render={<button type="button" />}
>
Open submenu
</Menu.SubmenuTrigger>
Then style based on data-[disabled]:
&[data-disabled][data-highlighted]::before {
background-color: var(--color-gray-300);
}
&[data-disabled] {
color: var(--color-gray-400);
}
That said, I’ve been exploring a possible fix as a contributor so that Menu.SubmenuTrigger can also derive disabled from the rendered element.
I’ll share a PR if it gets approved internally, until then, using the disabled prop on Menu.SubmenuTrigger directly is the recommended approach.
This fix will be available in the next npm release of Base UI.
In the meantime, you can try it out on our Canary release channel:
npm i https://pkg.pr.new/@base-ui/react@3858