Skip to content

feat!: standardize v11 callback shapes on (event, data) - #3251

Merged
interactivellama merged 2 commits into
masterfrom
feat/callback-shapes
Oct 27, 2026
Merged

interactivellama merged 2 commits into
masterfrom
feat/callback-shapes

Conversation

@Niznikr

@Niznikr Niznikr commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Additional description

Callbacks across 12 components now share one shape, as the callback conventions require:

  • They are called as (event, data).
  • event is the React event that caused the call, or undefined when there is none (a timer, an unmount, a programmatic change).
  • data is always an object, with an exported type.
  • onRequest* and toggle callbacks report the requested state, not the current one.
  • No callback uses its return value to talk back to the component.

Where the roadmap keeps a callback's name, the signature changes in place (breaking). Where it renames one, the old prop keeps working with its old payload and logs a one-time deprecation warning.

Breaking changes and migration

Component Before After Migration
Tabs onSelect(selectedIndex, lastIndex); returning false cancelled the selection onSelect(event, { selectedIndex, previousIndex }); the return value is ignored Read the indexes from data. To block a tab change, control the component: pass selectedIndex and update it only when the change should happen
MenuDropdown onSelect(option, { option, optionIndex }) onSelect(event, { option, optionIndex }) Change (option) => … to (event, { option }) => …. Handlers that read the second argument need no change
MenuDropdown Clicking custom (non-List) content called onSelect with an empty option and optionIndex: -1 onSelect is not called Use onClose to react to those clicks
Carousel onRequestAutoplayToggle data isAutoplayOn was the current state It is the requested state setIsAutoplayOn(!data.isAutoplayOn) becomes setIsAutoplayOn(data.isAutoplayOn)
Carousel Timer-driven calls passed {} as the event They pass undefined Guard with event?.
SetupAssistant / SetupAssistantStep onStepToggleIsOpen / onToggleIsOpen data isOpen was the current state It is the requested state expanded[i] = !data.isOpen becomes expanded[i] = data.isOpen
Popover onRequestClose data was sometimes {} It always has a trigger: 'cancel' | 'clickOutside' | 'mouseLeave' | 'newPopover' | 'triggerClick' Type change only; Escape now passes the keydown event instead of undefined

Carousel onRenderItem is now typed as ({ item }) => ReactElement, which is how it has always been called at runtime.

Deprecated (still work, warn once)

  • Tree:
    • onClick is replaced by onSelect(event, { node, isSelected }).
    • onExpandClick is replaced by onRequestToggle(event, { node, isExpanded }).
    • With the new callbacks, onRequestToggle fires only for real expand/collapse requests. Left arrow on an item or a collapsed branch now selects the parent through onSelect and leaves it expanded, as the WAI-ARIA tree pattern describes. Before, it came through onExpandClick with select: true and usually collapsed the parent. onExpandClick keeps the old behaviour.
    • onScroll data gains ratio (0–1). percentage is deprecated.
  • SplitView: events.onOpen and events.onClose are replaced by events.onToggle(event, { isOpen }).
  • PillContainer: the flat onClickPill and onRequestRemovePill props move into an events object, with the same signatures.

In every case the new callback wins if both are passed.

Non-breaking: callbacks that took no arguments now get (event, data)

  • Toast onRequestClose(event, { trigger: 'close-button' | 'timeout' }). The timer path passes undefined as the event.
  • Modal and WelcomeMat onRequestClose(event, { trigger: 'close-button' | 'escape' | 'click-outside' }).
  • DatePicker:
    • onRequestOpen(event, { trigger }) and onRequestClose(event, { trigger }). For an outside click the event is the native mousedown/touchstart, because the listener is on document.
    • onClose(undefined, { componentWillUnmount }).
  • MenuDropdown onOpen(event, {}) and onClose(event, {}).

Bug fixes (with regression tests)

  • Toast never auto-dismissed while its parent kept re-rendering with an inline onRequestClose.
    • Cause: the timer effect depended on a callback that depended on onRequestClose, so every new function cleared and restarted the timeout.
    • Fix: the latest callback is kept in a ref, so the timer is set once.
  • Popover: opening a second popover never closed the first.
    • Cause: the shared "currently open" record held a handleClose captured while the popover was still closed, so its isOpen guard always made it a no-op.
    • Fix: it now calls the latest handler through a ref.
  • MenuDropdown onClose fired twice per close.
    • Cause: Dialog reports a close again on unmount, and Tab was handled by both Dialog and MenuDropdown.
    • Fix: each close is reported once.
  • MenuDropdown: mouse selection passed no event.
    • Cause: the menu-list item didn't forward its click.
  • DatePicker onRequestClose fired when the calendar was already closed.
  • DatePicker keyboard open/close skipped onRequestOpen/onRequestClose.
    • Cause: keyboard handling set internal state directly.
    • Effect of the fix: controlled pickers can now open from the keyboard.
  • Tree onScroll reported NaN/Infinity for a list that can't scroll.
    • Fix: ratio is computed from currentTarget and clamped.

