Repository navigation
[BpkChipGroup] POC: renderChip render prop for custom subcomponents - #4918
Gert-Jan Vercauteren (gert-janvercauteren) wants to merge 5 commits into
Conversation
Adds an optional renderChip prop to ChipItem so callers can supply their own render function for individual chip slots. This enables attaching a BpkPopover (or any other component) directly to a chip rather than to the group root, fixing incorrect popover positioning. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4918 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 renderChip render-prop escape hatch to ChipItem so consumers of BpkMultiSelectChipGroup can fully control rendering for individual chip slots (e.g. anchor a BpkPopover to a specific chip), and demonstrates usage via a new Storybook example.
Changes:
- Introduces and exports
ChipRenderPropsplus an optionalrenderChipprop onChipItem. - Updates chip rendering to delegate to
renderChipwhen provided (otherwise usesCHIP_COMPONENT_MAP). - Adds a
WithPopoverStorybook story demonstrating a popover anchored to a single chip.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| packages/backpack-web/src/bpk-component-chip-group/src/BpkMultiSelectChipGroup.tsx | Adds renderChip support and ChipRenderProps for custom chip rendering. |
| packages/backpack-web/src/bpk-component-chip-group/src/BpkChipGroup.stories.tsx | Adds WithPopover story demonstrating per-chip custom rendering with BpkPopover. |
| packages/backpack-web/src/bpk-component-chip-group/index.ts | Re-exports ChipRenderProps from the package barrel. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (renderChip) { | ||
| return renderChip({ | ||
| selected: selected ?? false, | ||
| chipStyle, | ||
| accessibilityLabel: accessibilityLabel || text, | ||
| onClick: handleClick, | ||
| index: chipIndex, | ||
| }); | ||
| } |
| export type ChipRenderProps = { | ||
| selected: boolean; | ||
| chipStyle: ChipStyleType; | ||
| accessibilityLabel: string; | ||
| onClick: () => void; | ||
| index: number; | ||
| }; |
| return renderChip({ | ||
| selected: selected ?? false, | ||
| chipStyle, | ||
| accessibilityLabel: accessibilityLabel || text, |
|
|
||
| export type ChipItem = { | ||
| component?: ChipComponentType; | ||
| renderChip?: (props: ChipRenderProps) => ReactElement | null; |
Each chip in the story now uses renderChip to wrap a BpkDropdownChip inside a BpkPopover anchored to the bottom of that individual chip. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4918 to see this build running in a browser. |
BpkPopover uses cloneElement to attach a floating-ui ref to its target element. Without forwardRef on BpkSelectableChip the ref was silently dropped, leaving floating-ui with no anchor and causing the popover to render in the wrong position when a chip is used as the target. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4918 to see this build running in a browser. |
BpkPopover applies a floating-ui positioning ref via cloneElement on its target. BpkDropdownChip was a plain function component so React dropped the ref before it reached BpkSelectableChip, leaving the popover unanchored. Forwarding the ref through to BpkSelectableChip fixes popover positioning when a BpkDropdownChip is used as a popover target. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4918 to see this build running in a browser. |
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]>
…ring (#4910) * [NOJIRA] Add BpkChipGroup + BpkPopover anchoring limitation story 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]> * docs: add BpkChipGroup children API design spec 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]> * docs: refine chip-group children spec after source verification - 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]> * docs: rewrite chip-group spec to backport renderChip from hotels fork 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]> * docs: align chip-group spec to PR 4918 renderChip, drop content 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]> * docs: clarify PR 4918 is design reference only, spec is full impl 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]> * docs: sync spec with updated PR 4918 branch (forwardRef + showArrow) 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]> * docs: add chip-group renderChip implementation plan 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]> * docs: correct chip-group plan commands after empirical verification 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]> * docs: use Chrome DevTools MCP for Storybook anchoring verification 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]> * [BpkChip] forward ref to button in BpkSelectableChip * [BpkChip] forward ref to button in BpkDropdownChip * [BpkChipGroup] add renderChip render prop and ChipRenderProps * [BpkChipGroup] export ChipRenderProps from package barrel * [BpkChipGroup] add WithPopover story, remove standalone popover demo * [BpkChipGroup] document renderChip popover-anchoring usage * chore: remove superpowers docs (not for PR) * [BpkChipGroup] use sticky chip group rail in WithPopover story * [BpkChipGroup] add 8px gap between popover and chip in WithPopover story * [BpkChipGroup] wire up onClick and sticky chip selection in WithPopover story * chore: revert README renderChip docs * [BpkChip] revert forwardRef, use BpkVessel wrapper in WithPopover story instead * chore: restore chip test files to main state * [BpkChipGroup] add role to ChipRenderProps, extract chipRenderProps variable * [BpkChipGroup] redefine ChipRenderProps as Omit<ChipItem> extension * [BpkChipGroup] keep onClick type consistent with ChipItem in ChipRenderProps * Revert "[BpkChipGroup] keep onClick type consistent with ChipItem in ChipRenderProps" This reverts commit aab06a8. * [BpkChipGroup] normalize ChipRenderProps types, simplify Component spread * [BpkChipGroup] introduce ChipBaseProps to share fields without index signature * [BpkChipGroup] fix story renderChip props, exclude text from Component spread --------- Co-authored-by: Claude Sonnet 4.6 (1M context) <[email protected]>
Summary
Adds an optional
renderChipprop toChipItemthat lets callers supply a custom render function for individual chip slots inBpkMultiSelectChipGroup. WhenrenderChipis provided, the group delegates leaf rendering to the caller instead of picking from the internalCHIP_COMPONENT_MAP. This is a POC to support attaching aBpkPopover(or any other component) directly to a chip rather than the group root, which fixes incorrect popover positioning when used inside a chip group.A
WithPopoverStorybook story demonstrates the pattern: two chips render normally via the data-driven API, and one chip usesrenderChipto wrap aBpkDropdownChipinside aBpkPopoveranchored to that chip. The newChipRenderPropstype is exported from the package barrel for consumer use.Remember to include the following changes:
[Clover-123][BpkButton] Updating the colourREADME.md(If you have created a new component)README.mdWithPopoverstory added)