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

[BpkContextMenu] Context Menu Stories and Implementation - #4913

Merged
Ezreal Yang (Supremeyh) merged 18 commits into
mainfrom
CAPY-2348/context-menu-component
Jul 29, 2026
Merged

Ezreal Yang (Supremeyh) merged 18 commits into
mainfrom
CAPY-2348/context-menu-component

Conversation

@tranculent

@tranculent Yanko Mirov (tranculent) commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a new BpkContextMenu compound component wrapping Ark UI's Menu primitive, with accessible keyboard navigation, focus management, ARIA semantics, and floating positioning out of the box.

For Backpack reviewers

New component: BpkContextMenu

Namespaced compound API:

Part Purpose
.Root State container — open state, keyboard navigation, selection dispatch. unmountOnExit removes the portal from the DOM after the close animation.
.Trigger Generic trigger. Renders a plain <button> by default; asChild (requires forwardRef child) merges trigger props onto a custom element.
.SaveTrigger Pre-styled circular heart-icon trigger for the save-to-list pattern. No consumer styling required.
.Content Floating menu surface. Portalled, overflow-x: hidden so long names truncate with ellipsis.
.Item Selectable row — endIcon, destructive variant, onSelect (fires for pointer and keyboard via Ark's state machine — not a DOM onClick).
.ItemGroup Visual grouping container. Renders role="group" (plain <div> intentional — Menu.ItemGroup would emit a dangling aria-labelledby without a paired label).
.Separator Horizontal rule between groups.
.TriggerItem Row that opens a nested sub-menu on hover / arrow-right.

Architecture decisions

  • BpkContextMenu.SaveTrigger owns the heart-button visual entirely within this package — no dependency on BpkSaveButton as an Ark asChild trigger
  • Focus ring suppression on close is handled by useMenuTriggerFocusGuard (shared hook on both Trigger and SaveTrigger): tracks pointer vs keyboard interactions via capture-phase pointerdown/keydown listeners; suppresses :focus-visible after pointer-initiated close, preserves it for Tab/Escape keyboard navigation; also checks relatedTarget when focus returns from inside [role="menu"]
  • unmountOnExit on Menu.Root removes the content from the DOM after the close animation, preventing the invisible positioner from blocking pointer events
  • Ghost hover on open (cursor physically over item when menu appears) suppressed with a bpk-context-menu-item-hover-guard keyframe animation — CSS animations take cascade precedence over :hover, so items stay transparent for the ~200ms open animation, then normal hover resumes
  • All colour tokens migrated to CSS custom properties (var(--bpk-surface-elevated, ...), var(--bpk-text-primary, ...), etc.) for light/dark mode support
  • z-index uses tokens.$bpk-zindex-popover (900), consistent with tooltips and popovers
  • Bare :hover replaced with @include utils.bpk-hover to gate hover behind .bpk-no-touch-support

BpkSaveButton — no functional changes

The initial draft composed BpkSaveButton as an Ark asChild trigger, which required adding forwardRef, onClick, and focus-ring overrides. That approach was abandoned in favour of BpkContextMenu.SaveTrigger. BpkSaveButton is unchanged from its pre-PR state.

ESLint: Menu.Trigger and Menu.TriggerItem added to the forbid-component-props allowlist.

Storybook + unit + accessibility tests included. ResizeObserver stubbed in tests (Floating UI's autoUpdate uses it; JSDOM doesn't ship it). axe scans document.body to catch portalled content.

Consumer usage

// has lists → context menu
<BpkContextMenu.Root onSelect={({ value }) => handleSelect(value)}>
  <BpkContextMenu.SaveTrigger aria-label="Save to trip" />
  <BpkContextMenu.Content>
    <BpkContextMenu.ItemGroup>
      {trips.map(trip => (
        <BpkContextMenu.Item key={trip.id} value={trip.id}>
          {trip.name}
        </BpkContextMenu.Item>
      ))}
    </BpkContextMenu.ItemGroup>
    <BpkContextMenu.Separator />
    <BpkContextMenu.ItemGroup>
      <BpkContextMenu.Item value="new-trip" endIcon={<PlusIcon />}>
        Plan a new trip
      </BpkContextMenu.Item>
    </BpkContextMenu.ItemGroup>
  </BpkContextMenu.Content>
</BpkContextMenu.Root>

// no lists → plain BpkSaveButton, unchanged
<BpkSaveButton
  checked={isSaved}
  accessibilityLabel={isSaved ? 'Remove' : 'Save'}
  onCheckedChange={handleToggle}
/>
image image image
  • Component README.md
  • Tests
  • Accessibility tests
  • Storybook examples

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@tranculent
Yanko Mirov (tranculent) marked this pull request as ready for review July 24, 2026 14:22
Copilot AI review requested due to automatic review settings July 24, 2026 14:22

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 new BpkContextMenu compound component wrapping Ark UI’s Menu, plus small additive changes to BpkSaveButton to support composition as an asChild menu trigger.

Changes:

  • Introduces bpk-component-context-menu with a namespaced API (Root, Trigger, Content, Item, ItemGroup, Separator, TriggerItem) and SCSS styling.
  • Adds Storybook stories and unit + a11y tests for the new context menu.
  • Updates BpkSaveButton to use forwardRef, adds onClick and hoverEffect props, adjusts prop spread order, and tweaks focus styling when used as a menu trigger.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/backpack-web/src/bpk-component-context-menu/src/common-types.ts Adds shared public types and item variant constants for the context menu.
packages/backpack-web/src/bpk-component-context-menu/src/accessibility-test.tsx Adds axe-based accessibility coverage for open/closed states.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenuTrigger.tsx Implements the trigger wrapper with optional asChild composition.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenuSubTriggerItem.tsx Adds submenu trigger item wrapper (Menu.TriggerItem).
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenuSeparator.tsx Adds separator wrapper (Menu.Separator).
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenuRoot.tsx Adds root wrapper (Menu.Root) and wires selection/open callbacks.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenuItemGroup.tsx Adds item group wrapper for layout/dividers.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenuItem.tsx Adds menu item wrapper with variant, endIcon, and disabled support.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenuContent.tsx Adds portalled content/positioner wrappers.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenu.tsx Defines the namespaced API surface for the component.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenu.stories.tsx Provides Storybook examples and Percy-friendly visual stories.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenu.module.scss Adds styles for trigger, content surface, items, and animations.
packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenu-test.tsx Adds unit tests for rendering, selection, variants, and slots.
packages/backpack-web/src/bpk-component-context-menu/index.ts Exposes the component, constants, and selected public types.
packages/backpack-web/src/bpk-component-context-menu/README.md Documents installation/usage/parts and accessibility notes.
packages/backpack-web/src/bpk-component-card-button/src/BpkSaveButton.tsx Adds forwardRef, onClick, hoverEffect, and changes prop spreading.
packages/backpack-web/src/bpk-component-card-button/src/BpkSaveButton.module.scss Adjusts focus styling for menu-trigger usage and adds “no-hover” modifiers.
.eslintrc Allow-lists Ark Menu.* components for className prop usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@tranculent Yanko Mirov (tranculent) added the patch Patch production bug label Jul 27, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@toveadamsson

Copy link
Copy Markdown
Contributor

Regarding the long list UI, is it intentional that Plan a new trip and Quick Save aren't visible initially?
Screenshot 2026-07-27 at 14 00 19

@toveadamsson

Copy link
Copy Markdown
Contributor

Can we include documents in the descriptions that will be useful for external review, as to why certain decisions were made and the figma design as well 🙏

@tranculent

Copy link
Copy Markdown
Contributor Author

Regarding the long list UI, is it intentional that Plan a new trip and Quick Save aren't visible initially? Screenshot 2026-07-27 at 14 00 19

this is just a story but the way this Ark UI component is exposed to consumers is it lets them craft the menu as they wish. So technically it is possible to just render the Plan a new trip and quick save block on top without any issues. Also, this hasn't been confirmed by design yet.

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@Supremeyh Ezreal Yang (Supremeyh) added minor Non breaking change and removed patch Patch production bug labels Jul 28, 2026

@Supremeyh Ezreal Yang (Supremeyh) 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.

In the light mode, there is hover state background for each item, it seems there is blank space background between first/last item and it's border, is that expected? And does it also need hover state background on dark mode?

image

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@tranculent

Copy link
Copy Markdown
Contributor Author

Dark Mode:
image

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

skyscanner-backpack-bot Bot commented Jul 28, 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?

⚠️

Physical CSS properties are not RTL-safe. Prefer logical equivalents (inset-inline-, margin-inline-, padding-inline-, border-inline-, border-start-start-radius, text-align: start/end). Offending lines:

  • packages/backpack-web/src/bpk-component-context-menu/src/BpkContextMenu.module.scss:
  width: tokens.bpk-spacing-xxl();
  height: tokens.bpk-spacing-xxl();

Browser support

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

Generated by 🚫 dangerJS against 45acf74

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor


.bpk-context-menu__item-group {
--bpk-context-menu-item-divider: #{tokens.$bpk-border-size-sm} solid
var(--bpk-canvas-contrast, #{tokens.$bpk-canvas-contrast-day});

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.

should it be --bpk-other-line-default for semantic?

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.

no, it doesn't work right - it's too dark. Is --bpk-canvas-contrast to be migrated or it can be used?

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@Supremeyh Ezreal Yang (Supremeyh) 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, thanks your contribution, worth update PR description with latest changes

@Supremeyh Ezreal Yang (Supremeyh) changed the title Context Menu Stories and Implementation [BpkContextMenu] Context Menu Stories and Implementation Jul 29, 2026
@Supremeyh
Ezreal Yang (Supremeyh) merged commit 1b32215 into main Jul 29, 2026
15 checks passed
@Supremeyh
Ezreal Yang (Supremeyh) deleted the CAPY-2348/context-menu-component branch July 29, 2026 08:03
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.

5 participants