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

[STAR-352] [BpkBadge] interactive variant - #4896

Merged
GC Zhu (gc-skyscanner) merged 15 commits into
mainfrom
STAR-352_interactive-badge
Jul 17, 2026
Merged

GC Zhu (gc-skyscanner) merged 15 commits into
mainfrom
STAR-352_interactive-badge

Conversation

@vivitt

@vivitt Viviana Yanez (vivitt) commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add an new interactive variant to BpkBadge, using a polymorphic approach similar to BpkPressable.
The badge renders a non-interactive span by default, but it can also be rendered as a button or a link using the new as prop.
Interactive badges render a trailing info-circle icon (see the Figma design linked below).
Screenshot 2026-07-15 at 16 40 55

Notes

The interactive badge variants (as="button", as="a") are follow the pattern used in BpkPressable with two intentional simplifications:

  • disabled is omitted from both variants, a disabled interactive badge is semantically a non-interactive badge so the default span variant should be used instead
  • forwardRef is not used, interactive variants render as native or elements, which handle focus management natively without needing a DOM ref

What changed:

  • New as prop: 'span' (default, unchanged), 'button', or 'a'
  • Interactive variants render a trailing info circle icon and apply bpk-badge--interactive styles (flex layout, focus ring via bpk-focus-indicator, cursor pointer)
  • as="a" supports a blank convenience prop that sets target="_blank" and rel="noopener noreferrer" automatically
  • Props are now a strict discriminated union, replacing the previous [rest: string]: any index signature. The span variant extends HTMLAttributes so standard HTML attributes (aria-label, data-testid, etc.) are fully typed
  • snapshot and axe tests added for both interactive variants.

Useful links

BpkBadge Interactive ticket

figma

Interstellar jira ticket

Interactive badge screenshot

example of usage in combined explore deal-badges
Screenshot 2026-07-15 at 16 37 36

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

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

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

Copy link
Copy Markdown
Contributor

Browser support

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

Generated by 🚫 dangerJS against e7ad793

@vivitt
Viviana Yanez (vivitt) force-pushed the STAR-352_interactive-badge branch from 79c8d04 to c7b42fd Compare July 15, 2026 14:06
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

as?: 'span';
};

type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'className' | 'style' | 'type' | 'disabled'> & {

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.

The interactive badge variants (as="button" and as="a") follow the pattern in BpkPressable, but unlike it they intentionally omit the disabled prop. The rationale behind this decision is that a disabled interactive badge is semantically a non-interactive badge, so the span variant shopuld be used instead. Also, there are no design specs for a disabled interactive state.
Based on the above, disabled is explicitly removed from both ButtonProps and AnchorProps via Omit so this is enforced at the type level rather than silently ignored.
Happy to revisit if there's a use case I'm missing.

type = BADGE_TYPES.normal,
...rest
}: Props,
ref: Ref<HTMLButtonElement | HTMLAnchorElement >,

@vivitt Viviana Yanez (vivitt) Jul 15, 2026 •

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.

forwardRef is used so callers can receive a ref to the underlying DOM node for the interactive variants and can use it for programatic focus, or as a tooltip anchor. The span variant omits ref forwarding intentionally, since no interaction is expected on it.

@vivitt Viviana Yanez (vivitt) Jul 16, 2026 •

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.

Decided to keep it simple and remove the ref forwarding unless we see a clear need for it. Is there a particular reason BpkPressable forwards refs that we should consider here? 🙂

@vivitt Viviana Yanez (vivitt) added the minor Non breaking change label Jul 15, 2026
| AnchorProps
);

