Repository navigation
[STAR-352] [BpkBadge] interactive variant - #4896
Conversation
|
Visit https://backpack.github.io/storybook-prs/4896 to see this build running in a browser. |
79c8d04 to
c7b42fd
Compare
|
Visit https://backpack.github.io/storybook-prs/4896 to see this build running in a browser. |
| as?: 'span'; | ||
| }; | ||
|
|
||
| type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'className' | 'style' | 'type' | 'disabled'> & { |
There was a problem hiding this comment.
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 >, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? 🙂
| | AnchorProps | ||
| ); | ||
|
|
||
| const BadgeInfoCircleIcon = () => ( |
There was a problem hiding this comment.
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
|
Visit https://backpack.github.io/storybook-prs/4896 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 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"andas="a"(including ablankconvenience 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.
| 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; | ||
| }; |
|
Visit https://backpack.github.io/storybook-prs/4896 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4896 to see this build running in a browser. |
| export type Props = { | ||
| type SpanProps = Omit<HTMLAttributes<HTMLSpanElement>, 'className' > & { | ||
| as?: 'span'; | ||
| [rest: string]: any; // Inexact rest. See decisions/inexact-rest.md |
There was a problem hiding this comment.
keeping [rest: string]: any; to avoid breaking existing users that pass arbitrary props
| | AnchorProps | ||
| ); | ||
|
|
||
| const BadgeInfoCircleLogo = () => ( |
There was a problem hiding this comment.
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
|
Visit https://backpack.github.io/storybook-prs/4896 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4896 to see this build running in a browser. |
- add new variant in visual example story and fix fixed width/height
|
Visit https://backpack.github.io/storybook-prs/4896 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4896 to see this build running in a browser. |
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
asprop.Interactive badges render a trailing info-circle icon (see the Figma design linked below).
Notes
The interactive badge variants (as="button", as="a") are follow the pattern used in BpkPressable with two intentional simplifications:
What changed:
asprop: 'span' (default, unchanged), 'button', or 'a'Useful links
BpkBadge Interactive ticket
figma
Interstellar jira ticket
Interactive badge screenshot
example of usage in combined explore deal-badges

Remember to include the following changes:
[Clover-123][BpkButton] Updating the colourREADME.md(If you have created a new component)README.md