Repository navigation
feat!: type child and slot contracts and add a trigger prop - #3272
Conversation
| */ | ||
| children?: ReactNode; | ||
| children?: ChildrenOf< | ||
| BuilderHeaderNavLinkProps | BuilderHeaderNavDropdownProps |
There was a problem hiding this comment.
Many of these child types make sense and maybe we hint at this options and add a @Niznikr| ReactNode to the end. I would expect a consumer to want to put their own type of children in the navigation or the builder editor.
We may want to remove this typing for BuilderHeader
Never mind. I saw the displayName check in the old code It's only BuilderHeaderMisc that accepts non-specific components. These others should be typed.
|
@Niznikr We will want to pull back on using props for the triggers for the dialog-using element. For instance, in a first-time UX walkthrough, the Popover could be attached to a non-button in order to tell the user what the Card org toolbar does. |
Prettier only, so the functional commits that follow show just the behavior changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- isElementOfType matches a child by component reference instead of displayName, and narrows its props type - ChildrenOf<P> types children that must be elements of a component - mergeProps merges a component's props into a consumer element's: consumer props win, handlers and refs are composed (consumer first), className and aria-describedby/labelledby are joined without duplicates, and style objects are merged - renderTrigger renders a TriggerRender slot: an element (merged with mergeProps) or a function that receives the trigger props - warning/children-as-trigger warns once when a trigger is passed as children Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tooltip and MenuDropdown take a trigger prop. An element is merged with the component's trigger props through mergeProps, so the consumer's props win, its handlers run before the component's, and className/aria-describedby are joined. A function receives the trigger props (TooltipTriggerProps, MenuDropdownTriggerProps) for full control. For MenuDropdown, a Button element takes the dropdown's button props as defaults. Root cause of the old behavior: both components cloned their trigger child and overwrote the props they needed, so a trigger lost its own handlers and aria-describedby. The trigger passed as children (and the MenuDropdown DropdownTrigger child) still works, goes through the same merge, and warns once. Popover keeps its children: the wrapped element is what the popover attaches to, which need not be a button (for example a walkthrough step on a toolbar). Also: - MenuDropdown matches List and Button children by reference, and custom content keeps a stable key instead of remounting each render - Tooltip no longer throws when given several children - TrialBarDropdown passes its children to the menu - Library uses (button, progress-indicator, builder-header nav, menu-list, trial-bar) and the examples and stories use trigger BREAKING CHANGE: Tooltip and MenuDropdown merge trigger props instead of overwriting them. The trigger's own handlers now run, before the component's; its aria-describedby is joined with Tooltip's; and its className is joined with MenuDropdown's. Passing the trigger as children is deprecated in favor of trigger. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Parents that read or clone their children (accordion, alert, builder-header, button-group, files, input, page-header controls, panel filter list, radio-group, radio-button-group, scoped-notification, setup-assistant, simple-data-table, tabs, toast, visual-picker, welcome-mat) now type the children they accept, keep the props they inject in internal *InjectedProps types, and find children with isElementOfType instead of comparing displayName. Root causes of the bugs fixed along the way: - PanelFilterList gave an errored filter without an id no id, so the filter's aria-describedby pointed at a missing error element - ButtonGroup marked the last child by index over all children, so a trailing null/false child left the real last button unmarked - ScopedNotification spread the icon's assistiveText as an object, so a string one was lost - SimpleDataTable required custom cells to copy the cell displayName, counted conditional (false) columns for keyboard navigation, and overwrote a consumer RowActions menuPosition in fixedHeader tables - RadioGroup and VisualPicker cloned name over the child's own, and RadioGroup replaced the child's aria-describedby with its error id Filter declares errorLabel, which PanelFilterList already reads. TabChildProps and FileChildProps are deprecated aliases of TabsPanelProps and FileProps. BREAKING CHANGE: Children and slots are typed as the library components they accept (e.g. Alert and Toast icon as ReactElement<IconProps>), and injected props are no longer part of the public child types. BuilderHeader, MenuDropdown, PageHeader controls, SetupAssistant and SimpleDataTable no longer treat a component that copies a library component's displayName as that component. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The three element props are typed as the library components they take
(ReactElement<Partial<PopoverProps>>, ReactElement<Partial<InputProps>>,
ReactElement<Partial<TooltipProps>>), and their props win over the
combobox's defaults. The disabled-item tooltip gets its trigger through
trigger instead of children.
Root cause of the onChange bug: the input element's props were spread
last onto the private InnerInput, so an Input-style
onChange(event, { value }) replaced the combobox's handler and got a
native call. It is now wrapped: called with (event, { value }), then the
combobox's own handler runs.
BREAKING CHANGE: popover, input and tooltipMenuItemDisabled are typed as
Popover, Input and Tooltip elements, and the input's onChange runs
alongside the combobox's handler with (event, { value }).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A walkthrough step points at part of the page, such as a Card's toolbar, rather than at a button that opens it. Popover always cloned its first child with id, aria-haspopup, tabIndex and click/hover handlers, which made such an anchor focusable, announced it as opening a dialog, and toggled the step when the user clicked it. With openOn="none" the first child is only an anchor: Popover positions against it and adds nothing to it, and the parent opens and closes the popover through isOpen. Other openOn values behave as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CHANGELOG entries for the trigger prop and the typed child contracts, the theme 3 status and per-component notes in ROADMAP.md (including the decision to keep Popover's children as its anchor), and the utilities to use in the codebase overview. Co-Authored-By: Claude Opus 5.5 <[email protected]>
c641faf to
9175674
Compare
| * child gets `slds-button_last` added to its `triggerClassName`. Checkbox children default | ||
| * to `variant="button-group"` and are described by `labels.error`. | ||
| */ | ||
| children: ChildrenOf<ButtonProps | MenuDropdownProps | CheckboxProps>; |
There was a problem hiding this comment.
A Tooltip wrapped button might be likely.
|
A related trigger props thread in Base UI's issues. mui/base-ui#3983 |
* docs: update roadmap P1 status and drop the boolean renames Tick the completed P1 items (entry points, release tag format) and bump the status line to 11.0.0-alpha.8. Remove the Booleans theme and the per-component is*/has* rename findings, which were cancelled for v11. * docs: tick roadmap items removed in #3248 The deprecated-surface removal in 11.0.0-alpha.6 closed InlineEdit, ModalTrigger, the forms/checkbox and tabs/pane aliases, and the string assistiveText forms. Tick those items and trim the finished parts from the mixed ones. * docs: update roadmap status against master after #3272 Tick items fixed on master, add partly-done notes, merge #3272's roadmap changes and bump the version to 11.0.0-alpha.10.
What changed
triggerprop onTooltipandMenuDropdown. It takes either:TooltipTriggerProps/MenuDropdownTriggerProps, for full control.When you pass an element, the consumer's props win, the consumer's handlers run first, and
className/aria-describedby/aria-labelledbyare joined. AButtonpassed toMenuDropdowntakes the dropdown's button props as defaults. Passing the trigger aschildren(or as aDropdownTriggerchild) still works, goes through the same merge, and warns once (utilities/warning/children-as-trigger).Popover keeps its
children(maintainer decision). The first child is the element the popover attaches to, which need not be a button (for example a walkthrough step pointing at a Card's toolbar), so Popover gets notriggerprop and its trigger handling is unchanged. NewopenOn="none"makes the first child only an anchor: Popover positions against it and adds nothing to it (noid,aria-haspopup,tabIndexor handlers), and the parent opens and closes it throughisOpen.Typed library-component children. These components now type the children they accept and keep the props they inject in internal
*InjectedPropstypes: accordion, alert, builder-header, button-group, files, input, page-header controls, panel filter list, radio-group, radio-button-group, scoped-notification, setup-assistant, simple-data-table, tabs, toast, visual-picker and welcome-mat. Children that were found bydisplayNameare now matched by reference withisElementOfType.Combobox
popover/input/tooltipMenuItemDisabledare typed and the consumer's props win.input'sonChangeis wrapped so both handlers run. The disabled-item tooltip gets its trigger throughtrigger.Filter declares
errorLabel, whichPanelFilterListalready reads.New utilities:
utilities/is-element-of-type,utilities/merge-props(mergeProps,renderTrigger,TriggerRender) andChildrenOf<P>intypes/common.Breaking changes (each has a
BREAKING CHANGE:footer in its commit):aria-describedbyis joined with Tooltip's, and itsclassNameis joined with MenuDropdown's. Passing the trigger aschildrenis deprecated in favor oftrigger.Alert/ToasticonasReactElement<IconProps>). Injected props are no longer in the public child types.displayNameas that component.popover,inputandtooltipMenuItemDisabledare typed as Popover, Input and Tooltip elements, and the input element'sonChangeruns alongside the combobox's handler, called with(event, { value }).Popover is not breaking: its children contract and trigger behavior are unchanged, and
openOn="none"is additive.Migration:
<Tooltip …><Button/></Tooltip>with<Tooltip … trigger={<Button/>} />.<MenuDropdown …><DropdownTrigger><Button/></DropdownTrigger></MenuDropdown>with<MenuDropdown … trigger={<Button/>} />.openOn="none"and controlisOpen.displayName. Wrap the library component instead (see the SimpleDataTable examples).TabChildProps(useTabsPanelProps) andFileChildProps(useFileProps).Bugs fixed: root causes and regression tests
Tooltip / MenuDropdown triggers lost their own
onFocus/onMouse*/onClickhandlers andaria-describedby. The components cloned the child and overwrote those props. Tooltip also threw when given several children. Tests:tooltip-trigger.test.jsx,menu-dropdown-trigger.test.jsx.Popover: a walkthrough step on a non-interactive anchor made it focusable, announced it as opening a dialog, and toggled the step on click. Popover always cloned its first child with
id,aria-haspopup,tabIndexand open handlers. Fixed withopenOn="none". Test:popover-anchor.test.jsx.MenuDropdown custom content remounted on every render. Each child was cloned with
key: generateId(), a new key every time. Test:menu-dropdown-trigger.test.jsx(fails against the old key).PanelFilterList: an errored filter with no
idhad a danglingaria-describedby. The list rendered the error under its own generated id but didn't pass that id to the filter. Test:panel-filter-list.test.jsx.ButtonGroup: with a trailing
null/falsechild, the real last button wasn't markedslds-button_last. The last child was picked by index overChildren.count, which counts empty children. Test:button-group-children.test.jsx.ScopedNotification: a string
assistiveTexton theiconelement was lost. It was spread as an object. Test:scoped-notification.test.jsx.SimpleDataTable:
displayNamefalse) columns were counted for keyboard navigationRowActionsmenuPositionwas overwritten infixedHeadertablesTest:
simple-data-table-children.test.jsx.RadioGroup / VisualPicker overwrote a child's
name, and RadioGroup also replaced the child'saria-describedbywith its error id. Tests:radio-group-children.test.jsx,visual-picker-children.test.jsx.Combobox: the
inputelement'sonChangereplaced the combobox's handler and got a native-style call. The input's props were spread last onto the privateInnerInput. Test:combobox-slots.test.jsx.Reference matching and utilities are covered by
builder-header-children,setup-assistant-children,files,merge-propsandchildren-as-triggertests.Snapshot diff: 7 changed lines and one new story.
Buttontriggers now keep the dropdown'signore-click-*class, becauseclassNameis joined instead of replaced.openOn="none"on a Card toolbar).All other story markup is unchanged.
Examples and stories migrated from a children trigger to
trigger(before: trigger passed aschildrenor aDropdownTriggerchild; after:triggerprop on Tooltip or MenuDropdown). A scan of all examples and stories finds no remaining Tooltip or MenuDropdown children triggers. Popover examples are unchanged.components/builder-header/__docs__/BuilderHeader.stories.jsxcomponents/builder-header/__examples__/after-successful-save.jsxcomponents/builder-header/__examples__/base-with-page-type-editable.jsxcomponents/builder-header/__examples__/failed-save.jsxcomponents/menu-dropdown/__docs__/MenuDropdown.stories.tsxcomponents/menu-dropdown/__examples__/custom-trigger.jsxcomponents/page-header/__examples__/object-home.jsxcomponents/page-header/__examples__/related-list.jsxcomponents/simple-data-table/__examples__/joined-with-page-header.jsxcomponents/split-view/__examples__/base-multiple.jsxcomponents/split-view/__examples__/base.jsxcomponents/split-view/__examples__/custom-items-list.jsxcomponents/split-view/__examples__/external-state.jsxcomponents/tooltip/__docs__/Tooltip.stories.jsxcomponents/tooltip/__examples__/button-group.jsxcomponents/tooltip/__examples__/button.jsxOther example and story changes:
SimpleDataTableCell.displayNameonto their custom cell, because cells are matched by reference.Combobox.stories.tsxPopoverVariant: thepopoverelement drops its{null}children.Popover.stories.jsx: adds WalkthroughOnAnchor.Still open (noted in ROADMAP.md):
labelfromButtonGroupchildren, which isn't aButtonGrouppropcheck-props.jsis never calledisTriggerTabbablestill guesses fromdisplayNameMENU_DROPDOWN_TRIGGERlookup for custom trigger templates until the deprecated child trigger is removedCommits:
style:Prettier-only formatting of the touched filestriggerprop (Tooltip, MenuDropdown)openOn="none"Local runs:
npm run test:cipasses (1539 tests; lint has 0 errors and no new warnings in the files this PR adds).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 lintpasses with 0 errors (npm run lint:fixto auto-fix). Warnings are the tracked gradual-migration backlog; do not add new errors.npm run typecheckis clean (tsc --noEmit).npm test -- --runpasses — this runs both Vitest projects (jsdomunit+ real-browserbrowser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots withnpm test -- --run -uand review the diff.npm run buildsucceeds (type-check + Vite library build +.d.ts+ entry shims).Behavior & docs:
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.jsxfile (thebrowserproject); everything else is jsdom.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).content/visualPickerFigure, render props likerenderItem,iconprops,events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check againstcomponents/<name>/__examples__..d.ts(they're generated by the build); JS consumers rely on them via editor type-acquisition.REVIEWER checklist (do not remove)
CIworkflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).@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.