const BadgeInfoCircleIcon = () => (

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.

Note that this is added instead of using BpkIcon because, according to the design specs, the icon is slightly different in size and shape, and this is an info logo rather than the Backpack icon. See https://skyscanner.atlassian.net/jira/polaris/projects/BACKPACK/ideas/view/6690793?selectedIssue=BACKPACK-164 for more details

@vivitt Viviana Yanez (vivitt) changed the title [WIP] Initial draft for interactive badge [WIP] BpkBadge interactive variant Jul 16, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@vivitt Viviana Yanez (vivitt) changed the title [WIP] BpkBadge interactive variant [STAR-352] [BpkBadge] interactive variant Jul 16, 2026
@vivitt
Viviana Yanez (vivitt) marked this pull request as ready for review July 16, 2026 08:18
Copilot AI review requested due to automatic review settings July 16, 2026 08:18

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 no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR introduces an interactive variant for BpkBadge via a new polymorphic as prop, enabling badges to render as a <button> or <a> (with a trailing info icon) in addition to the default <span>.

Changes:

  • Added interactive badge rendering for as="button" and as="a" (including a blank convenience prop for links).
  • Introduced interactive styling and focus indicator support for the new variants.
  • Added snapshot and axe accessibility tests covering interactive variants.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/backpack-web/src/bpk-mixins/_badges.scss Adds an interactive badge mixin for layout/cursor/reset styles.
packages/backpack-web/src/bpk-component-badge/src/BpkBadge.module.scss Adds --interactive styles including focus-visible indicator.
packages/backpack-web/src/bpk-component-badge/src/BpkBadge.tsx Implements polymorphic as prop with <span>/<button>/<a> rendering and trailing icon.
packages/backpack-web/src/bpk-component-badge/src/BpkBadge.stories.tsx Adds Storybook examples for interactive button/link variants.
packages/backpack-web/src/bpk-component-badge/src/BpkBadge-test.tsx Adds snapshots for interactive button/link variants.
packages/backpack-web/src/bpk-component-badge/src/snapshots/BpkBadge-test.tsx.snap Updates snapshots to cover new interactive output.
packages/backpack-web/src/bpk-component-badge/src/accessibility-test.tsx Adds axe checks for interactive button/link variants.
packages/backpack-web/src/bpk-component-badge/README.md Documents the new interactive usage and blank behavior.

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

Comment on lines +53 to +66
type SpanProps = Omit<HTMLAttributes<HTMLSpanElement>, 'className' | 'style'> & {
as?: 'span';
};

type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'className' | 'style' | 'type' | 'disabled'> & {
as: 'button';
};

type AnchorProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'className' | 'style' | 'disabled'> & {
as: 'a';
href: string;
/** Open link in a new tab. Sets target="_blank" and rel="noopener noreferrer". */
blank?: boolean;
};
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

export type Props = {
type SpanProps = Omit<HTMLAttributes<HTMLSpanElement>, 'className' > & {
as?: 'span';
[rest: string]: any; // Inexact rest. See decisions/inexact-rest.md

@vivitt Viviana Yanez (vivitt) Jul 16, 2026 •

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.

keeping [rest: string]: any; to avoid breaking existing users that pass arbitrary props

| AnchorProps
);

const BadgeInfoCircleLogo = () => (

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.

Note that this is added instead of using BpkIcon because, according to the design specs, the icon is slightly different in size and shape, and this is an info logo rather than the Backpack icon. See skyscanner.atlassian.net/jira/polaris/projects/BACKPACK/ideas/view/6690793?selectedIssue=BACKPACK-164 for more details

- remove unused import
- add coverage for blank
- move type="button" after rest spread
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@gc-skyscanner
GC Zhu (gc-skyscanner) enabled auto-merge (squash) July 17, 2026 08:43
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

- add new variant in visual example story and fix fixed width/height
@gc-skyscanner
GC Zhu (gc-skyscanner) enabled auto-merge (squash) July 17, 2026 10:38
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@gc-skyscanner
GC Zhu (gc-skyscanner) merged commit d0e5e2c into main Jul 17, 2026
14 of 15 checks passed
@gc-skyscanner
GC Zhu (gc-skyscanner) deleted the STAR-352_interactive-badge branch July 17, 2026 11:02
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