An open source design system that's fully customizable and agent ready
TypeScript
fix(SideNav): expanded rows grow with a larger text size (#10550)
Cindy Zhang4deee89c635c
diff --git a/.changeset/sidenav-rows-grow-with-text.md b/.changeset/sidenav-rows-grow-with-text.mdnew file mode 100644index 0000000000..b3248b88b3--- /dev/null+++ b/.changeset/sidenav-rows-grow-with-text.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Navigation rows grow with a larger text size. The shared nav item styles (`navItemStyles`, used by `SideNavItem` and by `TopNavItem` and the mega menu in the mobile drawer) now take their size as a minimum height instead of a fixed one, so above 200% text a row's label no longer overlaps the next row, and its end content (such as a count `Badge`) stays inside the row. Collapsed rail rows keep their fixed square. At the default text size, TopNav drawer menu and mega menu rows with a description now fit their text instead of overlapping the next row; other rows are unchanged. A caller `height` on these styles no longer brings a row below its size; override `minHeight` instead.++@cixzhangdiff --git a/docs/specs/components/SideNav/SideNav.spec.md b/docs/specs/components/SideNav/SideNav.spec.mdindex 9882b7366f..a710ac9d3f 100644--- a/docs/specs/components/SideNav/SideNav.spec.md+++ b/docs/specs/components/SideNav/SideNav.spec.md@@ -96,8 +96,10 @@ Consumer migration instructions belong in consumer docs and release notes.`family:navigation-destinations`.- The collapsed item's tooltip and how it attaches — owned by`component:SideNavItem`.-- Exact fill colors, radius, row height, and row padding per size — owned by- the shared nav item styles and the `side-nav-item` theme target.+- Exact fill colors, radius, minimum row height, and row padding per size —+ owned by the shared nav item styles and the `side-nav-item` theme target;+ the shared styles take the height as a minimum, so a row grows with a+ larger text size (`spec:AST-102` FR4).- Layout of caller content placed directly inside a SideNavItem that is not aSideNavItem — owned by the product callsite.- SideNavHeading — owned by `component:SideNavHeading`; SideNavCollapseButton —@@ -107,10 +109,10 @@ Consumer migration instructions belong in consumer docs and release notes.## Public concepts-| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |-| ------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ------- | ------------------- | --------- | ---------------------- |-| Nesting depth | `0`, `1`, `2`, … (derived, not a prop) | The number of SideNavItem ancestors of a row within the same list. A collapsed rail's flyout restarts at 0. | Expanded rail; mobile drawer; flyout | `0` | `component:SideNav` | stable | Not caller-settable |-| Row size | `sm`, `md`, `lg` (existing SideNavItem `size`) | Sets the row's height and base inline padding; the indent adds to that padding. | Every row | `md` | `component:SideNav` | stable | Rejected by the type |+| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |+| ------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------- | ------- | ------------------- | --------- | ---------------------- |+| Nesting depth | `0`, `1`, `2`, … (derived, not a prop) | The number of SideNavItem ancestors of a row within the same list. A collapsed rail's flyout restarts at 0. | Expanded rail; mobile drawer; flyout | `0` | `component:SideNav` | stable | Not caller-settable |+| Row size | `sm`, `md`, `lg` (existing SideNavItem `size`) | Sets an expanded row's minimum height and every row's base inline padding; the indent adds to that padding. A collapsed rail row keeps a fixed square. | Every row | `md` | `component:SideNav` | stable | Rejected by the type |## Behavioral and layout contractdiff --git a/docs/specs/components/SideNav/SideNavItem.spec.md b/docs/specs/components/SideNav/SideNavItem.spec.mdindex 3a5b17b7e2..fae18efc14 100644--- a/docs/specs/components/SideNav/SideNavItem.spec.md+++ b/docs/specs/components/SideNav/SideNavItem.spec.md@@ -13,6 +13,7 @@ review_triggers: [public-api, behavior, accessibility]verified_by:[packages/core/src/SideNav/SideNav.test.tsx,+ packages/core/src/SideNav/__tests__/SideNavTextSize.interaction.browser.spec.ts,apps/storybook/stories/SideNav.stories.tsx,apps/storybook/rtl-audit/targets.json,]@@ -108,8 +109,9 @@ Consumer migration instructions belong in consumer docs and release notes.- The rail's collapsed state — owned by SideNav and `component:SideNavCollapseButton`.- Each control placed in `actions` — owned by that control (name, keyboard,disabled state).-- Row fill colors, radius, height, and padding per size — owned by the shared- nav item styles and the `side-nav-item` target.+- Row fill colors, radius, minimum height, and padding per size — owned by the+ shared nav item styles, which take the height as a minimum, and the+ `side-nav-item` target.## Public concepts@@ -137,7 +139,10 @@ Consumer migration instructions belong in consumer docs and release notes.### Allowed variation-- **AV1 — Size.** `sm`, `md`, and `lg` change row height and padding.+- **AV1 — Size.** `sm`, `md`, and `lg` change an expanded row's minimum+ height and its padding; an expanded row grows with a larger text size, so its+ label and end content stay inside it (`spec:AST-102` FR4). A collapsed rail+ row keeps its square size.- **AV2 — Theme styling.** Themes restyle `side-nav-item` per size, selected,and disabled state.@@ -202,6 +207,7 @@ is recorded. Row geometry visual intent is `component:SideNav` DD1.| ------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------- || FR1–FR3, FR5 | `SideNav.test.tsx` SideNavItem suite | Link, button, `as`, provider, disabled | Wrong element, lost `aria-current`, or a disabled item that runs `onClick` fails. | `audit:SideNavItem/behavior` || FR4–FR7, AR3 | `SideNav.test.tsx` actions-slot suite | Actions with toggle, endContent, disabled; row-wrapper `data-testid`; `defaultIsCollapsed` with whole-row `aria-controls` | Actions inside the primary element or wrong order fails. | `audit:SideNavItem/behavior` |+| AV1 text size | `SideNavTextSize.interaction.browser.spec.ts` at a 200% and 250% default font size | Default rows; end content | A row whose label or end content leaves the row, or overlaps the next row, fails. | `audit:SideNavItem/behavior` || FR6, FR7, AR2 | `SideNav.test.tsx` collapsible + href suite | Split, whole-row, controlled | A link that toggles or duplicated `aria-expanded` fails. | `audit:SideNavItem/accessibility` || FR8, FR9 | `SideNav.test.tsx` collapsed, hover-intent, and rail-tooltip suites | Leaf, parent, hover, click, keyboard, coarse | Lost delay, focus restore, or tooltip anchor fails. | `audit:SideNavItem/behavior` || FR10 | `SideNav.test.tsx` mobile drawer close-on-activate suite | Link, button, toggle, action, outside drawer | Wrong close behavior fails. | `audit:SideNavItem/behavior` |diff --git a/packages/core/src/NavItem/navItemStyles.stylex.ts b/packages/core/src/NavItem/navItemStyles.stylex.tsindex a6580560ce..a107dc97e5 100644--- a/packages/core/src/NavItem/navItemStyles.stylex.ts+++ b/packages/core/src/NavItem/navItemStyles.stylex.ts@@ -56,7 +56,9 @@ export const navItemStyles = stylex.create({alignItems: 'center',gap: spacingVars['--spacing-2'],width: '100%',- height: sizeVars['--size-element-md'],+ // A minimum, so an item grows with a larger text size and its label never+ // leaves it.+ minHeight: sizeVars['--size-element-md'],paddingInline: spacingVars['--spacing-2'],paddingBlock: 0,borderRadius: radiusVars['--radius-element'],@@ -138,19 +140,19 @@ export const navItemStyles = stylex.create({/** Small size variant */sm: {- height: sizeVars['--size-element-sm'],+ minHeight: sizeVars['--size-element-sm'],paddingInline: spacingVars['--spacing-1'],},/** Medium size variant (default) */md: {- height: sizeVars['--size-element-md'],+ minHeight: sizeVars['--size-element-md'],paddingInline: spacingVars['--spacing-2'],},/** Large size variant */lg: {- height: sizeVars['--size-element-lg'],+ minHeight: sizeVars['--size-element-lg'],paddingInline: spacingVars['--spacing-2'],},});diff --git a/packages/core/src/SideNav/SideNavItem.tsx b/packages/core/src/SideNav/SideNavItem.tsxindex 28966f616b..6e6692da2e 100644--- a/packages/core/src/SideNav/SideNavItem.tsx+++ b/packages/core/src/SideNav/SideNavItem.tsx@@ -99,13 +99,21 @@ const styles = stylex.create({flexDirection: 'column',width: '100%',},+ // A collapsed rail row holds only its icon, so it keeps a fixed square.itemCollapsed: {justifyContent: 'center',width: sizeVars['--size-element-md'],+ height: sizeVars['--size-element-md'],paddingInline: 0,},- itemCollapsedSm: {width: sizeVars['--size-element-sm']},- itemCollapsedLg: {width: sizeVars['--size-element-lg']},+ itemCollapsedSm: {+ width: sizeVars['--size-element-sm'],+ height: sizeVars['--size-element-sm'],+ },+ itemCollapsedLg: {+ width: sizeVars['--size-element-lg'],+ height: sizeVars['--size-element-lg'],+ },label: {flex: 1,minWidth: 0,@@ -189,6 +197,11 @@ const styles = stylex.create({transitionTimingFunction: easeVars['--ease-standard'],flexShrink: 0,},+ // Inside a whole-row toggle the chevron takes its 1em glyph's height, so+ // the row's height comes from its label, not from the chevron's box.+ expandChevronInRow: {+ height: 'auto',+ },expandChevronExpanded: {transform: 'rotate(180deg)',},@@ -801,6 +814,7 @@ export function SideNavItem({color="inherit"xstyle={[styles.expandChevron,+ styles.expandChevronInRow,!isItemCollapsed && styles.expandChevronExpanded,]}/>diff --git a/packages/core/src/SideNav/__tests__/SideNavTextSize.interaction.browser.spec.ts b/packages/core/src/SideNav/__tests__/SideNavTextSize.interaction.browser.spec.tsnew file mode 100644index 0000000000..c541e5f12a--- /dev/null+++ b/packages/core/src/SideNav/__tests__/SideNavTextSize.interaction.browser.spec.ts@@ -0,0 +1,99 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file SideNavTextSize.interaction.browser.spec.ts+ * @input The built SideNav 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 expanded row grows with a larger+ * text size, so no row's label or end content leaves the row or overlaps+ * the next row+ * @position Browser proof of AST-102 FR4 for SideNavItem+ */++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)},+ });+}++/**+ * Each row's own box, and the union of its visible content boxes (label+ * text and end content). A content box outside its row overlaps a+ * neighboring row.+ */+async function rowFit(page: Page) {+ return page.evaluate(() =>+ [...document.querySelectorAll<HTMLElement>('.astryx-side-nav-item')]+ .filter(row => row.getBoundingClientRect().height > 0)+ .map(row => {+ const rowBox = row.getBoundingClientRect();+ let top = Infinity;+ let bottom = -Infinity;+ for (const element of row.querySelectorAll<HTMLElement>('*')) {+ const box = element.getBoundingClientRect();+ if (box.height === 0 || element.closest('[role="menu"]') != null) {+ continue;+ }+ top = Math.min(top, box.top);+ bottom = Math.max(bottom, box.bottom);+ }+ return {+ label: row.innerText.trim().split('\n')[0],+ rowTop: rowBox.top,+ rowBottom: rowBox.bottom,+ contentTop: top,+ contentBottom: bottom,+ };+ }),+ );+}++for (const percent of [200, 250]) {+ for (const story of ['default', 'end-content']) {+ test(`at ${percent}% text size, rows grow with their content: ${story}`, async ({+ page,+ }) => {+ await setDefaultFontSize(page, (16 * percent) / 100);+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-sidenav--${story}&viewMode=story`,+ );+ await page.locator('.astryx-side-nav-item').first().waitFor();+ const rows = await rowFit(page);+ expect(rows.length).toBeGreaterThan(0);+ for (const row of rows) {+ expect(row.contentTop, row.label).toBeGreaterThanOrEqual(+ row.rowTop - 1,+ );+ expect(row.contentBottom, row.label).toBeLessThanOrEqual(+ row.rowBottom + 1,+ );+ }+ });+ }+}