Skip to content

[menu] Fix SubmenuTrigger not respecting disabled state from render prop - #3858

Merged
michaldudak merged 10 commits into
mui:masterfrom
CiscoFran10:fix/menu-submenu-trigger-disabled
Mar 25, 2026
Merged

michaldudak merged 10 commits into
mui:masterfrom
CiscoFran10:fix/menu-submenu-trigger-disabled

Conversation

@CiscoFran10

@CiscoFran10 CiscoFran10 commented Jan 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes an issue where Menu.SubmenuTrigger did not respect the disabled attribute when a disabled button was provided via the render prop. Also adds visual disabled styles to Menu demos to match existing patterns in experiments components.

Changes

  • Fixed Menu.SubmenuTrigger not detecting the disabled state when a disabled button is provided via the render prop (e.g., render={<button disabled />}). The component now correctly derives the disabled state from the rendered element and applies it to submenu trigger behavior.
  • Added disabled styles to all Menu demo components (CSS Modules and Tailwind CSS) to provide visual feedback for disabled menu items, following the existing pattern used in the experiments components.

Problem

When using Menu.SubmenuTrigger with a render prop that contains a disabled button:

<Menu.SubmenuTrigger
  nativeButton
  render={<button type="button" disabled />}
>
  Open submenu
</Menu.SubmenuTrigger>

The disabled state was not detected, causing the submenu to still open via mouse hover, even though the underlying button was disabled.

Additionally, Menu demos lacked disabled styling. There was no visual distinction between enabled and disabled menu items when highlighted.

Before

Before - no visual difference for disabled items

After

After - clear visual indication for disabled items

Added data-[disabled] styles to all Menu demos.

CSS Modules

&[data-disabled][data-highlighted]::before {
  background-color: var(--color-gray-300);
}

&[data-disabled] {
  color: var(--color-gray-400);
}

Tailwind CSS

data-[disabled]:text-gray-400
data-[disabled]:data-[highlighted]:before:bg-gray-300

Reviewer Notes

This follows the existing pattern used by experiments components where disabled state is expressed via data-[disabled] and styling is driven from that attribute.

Although there is a possible workaround today (passing disabled directly to Menu.SubmenuTrigger), this change ensures the render-prop pattern behaves consistently with developer expectations.

Tests

packages/react/src/menu/submenu-trigger/MenuSubmenuTrigger.test.tsx

  • Renders a disabled submenu trigger with correct attributes (data-disabled, aria-disabled)
  • Does not open submenu on click when the render prop contains a disabled button
  • Does not open submenu via keyboard (ArrowRight / ArrowLeft) when disabled, in both LTR and RTL directions

Related

Experiment Path: docs/src/app/(private)/experiments/menu/menu-disabled-submenu-trigger.tsx
Demo with Error: https://stackblitz.com/edit/aktrg8j2?file=src%2FApp.tsx

Fixes #3850

@pkg-pr-new

pkg-pr-new Bot commented Jan 25, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3858
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3858
    

commit: 8070a03

@mui-bot

mui-bot commented Jan 25, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@greptile-apps

greptile-apps Bot commented Jan 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Fixed Menu.SubmenuTrigger to correctly detect and respect the disabled state when provided via render prop (e.g., render={<button disabled />}), and added visual disabled styles across all Menu demos.

Key Changes:

  • Extracts disabled prop from render element in MenuSubmenuTrigger.tsx:43-47 and includes it in the disabled state computation
  • Added comprehensive test coverage for disabled render prop behavior including click, keyboard navigation, and RTL/LTR directionality
  • Applied consistent data-[disabled] styling across all Menu demos (both CSS Modules and Tailwind variants) to provide visual feedback for disabled items

