diff --git a/packages/react/cypress-image-diff-screenshots/baseline/IcTabs.cy.tsx/compact-flex-ancestor.png b/packages/react/cypress-image-diff-screenshots/baseline/IcTabs.cy.tsx/compact-flex-ancestor.png new file mode 100755 index 00000000000..7b8a914ada2 Binary files /dev/null and b/packages/react/cypress-image-diff-screenshots/baseline/IcTabs.cy.tsx/compact-flex-ancestor.png differ diff --git a/packages/react/cypress-image-diff-screenshots/baseline/IcTabs.cy.tsx/compact-grid-ancestor.png b/packages/react/cypress-image-diff-screenshots/baseline/IcTabs.cy.tsx/compact-grid-ancestor.png new file mode 100755 index 00000000000..7b8a914ada2 Binary files /dev/null and b/packages/react/cypress-image-diff-screenshots/baseline/IcTabs.cy.tsx/compact-grid-ancestor.png differ diff --git a/packages/react/src/component-tests/IcTabs/IcTabs.cy.tsx b/packages/react/src/component-tests/IcTabs/IcTabs.cy.tsx index 36a85a515b9..94b22dcb59a 100644 --- a/packages/react/src/component-tests/IcTabs/IcTabs.cy.tsx +++ b/packages/react/src/component-tests/IcTabs/IcTabs.cy.tsx @@ -3,6 +3,7 @@ import React from "react"; import { mount } from "cypress/react"; +import { IcTab, IcTabContext, IcTabGroup, IcTabPanel } from "../../components"; import { BE_VISIBLE, HAVE_ATTR, @@ -665,3 +666,74 @@ describe("IcTabs visual regression in high contrast mode", () => { }); }); }); + +const ReflowTabs = () => ( + + + Ingredients + Preparation method + Recipe history + Recommended drinks + Related recipes + Kitchen blog + + Ingredients + Preparation method + Recipe history + Recommended drinks + Related recipes + Kitchen blog + +); + +const ConstrainedReflowTabs = ({ display }: { display: "flex" | "grid" }) => ( +
+
+ +
+
+); + +const checkCompactReflow = (display: "flex" | "grid") => { + cy.checkHydrated(IC_TAB_GROUP); + + cy.findShadowEl(IC_TAB_GROUP, "ic-horizontal-scroll").should( + "have.class", + "ic-horizontal-scroll-visible" + ); + + cy.get(`#${display}-tabs-container`).then(([container]) => { + expect(container.scrollWidth).to.be.at.most(container.clientWidth); + }); + + // Match the existing compact-tabs regression: this layout state inherits + // the horizontal-scroll accessibility baseline and is tested here for reflow. + cy.compareSnapshot({ + name: `/compact-${display}-ancestor`, + testThreshold: setThresholdBasedOnEnv(DEFAULT_TEST_THRESHOLD + 0.014), + }); +}; + +describe("IcTabs flex/grid reflow", () => { + beforeEach(() => { + cy.viewport(360, 600); + cy.injectAxe(); + }); + + afterEach(() => { + cy.task("generateReport"); + }); + + it("should enter compact mode inside a flex layout", () => { + mount(); + checkCompactReflow("flex"); + }); + + it("should enter compact mode inside a grid layout", () => { + mount(); + checkCompactReflow("grid"); + }); +}); diff --git a/packages/web-components/src/components/ic-tab-group/ic-tab-group.css b/packages/web-components/src/components/ic-tab-group/ic-tab-group.css index 3667ade133f..3ba71479d8e 100644 --- a/packages/web-components/src/components/ic-tab-group/ic-tab-group.css +++ b/packages/web-components/src/components/ic-tab-group/ic-tab-group.css @@ -1,5 +1,7 @@ :host { display: block; + contain: inline-size; + min-width: 0; margin-bottom: var(--ic-space-md); border-bottom: var(--ic-space-1px) solid var(--ic-tab-bottom-border); }