Skip to content

feat!: move the remaining callbacks to (event, data) - #3280

Closed
interactivellama wants to merge 19 commits into
masterfrom
feat/v11-callback-shapes
Closed

interactivellama wants to merge 19 commits into
masterfrom
feat/v11-callback-shapes

Conversation

@interactivellama

Copy link
Copy Markdown
Contributor

Fixes the theme 4 "Callback shapes" items in ROADMAP.md.

Additional description

Moves the remaining callbacks to the (event, data) shape. Most of theme 4 already landed in #3251 (Tabs, MenuDropdown, Carousel, SetupAssistant, Popover, Tree, SplitView, PillContainer, Toast, Modal, WelcomeMat, DatePicker), but those roadmap items were never ticked; this PR finishes the rest and ticks them.

There is one commit per component (with a style: commit first where formatting changed), so it can be reviewed commit by commit.

Component Change
alert onRequestClose(event, { trigger: 'close-button' }), matching Toast
color-picker onRequestOpen(event, data) (took no arguments)
docked-composer events.onRequestMinimize/onRequestExpand(event, { isOpen }), events.onRequestClose(event, { trigger })
input/search onSearch/onClear(event, { value })
pill onClick(event, { trigger }), onRemove(event, { trigger }) (onRemove had no event on keyboard removal)
filter onClick(event, { id }) (took no arguments)
popover/edit-dialog onCancel/onSave(event, { isModified })
split-view listbox events.onSort(event, { sortDirection })
accordion onTogglePanel(event, { id, isExpanded }), isExpanded is the requested state
panel (PanelFilterGroup) the five button callbacks get (event, { action })
simple-data-table BREAKING: onSort(data, event) → onSort(event, data), onAction(item, option) → onAction(event, { item, option }); onLoadMore(event, { trigger })
combobox typed data (was Record<string, unknown>, always {}) with a trigger on onRequestOpen/onRequestClose/onClose, plus onOpen { portal } and onFocus { value }

Every component exports a *Data type for its payload and has tests asserting it. All changes except simple-data-table add a trailing argument, so existing handlers keep working.

Breaking change (simple-data-table): handlers written as onSort={(sortColumn) => …} or onAction={(item, option) => …} must take the event first. Migration: onSort={(event, sortColumn) => …}, onAction={(event, { item, option }) => …}. The deprecated onChange(selection, event) is unchanged. The examples are updated and CHANGELOG has a BREAKING entry.

Not in this PR (low priority, plain clicks): builder-header onClickBack/onClickHelp, files onClickDownload/onClickImage, alert/toast onClickHeadingLink.


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

onRequestClose received only the click event. It now also receives
{ trigger: 'close-button' }, matching Toast, and the data type is exported
as AlertRequestCloseData. Existing (event) handlers keep working.
onRequestOpen was called with no arguments. It now receives the swatch
button click and { trigger: 'triggerClick' }, typed as the exported
ColorPickerRequestOpenData. Existing no-argument handlers keep working.
events.onRequestMinimize and onRequestExpand now receive the requested open
state as data ({ isOpen }), and onRequestClose receives { trigger:
'close-button' }. Adds the DockedComposerRequestToggleData and
DockedComposerRequestCloseData types. Existing (event) handlers keep working.
onSearch (Enter or search icon click) and onClear now receive the input's
current value as data. The value is read from the input element, so it is
right whether or not value is controlled; a consumer inputRef still receives
the element. Adds the SearchData and SearchClearData types and the first
Search tests. Existing (event) handlers keep working.
onRemove took no arguments and onClick got no event when fired by Enter.
Both now receive the event and { trigger }: 'click' or 'enter' for onClick,
'remove-button', 'backspace' or 'delete' for onRemove. Adds the
PillClickData and PillRemoveData types. Existing handlers keep working.
onClick took no arguments. It now receives the click event and { id },
matching onChange and onRemove. Adds the FilterClickHandler type. Existing
handlers keep working.
…d onSave

The footer buttons now call onCancel and onSave with the click event and
{ isModified }, so a cancel handler can tell whether there are changes to
discard. Adds the EditDialogActionData type and the first EditDialog
tests. Existing (event) handlers keep working.
… onSort

events.onSort got only the event, so every example worked out the next
direction itself. It now also receives { sortDirection }, the requested
direction (the opposite of sortDirection, or 'down' when unset). Adds the
SplitViewListboxSortData type and updates the examples to use it. Existing
(event) handlers keep working.
onTogglePanel got only the event, so each consumer looked up which panel
and which state from its own closure. It now also receives the panel id
and the requested expansion state. onClickSummary, which Accordion injects
and always overrides, now gets the event and is documented as internal.
Adds the AccordionPanelToggleData type. Existing (event) handlers keep
working.
…callbacks

onClickAdd, onClickRemoveAll, onRequestCancel, onRequestClose and
onRequestSave now receive the click event and { action }, so one handler can
serve several buttons. The private header and footer are unchanged; the group
wraps their callbacks. Adds the PanelFilterGroupActionData and
PanelFilterGroupActionHandler types and the first PanelFilterGroup tests.
Existing (event) handlers keep working.
onSort was called as (data, event) and RowActions onAction as
(item, option). Both now follow the (event, data) convention:
onSort(event, { property, sortDirection }) and
onAction(event, { item, option }). onLoadMore, which took no arguments,
now receives (event, { trigger }). The examples and tests use the new
signatures. The deprecated onChange(selection, event) is unchanged; it
already warns and points to onRowChange.

BREAKING CHANGE: SimpleDataTable onSort is called as
onSort(event, { property, sortDirection }) instead of
onSort({ property, sortDirection }, event), and SimpleDataTableRowActions
onAction as onAction(event, { item, option }) instead of
onAction(item, option).
…the menu

The events data was typed Record<string, unknown> and always {}.
onRequestOpen now gets { trigger } ('click', 'typing', 'down', 'enter'),
onRequestClose and onClose get { trigger } ('escape', 'blur', 'select',
'enter', 'cancel', 'done', 'click-outside', 'trigger-click'), onOpen gets
{ portal } and onFocus gets { value }. Which closes also call the
popover's own onClose is unchanged. Adds the data types and trigger unions.
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.

1 participant