An open source design system that's fully customizable and agent ready
TypeScript
fix(MobileNav): the header row grows with taller header content (#8865)
Cindy Zhangcdc4dcbab012
diff --git a/.changeset/mobilenav-header-grows.md b/.changeset/mobilenav-header-grows.mdnew file mode 100644index 0000000000..5ca28efe63--- /dev/null+++ b/.changeset/mobilenav-header-grows.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `MobileNav`'s header row grows with its content. It was a fixed one-bar height, so a header taller than one row (a title with a search field under it, or a title that wraps at a larger text size) overflowed the row: the bottom border ran through it and the content ran into the first navigation item. The row is now at least one bar high, so a one-line header looks as before. `SideNav` in drawer mode, which passes its `header` to `MobileNav`, gets the same fix.++@cixzhangdiff --git a/apps/storybook/stories/MobileNav.stories.tsx b/apps/storybook/stories/MobileNav.stories.tsxindex c274d0f476..87837de075 100644--- a/apps/storybook/stories/MobileNav.stories.tsx+++ b/apps/storybook/stories/MobileNav.stories.tsx@@ -10,6 +10,8 @@ import {SideNavSection,} from '@astryxdesign/core/SideNav';import {Button} from '@astryxdesign/core/Button';+import {Text} from '@astryxdesign/core/Text';+import {TextInput} from '@astryxdesign/core/TextInput';import {Icon} from '@astryxdesign/core/Icon';import {NavIcon} from '@astryxdesign/core/NavIcon';import {useMediaQuery} from '@astryxdesign/core/hooks';@@ -337,3 +339,55 @@ export const WithoutTitle: Story = {);},};++// =============================================================================+// Tall Header+// =============================================================================++/**+ * Header content taller than one bar: a workspace name with a search field+ * under it. The header row grows to fit it, above the first item.+ */+export const TallHeader: Story = {+ name: 'Tall Header',+ render: () => {+ const [isOpen, setIsOpen] = useState(false);+ const [query, setQuery] = useState('');+ return (+ <>+ <Button+ label="Open Navigation"+ icon={<Icon icon="menu" color="inherit" />}+ variant="ghost"+ onClick={() => setIsOpen(true)}+ isIconOnly+ />+ <MobileNav+ isOpen={isOpen}+ onOpenChange={open => setIsOpen(open)}+ label="Workspace navigation"+ header={+ <div>+ <Text weight="bold">Workspace</Text>+ <TextInput+ label="Search"+ isLabelHidden+ value={query}+ onChange={setQuery}+ />+ </div>+ }>+ <SideNavSection title="Main">+ <SideNavItem+ label="Dashboard"+ icon={HomeIcon}+ isSelected+ href="/dashboard"+ />+ <SideNavItem label="Projects" icon={FolderIcon} href="/projects" />+ </SideNavSection>+ </MobileNav>+ </>+ );+ },+};diff --git a/packages/core/src/MobileNav/MobileNav.tsx b/packages/core/src/MobileNav/MobileNav.tsxindex 26f379712d..1743769b57 100644--- a/packages/core/src/MobileNav/MobileNav.tsx+++ b/packages/core/src/MobileNav/MobileNav.tsx@@ -225,7 +225,10 @@ const styles = stylex.create({display: 'flex',alignItems: 'center',justifyContent: 'space-between',- height: spacingVars['--spacing-12'],+ // At least one bar high, and taller for header content that needs it (a+ // stacked title and search, or a title wrapped at a larger text size), so+ // it never runs into the first item below.+ minHeight: spacingVars['--spacing-12'],paddingInline: spacingVars['--spacing-2'],flexShrink: 0,borderBlockEndWidth: borderVars['--border-width'],diff --git a/packages/core/src/MobileNav/__tests__/MobileNavHeader.a11y.chromium.spec.ts b/packages/core/src/MobileNav/__tests__/MobileNavHeader.a11y.chromium.spec.tsnew file mode 100644index 0000000000..ddf21a1c6d--- /dev/null+++ b/packages/core/src/MobileNav/__tests__/MobileNavHeader.a11y.chromium.spec.ts@@ -0,0 +1,89 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file MobileNavHeader.a11y.chromium.spec.ts+ * @input Built MobileNav stories in a phone context in real Chromium+ * @output Browser evidence that the header row is at least one bar high and+ * grows with taller header content: a stacked title and search field stay+ * inside the row, and the first navigation item starts below it+ * @position Chromium proof for MobileNav's header row (`styles.header` in+ * MobileNav.tsx, `minHeight`); jsdom has no layout to measure it+ */++import {expect, test, type Page} from '@playwright/test';+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.use({+ hasTouch: true,+ isMobile: true,+ viewport: {width: 390, height: 844},+ deviceScaleFactor: 1,+});++/** Opens a story's drawer and returns the boxes of its header row and first item. */+async function openAndMeasure(page: Page, story: string, firstItem: string) {+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-mobilenav--${story}&viewMode=story`,+ );+ await page.getByRole('button', {name: 'Open Navigation'}).click();+ const nav = page.getByRole('dialog');+ await expect(nav).toBeVisible();+ const close = nav.getByRole('button', {name: 'Close navigation'});+ // The Close button sits in the header row.+ const header = close.locator('xpath=..');+ const headerBox = await header.boundingBox();+ const itemBox = await nav+ .getByRole('link', {name: firstItem})+ .first()+ .boundingBox();+ if (headerBox == null || itemBox == null) {+ throw new Error('the drawer did not render');+ }+ return {nav, header, headerBox, itemBox};+}++test('a one-line header keeps the one-bar row', async ({page}) => {+ const {headerBox, itemBox} = await openAndMeasure(+ page,+ 'default',+ 'Dashboard',+ );+ // --spacing-12 at the default root size, as before.+ expect(headerBox.height).toBeCloseTo(48, 0);+ expect(itemBox.y).toBeGreaterThanOrEqual(headerBox.y + headerBox.height);+});++test('a taller header grows its row, and the first item starts below it', async ({+ page,+}) => {+ const {nav, headerBox, itemBox} = await openAndMeasure(+ page,+ 'tall-header',+ 'Dashboard',+ );+ expect(headerBox.height).toBeGreaterThan(48);+ const search = await nav.getByRole('textbox', {name: 'Search'}).boundingBox();+ if (search == null) {+ throw new Error('the search field did not render');+ }+ // The search field is inside the row, and nothing overlaps the first item.+ expect(search.y).toBeGreaterThanOrEqual(headerBox.y);+ expect(search.y + search.height).toBeLessThanOrEqual(+ headerBox.y + headerBox.height,+ );+ expect(itemBox.y).toBeGreaterThanOrEqual(headerBox.y + headerBox.height);+});