diff --git a/packages/react/src/component-tests/IcToggleButton/IcToggleButton.cy.tsx b/packages/react/src/component-tests/IcToggleButton/IcToggleButton.cy.tsx
index c8611755ed..0ab056ae20 100644
--- a/packages/react/src/component-tests/IcToggleButton/IcToggleButton.cy.tsx
+++ b/packages/react/src/component-tests/IcToggleButton/IcToggleButton.cy.tsx
@@ -13,6 +13,7 @@ import {
} from "../utils/constants";
import { setThresholdBasedOnEnv } from "../../../cypress/utils/helpers";
import {
+ ConditionalBadge,
Dark,
IconPlacementRight,
IconPlacementTop,
@@ -94,6 +95,14 @@ describe("IcToggleButton end-to-end tests", () => {
cy.clickOnButton(IC_TOGGLE_BUTTON_SELECTOR);
cy.get(WIN_CONSOLE_SPY).should(NOT_BE_CALLED_ONCE);
});
+
+ it("should render elements passed into slots after initial render", () => {
+ mount();
+ cy.checkHydrated(IC_TOGGLE_BUTTON_SELECTOR);
+ cy.get("ic-badge").should("not.exist");
+ cy.get("button").click();
+ cy.get("ic-badge").should("be.visible");
+ });
});
describe("IcToggleButton visual regression and a11y tests", () => {
diff --git a/packages/react/src/component-tests/IcToggleButton/IcToggleButtonTestData.tsx b/packages/react/src/component-tests/IcToggleButton/IcToggleButtonTestData.tsx
index 03a43817f5..ee330d9d77 100644
--- a/packages/react/src/component-tests/IcToggleButton/IcToggleButtonTestData.tsx
+++ b/packages/react/src/component-tests/IcToggleButton/IcToggleButtonTestData.tsx
@@ -1,5 +1,5 @@
-import React, { ReactElement } from "react";
-import { IcToggleButton } from "../../components";
+import React, { ReactElement, useState } from "react";
+import { IcBadge, IcToggleButton } from "../../components";
import { SlottedSVG } from "../../react-component-lib/slottedSVG";
const ReusableSlottedIcon = (): ReactElement => (
@@ -165,3 +165,29 @@ export const Light = (): ReactElement => {
);
};
+
+export const ConditionalBadge = (): ReactElement => {
+ const [count, setCount] = useState(0);
+ const incrementCount = () => setCount((previous) => previous + 1);
+
+ return (
+
+
+ Button with badge
+ {count > 0 && (
+
+ )}
+
+
+
+ );
+};
diff --git a/packages/react/src/stories/ic-button.stories.mdx b/packages/react/src/stories/ic-button.stories.mdx
index 3a8fc2aa6a..2df400365a 100644
--- a/packages/react/src/stories/ic-button.stories.mdx
+++ b/packages/react/src/stories/ic-button.stories.mdx
@@ -6,7 +6,7 @@ import {
Description,
} from "@storybook/addon-docs";
import { useRef } from "react";
-import { IcButton, IcPopoverMenu, IcMenuItem } from "../components";
+import { IcButton, IcPopoverMenu, IcMenuItem, IcBadge } from "../components";
import readme from "../../../web-components/src/components/ic-button/readme.md";
import { SlottedSVG } from "../react-component-lib/slottedSVG";
import { iconProps } from "../component-tests/IcButton/IcButtonTestData"
@@ -24,6 +24,8 @@ export const defaultArgs = {
size: "default",
variant: "secondary",
fullWidth: false,
+ hasIcon: true,
+ hasBadge: false,
};
### Primary
@@ -1150,6 +1152,12 @@ export const IconBtnGroup = (iconProps) => {
fullWidth: {
control: { type: "boolean" },
},
+ hasIcon: {
+ control: { type: "boolean" },
+ },
+ hasBadge: {
+ control: { type: "boolean" },
+ },
}}
name="Playground with icon"
>
@@ -1163,7 +1171,7 @@ export const IconBtnGroup = (iconProps) => {
fullWidth={args.fullWidth}
>
{args.message}
-
+ }
+ {args.hasBadge && }
)}
diff --git a/packages/react/src/stories/ic-toggle-button.stories.mdx b/packages/react/src/stories/ic-toggle-button.stories.mdx
index cf737fd1df..da772fb5e7 100644
--- a/packages/react/src/stories/ic-toggle-button.stories.mdx
+++ b/packages/react/src/stories/ic-toggle-button.stories.mdx
@@ -259,6 +259,8 @@ export const defaultWithIconArgs = {
iconPlacement: "left",
toggleChecked: false,
accessibleLabel: "Custom Button Ally Label",
+ hasIcon: true,
+ hasBadge: false,
};