Implementation Quality:

  • The fix correctly uses React.isValidElement with proper type annotation to safely extract the disabled prop
  • Tests are thorough and cover edge cases (keyboard navigation in both directions, click behavior)
  • Styling follows established patterns from experiments components

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean and focused, with proper type safety, comprehensive test coverage including edge cases, and consistent styling patterns. The core logic change is minimal (6 lines) and correctly integrates with existing disabled state handling. All changes follow established repository patterns.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/menu/submenu-trigger/MenuSubmenuTrigger.tsx Added logic to detect disabled state from render prop element, correctly integrating it into the disabled state computation
packages/react/src/menu/submenu-trigger/MenuSubmenuTrigger.test.tsx Added comprehensive tests for disabled render prop behavior covering click, keyboard navigation, and directionality
docs/src/app/(docs)/react/components/menu/demos/hero/css-modules/index.module.css Added disabled state styling using data-[disabled] attribute for better visual feedback
docs/src/app/(docs)/react/components/menu/demos/hero/tailwind/index.tsx Added disabled state Tailwind classes to menu items for consistent visual styling
docs/src/app/(private)/experiments/menu/menu-disabled-submenu-trigger.tsx Created experiment to demonstrate and test the disabled submenu trigger render prop behavior

@netlify

netlify Bot commented Jan 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8070a03
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69c3c08fc2b0270008f792c9
😎 Deploy Preview https://deploy-preview-3858--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +43 to +47
const renderElementDisabled = Boolean(
render &&
React.isValidElement<{ disabled?: boolean | undefined }>(render) &&
render.props.disabled,
);

@oliviertassinari oliviertassinari Jan 25, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be done the other way around: if the trigger is DOM disabled, have a warning logic in dev mode to detect it and ask developers to move the logic to the parent.

I don't see how we could do React tree introspection, the Base UI component wouldn't even know if that "disabled" prop defined user land maps to an actual disabled behavior, or something else that the user has defined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also doesn't support the function form of render. It seems like the event handlers in useMenuItem could inspect the disabled state of the ref to prevent themselves from executing instead, as we can't determine it in the render body of the component

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've implemented the approach of checking the disabled state via refs in event handlers, and also a warning when the trigger resolves to a DOM-disabled element, suggesting that the disabled state be moved to the Base UI component rather than being applied only at the rendered element level.

The core issue (submenu opening on hover while disabled) is addressed by the guard in useHoverReferenceInteraction.ts. I also added disabled checks inside useMenuItem.ts, which seemed conceptually reasonable, but I’m not fully confident they are strictly necessary.

Do you consider the additional guards in useMenuItem.ts valuable, or should they be removed to keep the fix minimal and scoped solely to preventing submenu activation?

@michaldudak michaldudak Jan 26, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor of removing all checks in production mode. I'm also not very keen on development-time warnings. Disabling a Base UI component's logic should be separate from rendering a custom component (so we can, for example, render Tooltips on disabled buttons).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaldudak To make sure I’m aligning the PR with this direction, could you clarify what you’d like to see as the concrete outcome?

Based on your comment, should I:

  1. Remove all DOM-disabled checks from event handlers (including the one in useHoverReferenceInteraction) and rely solely on the component-level disabled state?
  2. Remove the dev-time warning in MenuSubmenuTrigger entirely?
  3. Keep any minimal guard to prevent submenu opening when a trigger resolves to a disabled DOM element, or is that behavior intentionally unsupported?

Regarding

Disabling a Base UI component's logic should be separate from rendering a custom component (so we can, for example, render Tooltips on disabled buttons).

From an accessibility standpoint, most guidance suggests that tooltips should only be attached to focusable/hoverable elements; disabled buttons and plain text are not focusable, which makes tooltip content unreachable for keyboard and screen reader users:

adobe/react-spectrum#9232

adobe/react-spectrum#7038

https://react-spectrum.adobe.com/v3/Tooltip.html#usage-on-disabled-or-non-interactive-elements

https://mui.com/material-ui/react-tooltip/#disabled-elements

A common workaround is to render a focusable wrapper but i also found this approach to work:

