Repository navigation
[BD-11077][BpkChipGroup] add renderChip render prop for popover anchoring - #4910
Conversation
Demonstrates that BpkMultiSelectChipGroup cannot precisely anchor BpkPopover to the individual clicked chip, because chips inside the rail scroll container do not expose a ref. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds a Storybook demo story to illustrate the current anchoring limitation when using BpkPopover with BpkMultiSelectChipGroup (chips don’t expose refs inside the scroll container, so the popover can’t anchor to an individual chip).
Changes:
- Added
ChipGroupPopoverIssueStorybook story demonstrating the anchoring limitation. - Introduced story-specific styles (background image + positioning helpers) for the demo layout.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/backpack-web/src/bpk-component-chip-group/src/BpkChipGroupPopoverExample.stories.tsx | Adds a Storybook story rendering a rail chip group and a popover anchored to a workaround target element. |
| packages/backpack-web/src/bpk-component-chip-group/src/BpkChipGroupPopoverExample.stories.module.scss | Adds styling for the story layout, including a background image and popover anchor positioning. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Design for a backward-compatible composable children API on BpkMultiSelectChipGroup, enabling callers to wrap individual chips in BpkPopover for precise anchoring. Addresses the limitation demoed in PR #4910. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Remove redundant role=checkbox from story example (BpkSelectableChip
defaults role to checkbox)
- Note role is a native button attribute via {...rest}, not a chip prop
- Add shared-type risk: SingleSelectProps intersects MultiSelectProps, so
the chips XOR children union can break single-select inference; add
single-select tsc to the verification checklist
Verified against BpkPopover/BpkDropdownChip/BpkSelectableChip source and
backpack-cli props output.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
hotels-website already ships a renderChip escape hatch in its BpkChipGroup fork and uses it in production (PartnersFilter) to anchor a BpkPopover to a specific chip. Rewrite the spec to backport that mechanism (renderChip + content field + key de-dup bugfix) into official Backpack, instead of the earlier children composition API, so hotels can eventually drop its fork. Verified against the hotels fork source (BpkMultiSelectChipGroup.tsx, OfferFiltersChips.tsx, PartnersFilter.tsx) and official Backpack source. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Rewrite the spec to match colleague PR #4918's renderChip render prop: renderChip?: (props: ChipRenderProps) => ReactElement | null, where the group hands back selected / pre-wired onClick / chipStyle / accessibilityLabel / index so callers wire a custom chip (e.g. a popover-anchored chip) without rebuilding default bindings. Drop the content field entirely: content renders inside the chip button so it cannot host a popover, and it serves a separate rich-text-chip need. Add ChipRenderProps barrel export, WithPopover story, and the test/README/ cleanup follow-ups PR #4918 left unchecked. Verified against PR #4918 diff and official Backpack source. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
PR #4918 is a POC that will not merge; use it only as the API design reference. The spec now covers the complete implementation independently (prop, type, story, tests, README, cleanup) with no dependency on #4918 landing. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
PR #4918 branch was updated with two changes now folded into the spec: - forwardRef on BpkSelectableChip and BpkDropdownChip: BpkPopover injects its ref via cloneElement(target, {ref}), so a chip used as a popover target must forward that ref to its underlying button, otherwise floating-ui gets null and anchoring still fails. This is a hard prerequisite in bpk-component-chip, previously missing from the spec. - showArrow={false} in the WithPopover story. Expands scope, changed-files, tests, and verification to cover the bpk-component-chip package. Verified against the latest PR #4918 diff. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Task-by-task TDD plan implementing the renderChip spec: forwardRef on BpkSelectableChip + BpkDropdownChip (popover-anchoring prerequisite), ChipRenderProps type + renderChip render prop + Chip render branch, barrel export, WithPopover story, README, and a full verification pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Reviewed the plan against the real worktree, not assumptions. Fixes: - jest: pnpm jest -> pnpm exec jest (root jest script forces --coverage with a 70-75% global threshold that fails single-file runs; pnpm exec invokes the binary with no coverage gate — verified 17 passed clean). - tsc: pnpm tsc --noEmit -p tsconfig.json -> pnpm tsc -b tsconfig.lib.json. tsconfig.json has empty files/include and only references, so -p checks nothing (false pass); tsconfig.lib.json is composite (needs -b build mode) and is the real source config — verified exit 0. - eslint: documented a KNOWN worktree BLOCKER — worktree .eslintrc lacks root:true, so eslint loads main repo ../../../.eslintrc and dies on an @nx/eslint-plugin collision (even repo's own lint:js fails). Added Task 0 preflight and caveats on every lint step. Also verified every embedded current-code block matches source exactly (SelectableChip ends in }; , button first attr is aria-checked; DropdownChip body matches the replacement block). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The plan previously only eyeballed Storybook manually. Since the whole point of this feature is visual popover anchoring (which jest/tsc cannot verify), Task 7 Step 4 now drives Chrome DevTools MCP: start Storybook on port 9001, open the WithPopover iframe (id=bpk-component-chip-group--with-popover), click chips, screenshot to confirm each popover anchors beneath its own chip, check a pre-existing story for regressions, and save screenshots for the PR. Manual fallback kept for when the MCP is unavailable. Port and story id verified against package.json and the stories meta. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
| selected: selected ?? false, | ||
| chipStyle, | ||
| accessibilityLabel: accessibilityLabel || text, | ||
| onClick: handleClick, | ||
| index: chipIndex, |
There was a problem hiding this comment.
It's best to pass all chip props to the renderChip function to prevent omissions. You can define a variable to ensure that the props passed to CHIP_COMPONENT_MAP[component] and renderChip are the same.
const chipProps = {
selected: selected ?? false,
type: chipStyle,
accessibilityLabel: accessibilityLabel || text,
onClick: handleClick,
role: ariaMultiselectable ? 'checkbox' : 'radio'
leadingAccessoryView
...rest
}
if (renderChip) {
return renderChip(chipProps);
}
const Component = CHIP_COMPONENT_MAP[component];
return (
<Component {...chipProps}>{text}</Component>
)
There was a problem hiding this comment.
Good suggestion — extracted a shared chipRenderProps variable that both the renderChip path and the default Component path use, so future additions to ChipRenderProps automatically apply to both. Fixed in da9aca3.
| }: Props) => ( | ||
| }, ref) => ( | ||
| <BpkSelectableChip | ||
| ref={ref} |
There was a problem hiding this comment.
any reason to add ref here?
There was a problem hiding this comment.
Popover need a ref to control the target. But i found we can use BpkVessel. So i revert the change at this file.
| [rest: string]: any; // Inexact rest. See decisions/inexact-rest.md | ||
| }; | ||
|
|
||
| export type ChipRenderProps = { |
There was a problem hiding this comment.
renderChip drops the group's a11y role. The default path sets role={ariaMultiselectable ? 'checkbox' : 'radio'}, but the renderChip path passes no role and ChipRenderProps doesn't expose one — so callers can't reproduce it. The container is still radiogroup/group, so its children need the matching role. Worst in single-select (ariaMultiselectable={false} → radiogroup) where a custom chip stays non-radio.
Suggest adding role: 'checkbox' | 'radio' to ChipRenderProps (derived from ariaMultiselectable) + a single-select test asserting role="radio".
There was a problem hiding this comment.
Good catch! Added role: 'checkbox' | 'radio' to ChipRenderProps (derived from ariaMultiselectable), along with a test asserting role="radio" in single-select context. Fixed in da9aca3.
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
…ChipRenderProps" This reverts commit aab06a8.
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
| hidden?: boolean; | ||
| } & SingleSelectChipItem; | ||
|
|
||
| export type ChipRenderProps = Omit<ChipItem, 'component' | 'renderChip' | 'onClick' | 'accessibilityLabel' | 'leadingAccessoryView'> & { |
There was a problem hiding this comment.
ChipRenderProps now derives from Omit<ChipItem, ...>, but ChipItem carries the [rest: string]: any index signature via SingleSelectChipItem, and Omit preserves that index signature. As a result ChipRenderProps effectively accepts any key (all resolved as any), so it provides almost no type safety — the story below references chipStyle/index, which no longer exist on this type, yet tsc doesn't catch it for exactly this reason. Suggest making this a standalone type with only the explicit fields so renderChip consumers get real type checking.
There was a problem hiding this comment.
Good catch — introduced a ChipBaseProps type that holds the explicit fields (text, accessibilityLabel, leadingAccessoryView, selected, hidden). Both SingleSelectChipItem (which carries the index signature) and ChipRenderProps now extend ChipBaseProps independently, so ChipRenderProps gets the shared fields without inheriting [rest: string]: any. Fixed in 6461ffe.
|
|
||
| const makePopoverRenderChip = | ||
| (label: string) => | ||
| ({ accessibilityLabel, chipStyle, index, onClick, selected }: ChipRenderProps) => |
There was a problem hiding this comment.
This destructures chipStyle and index, but the refactored ChipRenderProps only provides type — chipStyle/index no longer exist (only the inexact rest signature lets this pass tsc). At runtime: index is undefined, so all four popovers get id="popover-chip-undefined" (line 459) → duplicate DOM ids; and chipStyle is undefined, so BpkDropdownChip (line 471) falls back to the default type and ignores the group's chipStyle. Since this story is the demo for anchoring a popover to a specific chip, it needs to switch to type and use a stable id source (either add index back to ChipRenderProps, or derive the id from text/label).
There was a problem hiding this comment.
Fixed — story now uses type (instead of chipStyle) and label as the stable id source (instead of index). Fixed in b07d714.
| {...rest} | ||
| > | ||
| return ( | ||
| <Component {...chipRenderProps}> |
There was a problem hiding this comment.
(Optional) {...chipRenderProps} also spreads text, which BpkSelectableChip doesn't destructure, so it leaks as an invalid <button text="..."> attribute. Suggest excluding text here. Non-blocking — DOM noise only, no functional impact.
There was a problem hiding this comment.
Fixed — text is now destructured out before spreading chipRenderProps onto Component, so it no longer leaks as a DOM attribute. Fixed in b07d714.
|
Visit https://backpack.github.io/storybook-prs/4910 to see this build running in a browser. |
Summary
BpkSelectableChipandBpkDropdownChipinforwardRefsoBpkPopovercan obtain the chip's<button>DOM node for anchoringrenderChip?: (props: ChipRenderProps) => ReactElement | nulltoChipIteminBpkMultiSelectChipGroup— lets callers replace per-chip rendering (e.g. wrapping inBpkPopover) while the group still providesselected,chipStyle,accessibilityLabel,onClick, andindexChipRenderPropsfrom the package barrel; add aWithPopoverStorybook story demonstrating per-chip popover anchoring; remove the old standalone popover demoTest plan
pnpm exec jest packages/backpack-web/src/bpk-component-chip packages/backpack-web/src/bpk-component-chip-group— 103 tests, all passpnpm tsc -b packages/backpack-web/tsconfig.lib.json— no errorsWithPopoverstory: click "Flights" → popover anchors below Flights chip; click "Trains" → popover anchors below Trains chip (per-chip tracking verified)on-imagestory renders correctly (no regression)