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

[STAR-352] [BpkBadge] Wrap BpkBadge in forwardRef - #4912

Merged
Iris Li (wpe1arhy) merged 2 commits into
mainfrom
STAR-352_interactive-badge-forward-ref
Jul 20, 2026
Merged

Iris Li (wpe1arhy) merged 2 commits into
mainfrom
STAR-352_interactive-badge-forward-ref

Conversation

@vivitt

Copy link
Copy Markdown
Contributor

BpkBadge Interactive

This PR is a follow up to #4896.
It wraps BpkBadge in forwardRef to expose the underlying or DOM node to consumers, following the pattern in BpkPressable.
The ref is forwarded only for interactive variants (as="button" or as="a"); the default badge does not forward a ref.
This change is needed for programmatically focus the badge after an action such as closing a bottom sheet, returning focus to the trigger.

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

@vivitt Viviana Yanez (vivitt) added the minor Non breaking change label Jul 20, 2026
@vivitt
Viviana Yanez (vivitt) marked this pull request as ready for review July 20, 2026 08:39
Copilot AI review requested due to automatic review settings July 20, 2026 08:39
@skyscanner-backpack-bot

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 c4779cb

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.

Wraps BpkBadge with forwardRef so consumers can access the underlying DOM element for interactive badge variants (as="button" / as="a") and document that behavior.

Changes:

  • Wrap BpkBadge in forwardRef and pass the forwarded ref to <a> and <button> render paths.
  • Rename the inner implementation to BpkBadgeInner and export the forwardRef wrapper as BpkBadge.
  • Document ref-forwarding behavior in the component README.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
packages/backpack-web/src/bpk-component-badge/src/BpkBadge.tsx Introduces forwardRef wrapper and forwards refs to anchor/button variants.
packages/backpack-web/src/bpk-component-badge/README.md Documents when BpkBadge forwards refs (interactive variants only).

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

type = BADGE_TYPES.normal,
...rest
}: Props,
ref: Ref<HTMLButtonElement | HTMLAnchorElement >,
const resolvedTarget = blank ? '_blank' : target;

return (<a
ref={ref as Ref<HTMLAnchorElement>}
const buttonRest = rest as Omit<ButtonProps, 'as' | 'children'>;
return (
<button
ref={ref as Ref<HTMLButtonElement>}
);
};

const BpkBadge = forwardRef(BpkBadgeInner);
* limitations under the License.
*/
import type { ReactNode, AnchorHTMLAttributes, ButtonHTMLAttributes, HTMLAttributes } from 'react';
import type { ReactNode, AnchorHTMLAttributes, ButtonHTMLAttributes, HTMLAttributes, Ref} from 'react';
type = BADGE_TYPES.normal,
...rest
}: Props,
ref: Ref<HTMLButtonElement | HTMLAnchorElement >,
);
```

`BpkBadge` forwards its `ref` to the underlying `<button>` (when `as="button"`) or `<a>` (when `as="a"`) element. For non-interactive `<span>` badge, no ref is forwarded.

@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 dde7f29 into main Jul 20, 2026
15 of 17 checks passed
@wpe1arhy
Iris Li (wpe1arhy) deleted the STAR-352_interactive-badge-forward-ref branch July 20, 2026 10:22
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.

3 participants