<Tooltip.Trigger
  render={(props) => (
    <Button focusableWhenDisabled {...props} disabled>
      <BoldIcon aria-label="Bold" />
    </Button>
  )}
/>

(StackBlitz: https://stackblitz.com/edit/ljb99a3s?file=src%2FApp.tsx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that I'm pretty fine with the current state of things. We may show a warning in dev for submenu triggers, but not for other components.

From an accessibility standpoint, most guidance suggests that tooltips should only be attached to focusable/hoverable elements; disabled buttons and plain text are not focusable, which makes tooltip content unreachable for keyboard and screen reader users.

We believe tooltips are inherently inaccessible and should be visual-only components.
BTW, you can make a disabled Button focusable using the focusableWhenDisabled prop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thnks, I reverted the submenu changes. But I kept the dev warning, the disabled state styles in the demos and some of the tests for the disabled submenu trigger.

@oliviertassinari
oliviertassinari removed their request for review January 26, 2026 10:31
@zannager zannager added the component: menu Changes related to the menu component. label Jan 26, 2026
useIsoLayoutEffect(() => {
const element = triggerElementRef.current;
if (element && isElementDisabled(element) && !disabledProp) {
warn(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to include the component stack trace, as in #3861

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added stack trace to warn message:

 if (process.env.NODE_ENV !== 'production') {
    // eslint-disable-next-line react-hooks/rules-of-hooks
    useIsoLayoutEffect(() => {
      const element = triggerElementRef.current;
      if (element && isElementDisabled(element) && !disabledProp) {
        const ownerStackMessage = SafeReact.captureOwnerStack?.() || '';
        warn(
          `A disabled element was detected on <Menu.SubmenuTrigger>. To properly disable the trigger, use the \`disabled\` prop on the component instead of setting it on the rendered element.${ownerStackMessage}`,
        );
      }
    });
  }

@mj12albert mj12albert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The demos don't actually contain disabled items, are the additional styles necessary?

@CiscoFran10

CiscoFran10 commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@mj12albert

The demos don't actually contain disabled items, are the additional styles necessary?

I think it’s a good enhancement for the sandboxes, even if the demos don’t include disabled items.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Feb 16, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 5, 2026
checked={showMinimap}
onCheckedChange={setShowMinimap}
className="grid cursor-default grid-cols-[0.75rem_1fr] items-center gap-2 py-2 pr-8 pl-2.5 text-sm leading-4 outline-hidden select-none data-[highlighted]:relative data-[highlighted]:z-0 data-[highlighted]:text-gray-50 data-[highlighted]:before:absolute data-[highlighted]:before:inset-x-1 data-[highlighted]:before:inset-y-0 data-[highlighted]:before:z-[-1] data-[highlighted]:before:rounded-xs data-[highlighted]:before:bg-gray-900"
className="grid cursor-default grid-cols-[0.75rem_1fr] items-center gap-2 py-2 pr-8 pl-2.5 text-sm leading-4 outline-hidden select-none data-[highlighted]:relative data-[highlighted]:z-0 data-[highlighted]:text-gray-50 data-[highlighted]:before:absolute data-[highlighted]:before:inset-x-1 data-[highlighted]:before:inset-y-0 data-[highlighted]:before:z-[-1] data-[highlighted]:before:rounded-xs data-[highlighted]:before:bg-gray-900 data-[disabled]:text-gray-400 data-[disabled]:data-[highlighted]:before:bg-gray-300"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data-[highlighted]:before:rounded-xs

Note: rounded-xs doesnt exist in tailwind v3.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're moving away from Tailwind v3 and showcase just v4 in the docs.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 16, 2026

@michaldudak michaldudak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Merge in the latest master and we'll be able to close this PR.

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 20, 2026
@michaldudak
michaldudak merged commit 8593e3a into mui:master Mar 25, 2026
8 of 10 checks passed
@michaldudak

Copy link
Copy Markdown
Member

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: menu Changes related to the menu component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

7 participants