An open source design system that's fully customizable and agent ready
TypeScript
fix(TabList): tabs grow with a larger text size instead of clipping their labels (#10534)
Cindy Zhang3918a54ad0e4
diff --git a/.changeset/tablist-grows-with-text.md b/.changeset/tablist-grows-with-text.mdnew file mode 100644index 0000000000..2102cd1780--- /dev/null+++ b/.changeset/tablist-grows-with-text.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `TabList` tabs, including a `TabMenu` tab, grow with a larger text size. Their size now sets a minimum height instead of a fixed one, so at 200% text and above a tab label is no longer clipped. At the default text size nothing changes.++@cixzhangdiff --git a/docs/specs/components/TabList/Tab.spec.md b/docs/specs/components/TabList/Tab.spec.mdindex 6cd0b7706b..4afaf64ef2 100644--- a/docs/specs/components/TabList/Tab.spec.md+++ b/docs/specs/components/TabList/Tab.spec.md@@ -15,6 +15,7 @@ verified_by:packages/core/src/TabList/TabList.test.tsx,packages/core/src/TabList/__tests__/Tabs.a11y.test.tsx,packages/core/src/TabList/__tests__/Tabs.a11y.chromium.spec.ts,+ packages/core/src/TabList/__tests__/TabListTextSize.interaction.browser.spec.ts,apps/storybook/stories/TabList.stories.tsx,apps/storybook/rtl-audit/targets.json,]@@ -120,8 +121,9 @@ Consumer migration instructions belong in consumer docs and release notes.### Allowed variation-- **AV1 — Size and layout.** Height follows the TabList size; `fill` layout- stretches Tabs.+- **AV1 — Size and layout.** The TabList size sets each Tab's minimum+ height; a Tab grows with a larger text size so its label is never clipped+ (`spec:AST-102` FR4). `fill` layout stretches Tabs.- **AV2 — Theme styling.** Themes restyle `tab` and `tab-indicator` per selectedstate.@@ -170,13 +172,14 @@ FR1–FR2.## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------------------------------------------------------------- | ------------------------- |-| FR1, FR2 | `TabList.test.tsx` aria-current, polymorphic link, and tabs-pattern tests; `Tabs.a11y.test.tsx`; `Tabs.a11y.chromium.spec.ts` for `aria-selected` | Navigation, link, tabs | Wrong role or state fails. | `audit:Tab/accessibility` |-| FR3 | `TabList.test.tsx` single tab stop and roving tabindex tests | Selected | Extra tab stops, or a wrong starting stop, fail. | `audit:Tab/accessibility` |-| FR4, FR5 | `TabList.test.tsx` onChange and disabled tests | Click, disabled button | Selection when disabled fails. | `audit:Tab/behavior` |-| FR6, FR7 | `TabList.test.tsx` icon, icon-only, and pressed-overlay tests | Icon, selected icon, hidden label | Wrong icon, name, or overlay fails. | `audit:Tab/behavior` |-| RTL relation | RTL audit curated D2 target (`apps/storybook/rtl-audit/targets.json`) on `TabList / With icons` | Tab icon and label; LTR and RTL | An icon that is not at the inline start of its label fails D2. | `audit:Tab/i18n-rtl` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | --------------------------------------------------------------------------- | ------------------------- |+| FR1, FR2 | `TabList.test.tsx` aria-current, polymorphic link, and tabs-pattern tests; `Tabs.a11y.test.tsx`; `Tabs.a11y.chromium.spec.ts` for `aria-selected` | Navigation, link, tabs | Wrong role or state fails. | `audit:Tab/accessibility` |+| FR3 | `TabList.test.tsx` single tab stop and roving tabindex tests | Selected | Extra tab stops, or a wrong starting stop, fail. | `audit:Tab/accessibility` |+| FR4, FR5 | `TabList.test.tsx` onChange and disabled tests | Click, disabled button | Selection when disabled fails. | `audit:Tab/behavior` |+| FR6, FR7 | `TabList.test.tsx` icon, icon-only, and pressed-overlay tests | Icon, selected icon, hidden label | Wrong icon, name, or overlay fails. | `audit:Tab/behavior` |+| AV1 text size | `TabListTextSize.interaction.browser.spec.ts` at a 200% and 250% default font size | Default, size variants, with menu | A tab or tab strip that clips its label, or a label outside its tab, fails. | `audit:Tab/behavior` |+| RTL relation | RTL audit curated D2 target (`apps/storybook/rtl-audit/targets.json`) on `TabList / With icons` | Tab icon and label; LTR and RTL | An icon that is not at the inline start of its label fails D2. | `audit:Tab/i18n-rtl` |Read from source, with no focused test yet:diff --git a/packages/core/src/TabList/Tab.tsx b/packages/core/src/TabList/Tab.tsxindex 2aa689cc3b..93dda9d33b 100644--- a/packages/core/src/TabList/Tab.tsx+++ b/packages/core/src/TabList/Tab.tsx@@ -235,17 +235,20 @@ const styles = stylex.create({},});+// A minimum, not a fixed height: a tab grows with a larger text size, so its+// label is never clipped.const sizeStyles = stylex.create({- sm: {height: sizeVars['--size-element-sm']},- md: {height: sizeVars['--size-element-md']},- lg: {height: sizeVars['--size-element-lg']},+ sm: {minHeight: sizeVars['--size-element-sm']},+ md: {minHeight: sizeVars['--size-element-md']},+ lg: {minHeight: sizeVars['--size-element-lg']},});-// Hover bg uses the standard element size (one step smaller than tab)+// The hover background fills the tab (inset 0) and is never shorter than the+// element size.const hoverSizeStyles = stylex.create({- sm: {height: sizeVars['--size-element-sm']},- md: {height: sizeVars['--size-element-md']},- lg: {height: sizeVars['--size-element-lg']},+ sm: {minHeight: sizeVars['--size-element-sm']},+ md: {minHeight: sizeVars['--size-element-md']},+ lg: {minHeight: sizeVars['--size-element-lg']},});const layoutStyles = stylex.create({diff --git a/packages/core/src/TabList/TabMenu.tsx b/packages/core/src/TabList/TabMenu.tsxindex 5a8cdee14a..d0c4d6de61 100644--- a/packages/core/src/TabList/TabMenu.tsx+++ b/packages/core/src/TabList/TabMenu.tsx@@ -234,17 +234,20 @@ const styles = stylex.create({},});+// A minimum, not a fixed height: a tab grows with a larger text size, so its+// label is never clipped.const sizeStyles = stylex.create({- sm: {height: sizeVars['--size-element-sm']},- md: {height: sizeVars['--size-element-md']},- lg: {height: sizeVars['--size-element-lg']},+ sm: {minHeight: sizeVars['--size-element-sm']},+ md: {minHeight: sizeVars['--size-element-md']},+ lg: {minHeight: sizeVars['--size-element-lg']},});-// Hover bg uses the standard element size (one step smaller than tab)+// The hover background fills the tab (inset 0) and is never shorter than the+// element size.const hoverSizeStyles = stylex.create({- sm: {height: sizeVars['--size-element-sm']},- md: {height: sizeVars['--size-element-md']},- lg: {height: sizeVars['--size-element-lg']},+ sm: {minHeight: sizeVars['--size-element-sm']},+ md: {minHeight: sizeVars['--size-element-md']},+ lg: {minHeight: sizeVars['--size-element-lg']},});/**diff --git a/packages/core/src/TabList/__tests__/TabListTextSize.interaction.browser.spec.ts b/packages/core/src/TabList/__tests__/TabListTextSize.interaction.browser.spec.tsnew file mode 100644index 0000000000..e6573fdbfa--- /dev/null+++ b/packages/core/src/TabList/__tests__/TabListTextSize.interaction.browser.spec.ts@@ -0,0 +1,110 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file TabListTextSize.interaction.browser.spec.ts+ * @input The built TabList stories, with Chromium's default font size raised+ * to 200% and 250% (the setting a browser's text-only zoom changes)+ * @output Real-browser evidence that each tab grows with a larger text size,+ * so no tab label and no tab strip clips its text+ * @position Browser proof of AST-102 FR4 for TabList, Tab and TabMenu+ */++import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;++test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});++test.afterAll(async () => {+ await storybook?.close();+});++test.skip(+ ({browserName}) => browserName !== 'chromium',+ 'Page.setFontSizes is a Chromium DevTools command',+);++/** Sets the browser's default font size, which rem-based text follows. */+async function setDefaultFontSize(page: Page, px: number): Promise<void> {+ const session = await page.context().newCDPSession(page);+ await session.send('Page.setFontSizes', {+ fontSizes: {standard: px, fixed: Math.round((px * 13) / 16)},+ });+}++/** Tabs that leave the tab strip's box, which clips its overflow. */+async function tabsOutsideStrip(page: Page) {+ return page.evaluate(() =>+ [...document.querySelectorAll<HTMLElement>('.astryx-tab-strip')].flatMap(+ strip => {+ const stripBox = strip.getBoundingClientRect();+ return [+ ...strip.querySelectorAll<HTMLElement>(+ '.astryx-tab, .astryx-tab-menu',+ ),+ ]+ .filter(tab => {+ const tabBox = tab.getBoundingClientRect();+ return (+ tabBox.top < stripBox.top - 1 ||+ tabBox.bottom > stripBox.bottom + 1+ );+ })+ .map(tab => tab.innerText.trim());+ },+ ),+ );+}++/** Each tab's label box against the tab's own box. */+async function labelFit(page: Page) {+ return page.evaluate(() =>+ [+ ...document.querySelectorAll<HTMLElement>(+ '.astryx-tab, .astryx-tab-menu',+ ),+ ].map(tab => {+ const tabBox = tab.getBoundingClientRect();+ const range = document.createRange();+ range.selectNodeContents(tab);+ const textBox = range.getBoundingClientRect();+ return {+ label: tab.innerText.trim(),+ tabTop: tabBox.top,+ tabBottom: tabBox.bottom,+ textTop: textBox.top,+ textBottom: textBox.bottom,+ };+ }),+ );+}++for (const percent of [200, 250]) {+ for (const story of ['default', 'size-variants', 'with-menu']) {+ test(`at ${percent}% text size, tabs grow with their labels: ${story}`, async ({+ page,+ }) => {+ await setDefaultFontSize(page, (16 * percent) / 100);+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-tablist--${story}&viewMode=story`,+ );+ await page.locator('.astryx-tab-strip').first().waitFor();+ expect(await tabsOutsideStrip(page)).toEqual([]);+ for (const fit of await labelFit(page)) {+ expect(fit.textTop, fit.label).toBeGreaterThanOrEqual(fit.tabTop - 1);+ expect(fit.textBottom, fit.label).toBeLessThanOrEqual(+ fit.tabBottom + 1,+ );+ }+ });+ }+}