Skip to content

fix!: type RadioGroup onChange and MenuDropdown onClick events as the events they pass - #3349

Merged
interactivellama merged 3 commits into
fix/v11-slds2-css-fixesfrom
fix/v11-event-union-types
Nov 24, 2026
Merged

interactivellama merged 3 commits into
fix/v11-slds2-css-fixesfrom
fix/v11-event-union-types

Conversation

@interactivellama

Copy link
Copy Markdown
Contributor

Release stack for 11.0.0-rc.1 (milestone 11.0.0-rc.1). Base: #3309. The release PR #3342 sits on top of this one.

Fixes #

Additional description

Two onChange/onClick event types that were narrower than the events the components actually pass. Both are type-only breaking changes; runtime behavior is unchanged. They come out of the type-assertion lint work (the rest of it targets 11.0.0-rc.2), and land in rc.1 so the breaking type changes ship before the RC settles.

fix(radio-group)!: type onChange's event as the click or keydown it can be

  • Root cause: Radio calls onChange with the input's change event when a click selects it, but with the click event when a click deselects a checked deselectable radio (a checked radio fires no change), and with the keydown event for Enter, and Space on a checked deselectable radio. Radio cast the click as ChangeEvent, and RadioGroup cast Radio's ChangeEvent | KeyboardEvent as ChangeEvent, so RadioGroup/RadioButtonGroup onChange claimed it always got a ChangeEvent. 0.10.x passed the same events, but had no types.
  • Fix: add RadioChangeEvent (ChangeEvent | MouseEvent | KeyboardEvent on the input, exported from components/radio) and use it for Radio's and RadioGroup's onChange; drop both casts. ColorPicker's swatch toggle, the one internal handler typed for ChangeEvent only, now reads data.value.
  • Tests: radio-group.test.jsx asserts the change, click and keydown events reach onChange; radio-group.type-test.tsx fails if a ChangeEvent-only handler type-checks again.

fix(menu-dropdown)!: type onClick's event as the keydown that can open the menu

  • Root cause: Enter, Space, Up or Down on the trigger opens the menu and keyboardNavigate calls the context's handleClick with that keydown event, which MenuDropdown passed to onClick cast as unknown as MouseEvent. A handler reading clientX or button type-checked and got undefined from the keyboard. Same pattern as Checkbox's cast fixed in fix!: v11 P1 theme 1, behavior and accessibility fixes #3284.
  • Fix: type onClick's event as MouseEvent | KeyboardEvent, and build the keyboard context where the keydown event is in scope, so it passes through without a cast.
  • Tests: dropdown.test.jsx asserts onClick gets the keydown event on a keyboard open; menu-dropdown.type-test.tsx fails if a MouseEvent-only handler type-checks again.

Breaking changes (CHANGELOG Changed, marked BREAKING):

  • RadioGroup and RadioButtonGroup onChange event is RadioChangeEvent, and Radio's adds MouseEvent. A handler annotated (event: ChangeEvent) => … no longer type-checks; read the selection from data.value.
  • MenuDropdown onClick event is MouseEvent | KeyboardEvent. A handler annotated (event: MouseEvent) => … no longer type-checks.

No rendered markup changes, so no snapshot diff.


CONTRIBUTOR checklist (do not remove)

Please complete for every pull request.

