Skip to content

fix(combobox)!: route action items to events.onSelectActionItem, never onSelect - #3243

Merged
interactivellama merged 4 commits into
masterfrom
fix/combobox-action-items
Oct 26, 2026
Merged

interactivellama merged 4 commits into
masterfrom
fix/combobox-action-items

Conversation

@showerbee

@showerbee showerbee commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Additional description

Symptom. Header rows (optionsSearchEntity, e.g. "Search in Accounts") and footer rows (optionsAddItem, e.g. "+ New Account") behaved differently depending on input:

Mouse click Enter
Before Item onClick ignored. Row sent to onSelect as the new selection (single-select examples showed "New Account" as the value) Item onClick called, onSelect skipped, menu stays open
After Item onClick (deprecated) then events.onSelectActionItem(event, { option, value }), menu closes, onSelect not fired, selection untouched Same as mouse
Disabled, after Nothing; row has aria-disabled="true" Nothing

option is the consumer's own item object. value is the current input text (for "Search for 'acme' in Accounts").

Root cause. Two code paths for one row. Menu sends header/footer clicks into handleSelect, which treats them like any option. handleInputSubmit special-cased header/footer to call activeOption.onClick and return early, without closing. That onClick was never in the optionsAddItem/optionsSearchEntity types. The same split exists in 0.10.x (git show 520f86bb7~1:components/combobox/combobox.jsx, lines ~771 and ~1047), so it predates the v11 rewrite.

Fix. Action rows are commands, not options. Combobox builds them from the two props and marks them with a module-private symbol. Both click and Enter reach handleSelect, which dispatches the action callbacks and returns before any selection logic.

Breaking change and migration

Choosing an action row by mouse no longer calls onSelect or adds the row to selection.

  • Consumers filtering sentinel ids in onSelect (e.g. if (selection[0].id === 'new') openModal()): move that to events.onSelectActionItem.
  • Consumers using item onClick: keeps working for click and Enter, with a one-time deprecation warning. If both onClick and onSelectActionItem are set, both are called (onClick first). Removal is planned for v12.
  • Header/footer rows passed directly in options (not via the two props): unchanged. Enter still calls option.onClick and click still goes to onSelect. ComboboxOption.onClick is marked @deprecated with that scope.

Commit is fix(combobox)!: with a BREAKING CHANGE: footer. We're in the v11 alpha, which is the window for this.

How #3242 shaped this

The first version of this PR fixed the inconsistency by switching modes on whether the item had onClick (has onClick → call it; no onClick → onSelect). Reading #3242 (v11 prop-API freeze review) changed the design:

  • Callback-presence mode switches are a smell. docs: add v11 prop API freeze review to roadmap #3242 flags this pattern in input-icon and pill. Our first version added another. Now the item onClick and events.onSelectActionItem are dispatched independently. Neither one changes what the other does.
  • "onSelect is really a request." An action row isn't a request to change the selection, so routing it through onSelect was the wrong channel. It gets its own callback.
  • Keep the grouped events object. docs: add v11 prop API freeze review to roadmap #3242 keeps Combobox's events. The new callback lives there and follows the (event, data) convention.
  • type: ... | string collapses discriminated unions. That's why action rows aren't identified by type === 'header'. Consumer rows can carry any type and any extra key. A private symbol is the only marker consumers can't collide with (see Codex round 3 below).
  • Controlled isOpen close bug is already tracked there. This PR reuses handleClose() and leaves that fix to the docs: add v11 prop API freeze review to roadmap #3242 follow-up instead of widening scope.

Review

