Repository navigation
[toolbar] Do not forward disabled to default toolbar button - #4967
Conversation
2ef531b to
9073233
Compare
commit: |
Bundle size
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
flaviendelangle
left a comment
There was a problem hiding this comment.
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)
-
[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 nativedisabledattribute, now relying entirely ongetButtonProps→useFocusableWhenDisabled). It is correct in code, and is covered in Chromium byToolbarRoot.test.tsx:184(toHaveAttribute('disabled')) — but that runs only underdescribe.skipIf(isJSDOM), so there's no JSDOM-level guard. A small explicit test would lock it in. (code-reviewer + pr-test-analyzer) -
[comments] The new comment over-narrows the condition —
ToolbarButton.tsx:62-63says "When composing with another Base UI component,disabledmust be passed through," but the actual branch isrenderbeing any truthy value (a plain<a>,<div>, or render function also triggers forwarding). Suggested rewording anchors it to therenderprop 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) -
[tests] Brittle assertion — the hover tests assert
handleMouseMovefired exactly once (toHaveBeenCalledTimes(1));user.hovercan dispatch more than onemousemovedepending on pointer path.toHaveBeenCalled()is more robust.Button.test.tsx,ToolbarButton.test.tsx. (pr-test-analyzer) -
[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.tsxwas 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" —MenuSubmenuTriggeris 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) areToolbarButton.test.tsx:94andTooltipTrigger.test.tsx:60. (pr-test-analyzer)
Strengths
- Conditional verified correct across all four cases: default focusable (aria-disabled, hoverable, no native
disabled),focusableWhenDisabled={false}(nativedisabledstill applied viagetButtonProps),renderwith a Base UI button (unchanged), andrenderfunction/non-button (unchanged). EMPTY_OBJECTis the established idiom for this exactcondition ? {…} : EMPTY_OBJECTpattern in aCompositeItemprops array (same usage inCheckboxRoot,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 setsaria-disabled). The TODO (issue #1976) is correctly retained since the render-branch forwarding still exists. data-disabledstyling hook is unaffected (it derives from component state, not the React prop) — and tests assert this.- Project-guideline compliant:
@base-ui/utils/emptyimport, correctit.skipIf(isJSDOM)gating for hover-dependent tests, Vitest/jest-dom matchers only, no redundantflushMicrotasksafterrender. - The
updateDisabledlayout-effect hack inuseButton.ts:67-88is not dead code — still required for therendercomposition 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.
disabled to default toolbar buttondisabled to default toolbar button
Stackblitz: https://stackblitz.com/edit/jv4sr229?file=package.json
Fixes #4966