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

[BD-11077][BpkChipGroup] add renderChip render prop for popover anchoring - #4910

Merged
Iris Li (wpe1arhy) merged 30 commits into
mainfrom
worktree-example-chip-group-popover
Jul 24, 2026
Merged

Iris Li (wpe1arhy) merged 30 commits into
mainfrom
worktree-example-chip-group-popover

Conversation

@LuoTuxiu

@LuoTuxiu tuxiu.luo (LuoTuxiu) commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Wrap BpkSelectableChip and BpkDropdownChip in forwardRef so BpkPopover can obtain the chip's <button> DOM node for anchoring
  • Add renderChip?: (props: ChipRenderProps) => ReactElement | null to ChipItem in BpkMultiSelectChipGroup — lets callers replace per-chip rendering (e.g. wrapping in BpkPopover) while the group still provides selected, chipStyle, accessibilityLabel, onClick, and index
  • Export ChipRenderProps from the package barrel; add a WithPopover Storybook story demonstrating per-chip popover anchoring; remove the old standalone popover demo
new

Test plan

  • pnpm exec jest packages/backpack-web/src/bpk-component-chip packages/backpack-web/src/bpk-component-chip-group — 103 tests, all pass
  • pnpm tsc -b packages/backpack-web/tsconfig.lib.json — no errors
  • Storybook WithPopover story: click "Flights" → popover anchors below Flights chip; click "Trains" → popover anchors below Trains chip (per-chip tracking verified)
  • Pre-existing on-image story renders correctly (no regression)

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

Copy link
Copy Markdown
Contributor

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 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 ChipGroupPopoverIssue Storybook 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.

tuxiu.luo (LuoTuxiu) and others added 15 commits July 21, 2026 10:37
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]>
@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 b07d714

@LuoTuxiu tuxiu.luo (LuoTuxiu) changed the title [NOJIRA] Add BpkChipGroup + BpkPopover anchoring limitation story [BpkChipGroup] add renderChip render prop for popover anchoring Jul 22, 2026
@LuoTuxiu tuxiu.luo (LuoTuxiu) added the minor Non breaking change label Jul 22, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@LuoTuxiu tuxiu.luo (LuoTuxiu) changed the title [BpkChipGroup] add renderChip render prop for popover anchoring [BD-11077][BpkChipGroup] add renderChip render prop for popover anchoring Jul 22, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

Comment on lines +143 to +147
selected: selected ?? false,
chipStyle,
accessibilityLabel: accessibilityLabel || text,
onClick: handleClick,
index: chipIndex,

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.

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>
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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}

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.

any reason to add ref here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 = {

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.

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@wpe1arhy Iris Li (wpe1arhy) 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.

LGTM

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

hidden?: boolean;
} & SingleSelectChipItem;

export type ChipRenderProps = Omit<ChipItem, 'component' | 'renderChip' | 'onClick' | 'accessibilityLabel' | 'leadingAccessoryView'> & {

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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) =>

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.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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}>

@wpe1arhy Iris Li (wpe1arhy) Jul 24, 2026 •

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.

(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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — text is now destructured out before spreading chipRenderProps onto Component, so it no longer leaks as a DOM attribute. Fixed in b07d714.

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@wpe1arhy Iris Li (wpe1arhy) 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.

LGTM

@wpe1arhy
Iris Li (wpe1arhy) merged commit 8718148 into main Jul 24, 2026
15 checks passed
@wpe1arhy
Iris Li (wpe1arhy) deleted the worktree-example-chip-group-popover branch July 24, 2026 09:51
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.

4 participants