The design was debated with Codex (codex exec, read-only sandbox) across three rounds:

  1. Changing ComboboxOption.onClick's signature broke existing consumer code (option.onClick?.(event)). The widened signature moved to the new ComboboxActionItem type.
  2. The payload option was typed as ComboboxOption; retyped as ComboboxActionItem. In the design debate Codex conceded the mode-switch point (from docs: add v11 prop API freeze review to roadmap #3242), proposed independent dispatch over a precedence fallback, and agreed to keep the isOpen fix and the row union out of scope/private. Naming onSelect… over onRequest… follows the LBC button-menu select precedent.
  3. Review of the implementation found: a string actionItem discriminator could be spoofed by consumer data (actionItem: null would crash), and header/footer rows passed directly in options lost their Enter onClick. It also found the deprecation test was order-dependent. All three are fixed with regression tests.

Commits

  1. style(combobox): Prettier on touched files (lint-staged would otherwise fold ~1200 lines of reformatting into the fix).
  2. fix(combobox): first version (callback-presence routing). Superseded by 4.
  3. style(combobox): Prettier on menu.tsx.
  4. fix(combobox)!: the final design. Review 2 and 4 together, or the squashed diff.

Tests

components/combobox/__tests__/combobox.test.jsx, "Action items": {header, footer} × {mouse, keyboard} for onSelectActionItem payload/close/no-onSelect, no handler, deprecated onClick ordering, disabled + aria-disabled; plus the deprecation warning (fresh module, exact count per prop), legacy direct header/footer rows, and an ordinary option carrying an actionItem key. npm run test:ci: 1033 tests pass, build OK, lint 0 errors. No story snapshot changes. The SearchAndAddEntities story and examples now wire onSelectActionItem.

Context: raised by the GUS team (PFT Browser), who use Combobox as a lookup with "+ New" and "Show more results" rows. We haven't verified their current wiring; they may need the onSelect → onSelectActionItem migration above.


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.

`optionsSearchEntity` (header) and `optionsAddItem` (footer) items took
two different code paths. A mouse click went through option selection,
so the action item itself was sent to `onSelect` as the new selection.
Enter called the item's undocumented `onClick` and returned early,
leaving the menu open, and did nothing when no `onClick` was given.

Both inputs now go through `handleSelect`. If the item has `onClick`, it
is called with `(event, { option })`, the menu closes, and the selection
is left alone. Without `onClick`, both inputs keep the existing mouse
behavior and fire `onSelect`.

Adds an exported `ComboboxActionItem` type that documents `onClick` and
`disabled`. `ComboboxOption` is unchanged.
…r onSelect

`optionsSearchEntity` and `optionsAddItem` rows behaved differently by input
method. Clicking a row skipped the item's `onClick` and called `onSelect`
(and in single-select variants pushed the action row into `selection`),
while Enter called the item's `onClick` and skipped `onSelect`. Consumers
had to wire both paths and filter sentinel ids out of `onSelect`.

Root cause: the menu sent every row click through `handleSelect`, while
`handleInputSubmit` special-cased `type: 'header' | 'footer'` and called
`option.onClick` directly. The two paths never converged.

Action rows are now commands, not options:

- Click and Enter both go through `handleSelect`, which detects action rows
  via a module-private symbol that combobox sets only when it builds rows
  from the two props. It calls the deprecated item `onClick`
  (if any), then `events.onSelectActionItem(event, { option, value })`,
  closes the menu, and returns without touching `onSelect` or selection.
- Disabled action rows do nothing for click or Enter and render
  `aria-disabled="true"`.
- Item `onClick` is deprecated (deprecated-property warning, removal in
  v12). Its signature on `ComboboxActionItem` is widened to
  `(event: MouseEvent | KeyboardEvent, { option })`. `ComboboxOption.onClick`
  keeps its old type and its old behavior (Enter on a `type: 'header' |
  'footer'` row passed directly in `options`), and is marked `@deprecated`.

How #3242 (v11 prop-API freeze review) shaped this:

- It flags callback-presence mode switches as a smell (input-icon, pill).
  The first version of this fix used one, routing to `onSelect` only when
  `onClick` was absent. Now both handlers are dispatched independently.
- "`onSelect` is really a request." An action row is not a selection
  request, so it gets its own callback instead of overloading `onSelect`.
- It keeps Combobox's grouped `events` object. The new callback lives
  there, with the repo's `(event, data)` convention.
- Discriminated unions are preferred, and `type: ... | string` collapses
  them. Action rows are marked with a module-private symbol instead of
  another `type` string, so consumer rows in `options` (any `type`, any
  extra keys) can't be mistaken for action items.
- The controlled-`isOpen` close bug is already tracked there. This fix
  reuses `handleClose()` and leaves that bug out of scope.

The design was debated with an adversarial reviewer (Codex) over three
rounds. Round 1 changed `ComboboxOption.onClick` in place, which broke
consumer types, so the widened signature moved to `ComboboxActionItem`.
Round 2 typed the payload `option` as `ComboboxActionItem`, which hands
back the consumer's own item object. Round 3 found that a string
`actionItem` key could be spoofed by consumer data (crashing on
`actionItem: null`) and that header/footer rows passed directly in
`options` lost their Enter `onClick`. Both are fixed with regression
tests, and the deprecation test now runs against a fresh module.

BREAKING CHANGE: choosing an `optionsSearchEntity` or `optionsAddItem` row
by mouse no longer calls `onSelect` or adds the row to `selection`.
Migrate sentinel-id checks from `events.onSelect` to
`events.onSelectActionItem`. Rows that only use the item `onClick` keep
working for click and Enter, with a deprecation warning. Rows with
`type: 'header' | 'footer'` passed directly in `options` are unchanged.
@showerbee showerbee changed the title fix(combobox): make action items behave the same for mouse and keyboard fix(combobox)!: route action items to events.onSelectActionItem, never onSelect Oct 15, 2026
@interactivellama
interactivellama merged commit 63e0621 into master Oct 26, 2026
9 checks passed
@interactivellama
interactivellama deleted the fix/combobox-action-items branch October 26, 2026 23:08
interactivellama added a commit that referenced this pull request Nov 16, 2026
Everything since alpha.4 sat under [Unreleased]. Split it by release
using the CHANGELOG at each tag: each entry goes in the first release
whose tag had it, with that tag's wording. Entries first written after
alpha.10 stay under [Unreleased].

Add entries for the 18 PRs in alpha.5 to alpha.7 that shipped without
one, from their commit messages. This includes three breaking changes:
Combobox action rows moving to events.onSelectActionItem (#3243), the
discriminated-union prop types including Combobox option category
(#3252), and Badge style/styleIcon (#3256).

State how the section maps to a major/minor/patch level, and fix the
compare links to use the real tag names.
interactivellama added a commit that referenced this pull request Nov 17, 2026
Everything since alpha.4 sat under [Unreleased]. Split it by release
using the CHANGELOG at each tag: each entry goes in the first release
whose tag had it, with that tag's wording. Entries first written after
alpha.10 stay under [Unreleased].

Add entries for the 18 PRs in alpha.5 to alpha.7 that shipped without
one, from their commit messages. This includes three breaking changes:
Combobox action rows moving to events.onSelectActionItem (#3243), the
discriminated-union prop types including Combobox option category
(#3252), and Badge style/styleIcon (#3256).

State how the section maps to a major/minor/patch level, and fix the
compare links to use the real tag names.
interactivellama added a commit that referenced this pull request Nov 18, 2026
Everything since alpha.4 sat under [Unreleased]. Split it by release
using the CHANGELOG at each tag: each entry goes in the first release
whose tag had it, with that tag's wording. Entries first written after
alpha.10 stay under [Unreleased].

Add entries for the 18 PRs in alpha.5 to alpha.7 that shipped without
one, from their commit messages. This includes three breaking changes:
Combobox action rows moving to events.onSelectActionItem (#3243), the
discriminated-union prop types including Combobox option category
(#3252), and Badge style/styleIcon (#3256).

State how the section maps to a major/minor/patch level, and fix the
compare links to use the real tag names.
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