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

[menu] `Menu.SubmenuTrigger` that renders a disabled button is still enabled

Open benface opened this issue 10 months ago • 2 comments

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 the disabled attribute on the rendered <button>.
  • <Menu.SubmenuTrigger nativeButton={true} render={<button type="button" disabled>Open submenu</button> /> still opens the submenu when clicked, despite the disabled attribute.

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

benface avatar Jan 23 '26 19:01 benface

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.

CiscoFran10 avatar Jan 25 '26 18:01 CiscoFran10

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

github-actions[bot] avatar Mar 25 '26 11:03 github-actions[bot]