Skip to content

Commit 0c9e0e9

Browse files
authored
[WC-3327] Badge button: fix class duplication (#2132)
2 parents c27d43b + 6d912fe commit 0c9e0e9

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

packages/pluggableWidgets/badge-button-web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- We fixed an issue where custom button styles were not being applied correctly.
12+
913
## [3.2.2] - 2026-02-09
1014

1115
### Added

packages/pluggableWidgets/badge-button-web/src/components/BadgeButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const BadgeButton = (props: BadgeButtonProps): ReactElement => (
1313
<button
1414
className={classNames(
1515
"widget-badge-button btn",
16-
{ "btn-primary": !props.className?.match(/btn-{primary|secondary|success|warning|danger}/) },
16+
{ "btn-primary": !props.className?.match(/btn-(primary|secondary|success|warning|danger)/) },
1717
props.className
1818
)}
1919
onClick={props.onClick}

packages/pluggableWidgets/badge-button-web/src/components/__tests__/BadgeButton.spec.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,27 @@ describe("BadgeButton", () => {
4444

4545
expect(badge.getByRole("button")).toHaveClass("btn btn-secondary");
4646
});
47+
48+
describe("button style class detection", () => {
49+
it("does not add duplicate btn-primary when btn-success is present", () => {
50+
const badge = renderBadgeButton({ className: "btn-success" });
51+
const button = badge.getByRole("button");
52+
53+
expect(button.className).toEqual("widget-badge-button btn btn-success");
54+
});
55+
56+
it("adds btn-primary as default when no button style is present", () => {
57+
const badge = renderBadgeButton({ className: "custom-class" });
58+
const button = badge.getByRole("button");
59+
60+
expect(button.className).toEqual("widget-badge-button btn btn-primary custom-class");
61+
});
62+
63+
it("adds btn-primary when className is undefined", () => {
64+
const badge = renderBadgeButton({});
65+
const button = badge.getByRole("button");
66+
67+
expect(button.className).toEqual("widget-badge-button btn btn-primary");
68+
});
69+
});
4770
});

0 commit comments

Comments
 (0)