Skip to content

[toolbar] Do not forward disabled to default toolbar button - #4967

Merged
mj12albert merged 3 commits into
mui:masterfrom
mj12albert:fix-toolbar-button-native-disabled
Jun 4, 2026
Merged

mj12albert merged 3 commits into
mui:masterfrom
mj12albert:fix-toolbar-button-native-disabled

Conversation

@mj12albert

@mj12albert mj12albert commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

@mj12albert mj12albert added component: button Changes related to the button component. component: toolbar Changes related to the toolbar component. labels Jun 3, 2026
@mj12albert
mj12albert force-pushed the fix-toolbar-button-native-disabled branch from 2ef531b to 9073233 Compare June 3, 2026 22:15
@pkg-pr-new

pkg-pr-new Bot commented Jun 3, 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@4967
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4967
    

commit: 522152a

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+4B(0.00%) 🔺+3B(0.00%)

Details of bundle changes


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

@netlify

netlify Bot commented Jun 3, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 2ef531b
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a20a74ba5a4d400084136bd
😎 Deploy Preview https://deploy-preview-4967--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@netlify

netlify Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 522152a
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a21aa925187550008511c40
😎 Deploy Preview https://deploy-preview-4967--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@mj12albert mj12albert added type: bug It doesn't behave as expected. and removed component: button Changes related to the button component. labels Jun 3, 2026
@mj12albert
mj12albert marked this pull request as ready for review June 3, 2026 22:28

@flaviendelangle flaviendelangle 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.

Here's the consolidated review.

PR #4967 Review Summary — [toolbar] Do not forward disabled to default toolbar button

Author: mj12albert · Fixes: #4966 · Size: +130/−5 across 5 files (1 source, 4 tests)

The single source change in ToolbarButton.tsx:67:

-        { disabled },
+        render ? { disabled } : EMPTY_OBJECT,

Stops forcing the native disabled attribute onto the default toolbar button. A focusable-disabled native button now keeps only aria-disabled and stays hoverable, so tooltips/hover handlers work on it (issue #4966). The disabled prop is still forwarded when composing via render. All three agents agree this is a small, correct, idiomatic, well-targeted fix.

Critical Issues (0)

None.

Important Issues (0)

None.

Suggestions (4)

  1. [tests] Add an explicit guard for focusableWhenDisabled={false} on a default toolbar button — this is the one risky regression path (it must still render the native disabled attribute, now relying entirely on getButtonProps→useFocusableWhenDisabled). It is correct in code, and is covered in Chromium by ToolbarRoot.test.tsx:184 (toHaveAttribute('disabled')) — but that runs only under describe.skipIf(isJSDOM), so there's no JSDOM-level guard. A small explicit test would lock it in. (code-reviewer + pr-test-analyzer)

  2. [comments] The new comment over-narrows the condition — ToolbarButton.tsx:62-63 says "When composing with another Base UI component, disabled must be passed through," but the actual branch is render being any truthy value (a plain <a>, <div>, or render function also triggers forwarding). Suggested rewording anchors it to the render prop while keeping the Base-UI-composition intent:

    // When a render prop is provided (typically another Base UI component such as Menu.Trigger), forward disabled so the rendered component can derive its own disabled state. For the default toolbar button, avoid forwarding a React disabled prop so focusable disabled buttons remain hoverable for interactions like tooltips.
    (comment-analyzer)

  3. [tests] Brittle assertion — the hover tests assert handleMouseMove fired exactly once (toHaveBeenCalledTimes(1)); user.hover can dispatch more than one mousemove depending on pointer path. toHaveBeenCalled() is more robust. Button.test.tsx, ToolbarButton.test.tsx. (pr-test-analyzer)

  4. [tests] Two of the four new tests don't actually guard this PR's change (not a defect, just scoping clarity):

    • Button.test.tsx "native button: allows hover handlers…" — Button.tsx was untouched and never forwarded a separate { disabled }; this passes identically on master. Useful characterization test, not a regression guard.
    • MenuSubmenuTrigger.test.tsx "does not open on hover when disabled" — MenuSubmenuTrigger is a non-native div whose hover gate is unrelated to this change; also passes on master. A fine standalone test, but incidental to #4966.
      The two strong regression guards (would fail on old code in a real browser) are ToolbarButton.test.tsx:94 and TooltipTrigger.test.tsx:60. (pr-test-analyzer)

Strengths

  • Conditional verified correct across all four cases: default focusable (aria-disabled, hoverable, no native disabled), focusableWhenDisabled={false} (native disabled still applied via getButtonProps), render with a Base UI button (unchanged), and render function/non-button (unchanged).
  • EMPTY_OBJECT is the established idiom for this exact condition ? {…} : EMPTY_OBJECT pattern in a CompositeItem props array (same usage in CheckboxRoot, NavigationMenuContent, SwitchRoot, RadioRoot, ComboboxChips) and preserves referential stability. No type cast needed.
  • The comment rewrite fixes a previously inaccurate claim — the old comment said getButtonProps "includes it already," which was false for the default focusable button (it only sets aria-disabled). The TODO (issue #1976) is correctly retained since the render-branch forwarding still exists.
  • data-disabled styling hook is unaffected (it derives from component state, not the React prop) — and tests assert this.
  • Project-guideline compliant: @base-ui/utils/empty import, correct it.skipIf(isJSDOM) gating for hover-dependent tests, Vitest/jest-dom matchers only, no redundant flushMicrotasks after render.
  • The updateDisabled layout-effect hack in useButton.ts:67-88 is not dead code — still required for the render composition path; its existing comment remains accurate.

Recommended Action

This PR is in good shape to merge. None of the findings are blocking. If the author wants to polish: address Suggestion 2 (1-line comment accuracy fix) and optionally Suggestion 1 (lock in the focusableWhenDisabled={false} path with a JSDOM-level test). Suggestions 3–4 are minor/optional.

@mj12albert
mj12albert enabled auto-merge (squash) June 4, 2026 16:43
@mj12albert
mj12albert merged commit 2b5c94f into mui:master Jun 4, 2026
6 checks passed
@mj12albert
mj12albert deleted the fix-toolbar-button-native-disabled branch June 4, 2026 16:46
@jjenzz jjenzz changed the title [toolbar] Do not foward disabled to default toolbar button [toolbar] Do not forward disabled to default toolbar button Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: toolbar Changes related to the toolbar component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tooltip doesn't trigger for pseudo-disabled toolbar button

2 participants