Not in this PR

  • Control-model changes (default* props, how controlled vs uncontrolled mode is detected), child contracts, and other renames belong to separate roadmap themes.
  • Tabs naming: the roadmap suggested selectedValue/previousValue for Tabs. Tabs has no value prop today, so this PR uses index names.
  • Known issues left alone:
    • Popover's outside-click detection was lost in the rewrite, so 'clickOutside' can't currently fire.
    • Combobox forwards (event, { trigger }) to a consumer's popover.props.onClose.
    • Tabs fires onSelect for any key pressed on a tab.

Testing

  • New tests check the exact (event, data) payloads, including the requested-state values, the undefined events on timer and unmount paths, and the deprecated paths and their warnings.
  • Story markup is unchanged, so there are no snapshot changes.

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 (npm run lint:fix to auto-fix). Warnings are the tracked gradual-migration backlog; do not add new errors.
  • 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. render-props like onRenderContent / onRenderVisualPicker, 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.

Callbacks across Tabs, MenuDropdown, Carousel, SetupAssistant, Popover,
Tree, SplitView, PillContainer, Toast, Modal, WelcomeMat and DatePicker
now receive (event, data), report the requested state in data, and have
exported data types. Old Tree, SplitView and PillContainer callbacks are
deprecated with one-time warnings rather than removed.

BREAKING CHANGE: Tabs onSelect is called as onSelect(event, { selectedIndex,
previousIndex }) and returning false no longer cancels the selection.
MenuDropdown onSelect is called as onSelect(event, { option, optionIndex }).
Carousel onRequestAutoplayToggle and SetupAssistant onStepToggleIsOpen /
SetupAssistantStep onToggleIsOpen data report the requested state. Popover
onRequestClose data always includes a trigger. See CHANGELOG.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…base

#3248 removed Modal's check-props module and its checkProps call; the
callback-shapes rebase reintroduced the import and the componentDoc import.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@interactivellama
interactivellama merged commit 61a57e6 into master Oct 27, 2026
8 of 9 checks passed
@interactivellama
interactivellama deleted the feat/callback-shapes branch October 27, 2026 08:09
interactivellama added a commit that referenced this pull request Oct 29, 2026
* feat!: standardize v11 callback shapes on (event, data)

Callbacks across Tabs, MenuDropdown, Carousel, SetupAssistant, Popover,
Tree, SplitView, PillContainer, Toast, Modal, WelcomeMat and DatePicker
now receive (event, data), report the requested state in data, and have
exported data types. Old Tree, SplitView and PillContainer callbacks are
deprecated with one-time warnings rather than removed.

BREAKING CHANGE: Tabs onSelect is called as onSelect(event, { selectedIndex,
previousIndex }) and returning false no longer cancels the selection.
MenuDropdown onSelect is called as onSelect(event, { option, optionIndex }).
Carousel onRequestAutoplayToggle and SetupAssistant onStepToggleIsOpen /
SetupAssistantStep onToggleIsOpen data report the requested state. Popover
onRequestClose data always includes a trigger. See CHANGELOG.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(modal): drop check-props and component.json leftovers from the rebase

#3248 removed Modal's check-props module and its checkProps call; the
callback-shapes rebase reintroduced the import and the componentDoc import.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Stephen James <[email protected]>
interactivellama pushed a commit that referenced this pull request Nov 2, 2026
* style: format components touched by the className/root change

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(modal): drop dead title and closeButtonAssistiveText props

#3248 removed both props, and the callback-shapes rebase in #3251
reintroduced them in ModalProps and the destructuring. Nothing reads
them, so passing either one did nothing.

The progress-indicator modal example passed `title` (so no header
rendered) and `footerClassNames`, which never matched a prop. Use
`heading` and `footerClassName`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat!: put className, style and ref on the outermost element

Slider, Spinner, Tree, Modal, Popover, WelcomeMat and VerticalNavigation
now forward `ref` to the outermost element they render, which is also
where `className` and `style` land. Other nodes take suffixed props
(`classNameDialog`, `classNameSpinner`, `classNameList`, `styleFooter`,
...). Props named the old way (`containerClassName`, `listStyle`,
`footerClassName`, `triggerClassName`, ...) still work, are merged with
their replacements, and log a one-time development warning. Popover's
`styleFooter` applies to walkthrough footers too, like `classNameFooter`.

The docs rule in codebase-overview.md now says the outermost rendered
element, not the `.slds-[component]` node.

BREAKING CHANGE: Popover `className` and `style` apply to the root
trigger wrapper instead of the `.slds-popover` dialog; use
`classNameDialog` and `styleDialog` for the dialog. WelcomeMat
`className` applies to `.slds-welcome-mat` instead of
`.slds-welcome-mat__info-content`. See CHANGELOG.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
interactivellama added a commit that referenced this pull request Nov 11, 2026
…lbacks

#3251 already passes the triggering event (or undefined from the autoplay timer) to onRequestPanelChange and onRequestAutoplayToggle. The existing key-path test only checked that the event was truthy, which an empty object also passes.
interactivellama added a commit that referenced this pull request Nov 11, 2026
…lbacks

#3251 already passes the triggering event (or undefined from the autoplay timer) to onRequestPanelChange and onRequestAutoplayToggle. The existing key-path test only checked that the event was truthy, which an empty object also passes.
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