Green gate — all of these must pass locally (CI runs the same):

  • npm run lint passes with 0 errors and 0 warnings (npm run lint:fix to auto-fix).
  • npm run typecheck is clean (tsc --noEmit).
  • npm test -- --run passes — this runs both Vitest projects (jsdom unit + real-browser browser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots with npm test -- --run -u and review the diff.
  • npm run build succeeds (type-check + Vite library build + .d.ts + entry shims).

Behavior & docs:

  • First-time contributors: sign the CLA (a bot will comment with instructions).
  • Added/updated Vitest + React Testing Library tests for the change (template: components/button/__tests__). New props and bug fixes should get a regression test. Tests that genuinely need a real browser (focus traversal, layout/measurement, canvas) go in a *.browser.test.jsx file (the browser project); everything else is jsdom.
  • Reviewed the component's Storybook stories: npm run storybook → http://localhost:6007/. Confirm the story actually renders and behaves (deprecated Storyshots/Karma are gone; there is no separate browser-tests server).
  • Story/example code uses the component's real prop API (e.g. slots like content / visualPickerFigure, render props like renderItem, icon props, events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check against components/<name>/__examples__.
  • Storybook Accessibility (a11y) panel shows no new violations for the affected stories.
  • If you added or changed a type, remember runtime PropTypes were removed in the TS migration — types are the contract. Ship accurate .d.ts (they're generated by the build); JS consumers rely on them via editor type-acquisition.

REVIEWER checklist (do not remove)

  • CI is green (GitHub Actions CI workflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.
  • Change has adequate test coverage; bug fixes include a regression test.
  • Reviewed the affected Storybook stories and their a11y panels.
  • Rendered markup still conforms to SLDS — check the story HTML snapshot diff (components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).
  • Public API / package surface: if exports changed, the deep-import contract still holds (@salesforce/design-system-react/components/<name> and nested paths resolve for ESM, CJS, and types). Removing/renaming a public component or export is a breaking change → feat!:/BREAKING CHANGE: and a major version bump.

…an be

Radio calls onChange with the input's `change` event when a click selects
it, but with the `click` event when a click deselects a checked
`deselectable` radio (a checked radio fires no `change`), and with the
`keydown` event for Enter, and for Space on a checked `deselectable`
radio. Radio cast the click to a ChangeEvent, and RadioGroup cast Radio's
ChangeEvent | KeyboardEvent to a ChangeEvent, so RadioGroup and
RadioButtonGroup's `onChange` was typed as always getting a ChangeEvent.
This is the same mismatch as Checkbox's KeyboardEvent cast to a
ChangeEvent (#3284).

The events themselves predate v11: 0.10.x passed the click and keypress
events too, but it had no types. Unlike Checkbox, these keyboard and click
paths are real behavior (deselecting, and Enter to select), so the fix is
the type, not the handler.

Add RadioChangeEvent (ChangeEvent | MouseEvent | KeyboardEvent on the
input) and use it for Radio's and RadioGroup's onChange, and drop both
casts. ColorPicker's swatch toggle was the one internal handler typed for a
ChangeEvent only; it now reads `data.value`.

BREAKING CHANGE: RadioGroup and RadioButtonGroup's `onChange` event is
typed as `RadioChangeEvent`, and Radio's adds MouseEvent. A handler whose
event parameter is annotated as `ChangeEvent` no longer type-checks; read
the selection from `data.value`.
…n the menu

When Enter, Space, Up or Down on the trigger opens the menu,
keyboardNavigate calls the context's handleClick with that keydown
event, and MenuDropdown passed it to `onClick` cast `as unknown as
MouseEvent`. So `onClick` was typed as always getting a MouseEvent, and a
handler reading `clientX` or `button` type-checked and got `undefined`
from the keyboard. This is the same KeyboardEvent-as-another-event cast
as Checkbox's (#3284). 0.10.x also called onClick with the keypress
event, but had no types.

Type `onClick`'s event as `MouseEvent | KeyboardEvent`, and build the
keyboard context where the keydown event is in scope, so handleClick
passes it through without a cast.

BREAKING CHANGE: MenuDropdown's `onClick` event is typed as
`MouseEvent | KeyboardEvent`. A handler whose event parameter is
annotated as `MouseEvent` no longer type-checks.
@interactivellama
interactivellama removed this pull request from stack #3359 November 23, 2026 07:57
@interactivellama
interactivellama changed the base branch from feat/v11-llm-2-migration-guide to fix/v11-slds2-css-fixes November 23, 2026 07:57
@interactivellama
interactivellama force-pushed the fix/v11-event-union-types branch from c9fe0c9 to b73f657 Compare November 23, 2026 07:58
@interactivellama
interactivellama marked this pull request as ready for review November 23, 2026 08:40
@interactivellama
interactivellama removed this pull request from stack #3360 November 23, 2026 23:53
@interactivellama
interactivellama merged commit f807a2b into master Nov 24, 2026
8 checks passed
@interactivellama
interactivellama deleted the fix/v11-event-union-types branch November 24, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants