Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.

[BpkChipGroup] POC: renderChip render prop for custom subcomponents - #4918

Closed
Gert-Jan Vercauteren (gert-janvercauteren) wants to merge 5 commits into
mainfrom
gert-janvercauteren/chip-group-custom-subcomponents-poc
Closed

Gert-Jan Vercauteren (gert-janvercauteren) wants to merge 5 commits into
mainfrom
gert-janvercauteren/chip-group-custom-subcomponents-poc

Conversation

@gert-janvercauteren

Copy link
Copy Markdown
Contributor

Summary

Adds an optional renderChip prop to ChipItem that lets callers supply a custom render function for individual chip slots in BpkMultiSelectChipGroup. When renderChip is provided, the group delegates leaf rendering to the caller instead of picking from the internal CHIP_COMPONENT_MAP. This is a POC to support attaching a BpkPopover (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 WithPopover Storybook story demonstrates the pattern: two chips render normally via the data-driven API, and one chip uses renderChip to wrap a BpkDropdownChip inside a BpkPopover anchored to that chip. The new ChipRenderProps type is exported from the package barrel for consumer use.

Remember to include the following changes:

  • Ensure the PR title includes the name of the component you are changing so it's clear in the release notes for consumers of the changes in the version e.g [Clover-123][BpkButton] Updating the colour
  • README.md (If you have created a new component)
  • Component README.md
  • Tests
  • Accessibility tests
    • The following checks were performed:
      • Ability to navigate using a keyboard only
      • Zoom functionality (Deque University explanation):
        • The page SHOULD be functional AND readable when only the text is magnified to 200% of its initial size
        • Pages must reflow as zoom increases up to 400% so that content continues to be presented in only one column i.e. Content MUST NOT require scrolling in two directions (both vertically and horizontally)
      • Ability to navigate using a screen reader only
  • Storybook examples created/updated (WithPopover story added)
  • For breaking changes or deprecating components/properties, migration guides added to the description of the PR. If the guide has large changes, consider creating a new Markdown page inside the component's docs folder and link it here

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]>
Copilot AI review requested due to automatic review settings July 22, 2026 03:19
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

skyscanner-backpack-bot Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor
Warnings
⚠️

Package source files (e.g. packages/package-name/src/Component.js) were updated, but snapshots weren't. Have you checked that the tests still pass?

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against 13430b2

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ChipRenderProps plus an optional renderChip prop on ChipItem.
  • Updates chip rendering to delegate to renderChip when provided (otherwise uses CHIP_COMPONENT_MAP).
  • Adds a WithPopover Storybook 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.

Comment on lines +139 to +147
if (renderChip) {
return renderChip({
selected: selected ?? false,
chipStyle,
accessibilityLabel: accessibilityLabel || text,
onClick: handleClick,
index: chipIndex,
});
}
Comment on lines +72 to +78
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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

tuxiu.luo (LuoTuxiu) added a commit that referenced this pull request Jul 22, 2026
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]>
tuxiu.luo (LuoTuxiu) added a commit that referenced this pull request Jul 22, 2026
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]>
tuxiu.luo (LuoTuxiu) added a commit that referenced this pull request Jul 22, 2026
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]>
Iris Li (wpe1arhy) pushed a commit that referenced this pull request Jul 24, 2026
…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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

minor Non breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants