Skip to content

[toggle] Fix grouped cancelation and JSDoc - #4940

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/toggle-cancellation-handling
Jun 1, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/toggle-cancellation-handling

Conversation

@atomiks

@atomiks atomiks commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

This is part of the Codex review sweep

Changes

  • Stop grouped Toggle handling immediately when onPressedChange cancels the event.
  • Add regression coverage for canceled Toggle and ToggleGroup changes, including the parent callback staying quiet when child cancellation vetoes the change.
  • Document data-disabled for Toggle and add accessible labels to the ToggleGroup hero demos.

@atomiks atomiks added accessibility a11y component: toggle Changes related to the toggle component. component: toggle group Changes related to the toggle group component. docs Improvements or additions to the documentation. type: bug It doesn't behave as expected. labels May 29, 2026 — with ChatGPT Codex Connector
@pkg-pr-new

pkg-pr-new Bot commented May 29, 2026 •

Copy link
Copy Markdown

commit: 9b845e2

@code-infra-dashboard

code-infra-dashboard Bot commented May 29, 2026 •

Copy link
Copy Markdown

Bundle size

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

Details of bundle changes

Performance

Total duration: 1,341.78 ms 🔺+252.77 ms(+23.2%) | Renders: 50 (+0) | Paint: 2,022.77 ms 🔺+389.29 ms(+23.8%)

Test Duration Renders
Select mount (200 instances) 181.31 ms 🔺+44.53 ms(+32.6%) 3 (+0)
Menu mount (300 instances) 164.94 ms 🔺+43.89 ms(+36.3%) 2 (+0)
Menu open (500 items) 93.24 ms 🔺+31.51 ms(+51.0%) 12 (+0)
Mixed surface mount (app-like density) 97.61 ms 🔺+30.01 ms(+44.4%) 5 (+0)
Select open (500 options) 71.46 ms 🔺+17.48 ms(+32.4%) 14 (+0)

…and 1 more (+6 within noise) — details


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

@netlify

netlify Bot commented May 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 9b845e2
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a1d92df1695c90008900b82
😎 Deploy Preview https://deploy-preview-4940--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.

@atomiks atomiks changed the title [toggle] Fix grouped cancellation handling [toggle] Fix grouped cancelation and JSDoc May 29, 2026
@atomiks
atomiks marked this pull request as ready for review May 29, 2026 10:19

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

PR #4940 Review Summary — [toggle] Fix grouped cancelation and JSDoc

The fix itself is correct and well-tested for the headline scenarios. Main gap: the new tests don't cover several adjacent code paths that could regress silently. No blocking issues.

Critical Issues

None.

Important Issues

Test coverage gaps (packages/react/src/toggle/Toggle.test.tsx, packages/react/src/toggle-group/ToggleGroup.test.tsx):

  • No test for cancellation in multiple mode — setGroupValue (ToggleGroup.tsx:70-76) has a distinct array-mutation branch that's exercised only in multi mode. A regression there would slip through.
  • No test for keyboard activation (Enter/Space) — the existing tests use button.click(). The repo's convention (see ToggleGroup.test.tsx:402-426) tests both paths separately.
  • No test asserting onPressedChange is called exactly once in the cancel case. A future bug that skips or double-fires it would still pass assertions on aria-pressed.

Suggestions

  • Toggle.tsx:90-91 comment wording: "before the group commits" is slightly imprecise — setGroupValue itself fires onValueChange before committing. Consider tightening to: "before setGroupValue runs, so canceling here also vetoes onValueChange and the group value commit (they share this details object)."
  • Toggle.tsx:101-103 (second isCanceled check): still meaningful — guards the case where onValueChange cancels — but could use a mirroring one-line comment so future readers understand why both checks exist.
  • Pre-existing silent-failure hazard (not introduced by this PR): if a Toggle inside a ToggleGroup has a falsy value, the group commit is silently skipped in production (the dev-only error() at Toggle.tsx:52-63 doesn't run in prod). Worth tracking separately.

Strengths

  • The reorder genuinely fixes the bug: pre-PR, canceling in onPressedChange couldn't veto the group commit because setGroupValue had already run.
  • The added comment correctly explains the WHY (shared details object, cancel ordering), not the WHAT — aligned with AGENTS.md guidance.
  • data-disabled is already emitted via state.disabled (verified by Toggle.test.tsx:93); this PR just documents the existing attribute appropriately in ToggleDataAttributes.ts, types.md, and page.mdx.
  • aria-label="Text alignment" on the ToggleGroup hero demos is a real a11y improvement.
  • Tests follow conventions: Vitest matchers, no Chai chains, no unnecessary flushMicrotasks, mirror existing describe structure.
  • No new silent failures, no broad catches, exception propagation is unaffected.
  • AGENTS.md compliance: no window.setTimeout/useCallback/useLayoutEffect violations.

Recommended Action

  1. (Optional) Add a multiple mode cancellation test and a keyboard-activation cancellation test — closest to "important" of any finding here.
  2. (Optional) Tighten the Toggle.tsx:90-91 comment wording and mirror it above the second isCanceled check.
  3. Approve and merge — the fix is correct and reasonably covered.

@atomiks
atomiks merged commit 93c316f into mui:master Jun 1, 2026
22 of 23 checks passed
@atomiks
atomiks deleted the codex/toggle-cancellation-handling branch June 1, 2026 15:05
@michaldudak michaldudak mentioned this pull request Jun 17, 2026
@michaldudak michaldudak removed the docs Improvements or additions to the documentation. label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y component: toggle group Changes related to the toggle group component. component: toggle Changes related to the toggle component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants