An open source design system that's fully customizable and agent ready
TypeScript
fix(Layout): a Layout with no contentWidth caps no header or footer (#10715)
Cindy Zhang0191e1370e67
diff --git a/.changeset/layout-default-content-width.md b/.changeset/layout-default-content-width.mdnew file mode 100644index 0000000000..79d60e418c--- /dev/null+++ b/.changeset/layout-default-content-width.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A `Layout` with no `contentWidth` no longer caps its `LayoutHeader` and `LayoutFooter` at the viewport's width. In a frame wider than the viewport, such as a scrolling canvas or a wide embed, their content now spans the frame like the rest of the Layout.++@cixzhangdiff --git a/apps/storybook/stories/Layout.stories.tsx b/apps/storybook/stories/Layout.stories.tsxindex 34da5bf604..343cc3baec 100644--- a/apps/storybook/stories/Layout.stories.tsx+++ b/apps/storybook/stories/Layout.stories.tsx@@ -125,6 +125,9 @@ const styles = stylex.create({borderRadius: radiusVars['--radius-container'],overflow: 'hidden',},+ wideFrame: {+ inlineSize: 2400,+ },cwContainerMatrix: {height: 240,},@@ -1430,6 +1433,39 @@ export const ContentWidthWider: Story = {),};+/**+ * A Layout with no `contentWidth` in a frame wider than the viewport: the+ * header and footer span the frame, as the content does.+ */+export const WiderThanViewport: Story = {+ name: 'No Content Width — Frame Wider Than the Viewport',+ render: () => (+ <div {...stylex.props(styles.wideFrame)} data-testid="wide-frame">+ <Layout+ defaultHasDividers+ header={+ <LayoutHeader data-testid="wide-header">+ <h3 {...stylex.props(styles.heading)}>Header</h3>+ </LayoutHeader>+ }+ content={+ <LayoutContent data-testid="wide-content">+ <p {...stylex.props(styles.bodyText)}>+ The frame is 2400px wide, wider than the viewport. With no+ contentWidth, nothing caps the regions.+ </p>+ </LayoutContent>+ }+ footer={+ <LayoutFooter data-testid="wide-footer">+ <p {...stylex.props(styles.bodyText)}>Footer</p>+ </LayoutFooter>+ }+ />+ </div>+ ),+};+export const ContentWidthResponsive: Story = {name: 'Content Width — Responsive Panels',render: () => (diff --git a/docs/specs/components/Layout/Layout.spec.md b/docs/specs/components/Layout/Layout.spec.mdindex b11a3a3d59..2e304732e3 100644--- a/docs/specs/components/Layout/Layout.spec.md+++ b/docs/specs/components/Layout/Layout.spec.md@@ -16,6 +16,7 @@ verified_by:packages/core/src/Layout/LayoutSlots.test.tsx,packages/core/src/Layout/__tests__/childrenAsContent.test.tsx,packages/core/src/Layout/__tests__/contentWidth.test.tsx,+ packages/core/src/Layout/__tests__/LayoutContentWidthDefault.a11y.chromium.spec.ts,packages/core/src/Layout/__tests__/nestedPadding.test.tsx,packages/core/src/Layout/__tests__/LayoutAudit.a11y.chromium.spec.ts,packages/core/src/theme/themingTargets.test.ts,@@ -206,18 +207,18 @@ Panel stands for every LayoutPanel, at logical start, end, or both.## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |-| FR1, ORD1, AV1 | `Layout.test.tsx` slot and content tests, including `reports a slot that renders nothing as empty`; `childrenAsContent.test.tsx`; `LayoutAudit.a11y.chromium.spec.ts` `closed-regions` receipts | Every slot; omitted slots; `false`, `true`, and `''` slots; `content` and `children` | A missing slot, `children` beating `content`, or a `false`, `true`, or `''` slot reported as filled fails. Gap: the omitted-slot test checks only the content text, so a wrapper rendered for an omitted slot passes, and no test asserts that slot content gains no target or element. The closed-region geometry has audit receipts only: the browser spec runs only for a Layout audit pull request. | `audit:Layout/anatomy` |-| FR2 | `Layout.test.tsx` height-reflection tests; `LayoutAudit.a11y.chromium.spec.ts` escape-margin and zero-publication receipts | `fill`, `auto` | A lost `data-height` reflection fails. Gap: no always-run check covers the escape margins, the zero publication, or the fill and auto heights; the browser spec that measures the margins and the publication runs only for a Layout audit pull request, so they have audit receipts only. | `audit:Layout/layout` |-| FR3, ORD2 | `nestedPadding.test.tsx` | Inside AppShell, Card, Section; nested full-bleed and padded Layouts; explicit nested padding | A nested Layout inheriting a parent Layout's padding, or losing the enclosing Card or Section padding or the default inset, fails. Gap: `Layout.test.tsx` padding tests assert only that rendering succeeds. | `audit:Layout/layout` |-| FR4 | `LayoutSlots.test.tsx` class tests; `themingTargets.test.ts` | Each region component; start and end panels | A lost region target fails. | `audit:Layout/theming` |-| FR5, ORD3 | `Layout.test.tsx` divider-default tests, including `a nested Layout without defaultHasDividers keeps its parent default` and `stops the default at a layer boundary` | Default true; unset; explicit `false`; nested Layout; inside a Dialog | A header or footer that ignores the default, an explicit `hasDivider={false}` that loses, a nested Layout that loses its parent's default, or a default that crosses a layer boundary fails. | `audit:Layout/layout` |-| FR6 | `contentWidth.test.tsx`; stable visual baseline `core-layout--content-width-scrollbar-placement` | No panels, start only, end only, both; zero padding; nested | A no-panel content region that is not full width, a both-panel middle that is not constrained, or a nested Layout inheriting content width fails; a scrollbar moved off its content edge comes back changed for review. A closed start or end slot has audit receipts only (`LayoutAudit.a11y.chromium.spec.ts` `closed-regions`, run only for a Layout audit pull request). | `audit:Layout/layout` |-| FR7 | `Layout.test.tsx` ref, className, style, passthrough, event-handler, and owned-metadata tests | Ref; caller inputs; event props; colliding `data-height` | A ref on another element, a dropped caller input or event handler, or a caller `data-height` that wins fails. Gap: no test pins the `xstyle` merge order. | `audit:Layout/api` |-| FR8 | `layoutReset.test.tsx`, which fails when Layout or Section writes a layout custom property the reset does not stop, and reads each reset value back inside a padded Section; the docsite's `example-layout-root.test.ts`, which fails when the docsite example root's mirror differs from the reset | Every custom property Layout and Section write; a padded Section host | A property written but not reset, a reset value an ancestor still overrides, or a docsite mirror that differs from the reset, fails. | `audit:Layout/layout` |-| AR1, AR2, PR1 | Source review | Every slot | Gap: no automated check fails if Layout adds a role, reorders slots, or adds a listener or measurement. | `audit:Layout/accessibility` |-| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current targets | Missing, extra, or stale mappings fail repository validation. | `audit:Layout/theming` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |+| FR1, ORD1, AV1 | `Layout.test.tsx` slot and content tests, including `reports a slot that renders nothing as empty`; `childrenAsContent.test.tsx`; `LayoutAudit.a11y.chromium.spec.ts` `closed-regions` receipts | Every slot; omitted slots; `false`, `true`, and `''` slots; `content` and `children` | A missing slot, `children` beating `content`, or a `false`, `true`, or `''` slot reported as filled fails. Gap: the omitted-slot test checks only the content text, so a wrapper rendered for an omitted slot passes, and no test asserts that slot content gains no target or element. The closed-region geometry has audit receipts only: the browser spec runs only for a Layout audit pull request. | `audit:Layout/anatomy` |+| FR2 | `Layout.test.tsx` height-reflection tests; `LayoutAudit.a11y.chromium.spec.ts` escape-margin and zero-publication receipts | `fill`, `auto` | A lost `data-height` reflection fails. Gap: no always-run check covers the escape margins, the zero publication, or the fill and auto heights; the browser spec that measures the margins and the publication runs only for a Layout audit pull request, so they have audit receipts only. | `audit:Layout/layout` |+| FR3, ORD2 | `nestedPadding.test.tsx` | Inside AppShell, Card, Section; nested full-bleed and padded Layouts; explicit nested padding | A nested Layout inheriting a parent Layout's padding, or losing the enclosing Card or Section padding or the default inset, fails. Gap: `Layout.test.tsx` padding tests assert only that rendering succeeds. | `audit:Layout/layout` |+| FR4 | `LayoutSlots.test.tsx` class tests; `themingTargets.test.ts` | Each region component; start and end panels | A lost region target fails. | `audit:Layout/theming` |+| FR5, ORD3 | `Layout.test.tsx` divider-default tests, including `a nested Layout without defaultHasDividers keeps its parent default` and `stops the default at a layer boundary` | Default true; unset; explicit `false`; nested Layout; inside a Dialog | A header or footer that ignores the default, an explicit `hasDivider={false}` that loses, a nested Layout that loses its parent's default, or a default that crosses a layer boundary fails. | `audit:Layout/layout` |+| FR6 | `contentWidth.test.tsx`; stable visual baseline `core-layout--content-width-scrollbar-placement`; `LayoutContentWidthDefault.a11y.chromium.spec.ts`, which fails when a Layout with no `contentWidth` caps its header or footer below the frame's width in a frame wider than the viewport | No panels, start only, end only, both; zero padding; nested; no content width in a frame wider than the viewport | A no-panel content region that is not full width, a both-panel middle that is not constrained, or a nested Layout inheriting content width fails; a scrollbar moved off its content edge comes back changed for review. A closed start or end slot has audit receipts only (`LayoutAudit.a11y.chromium.spec.ts` `closed-regions`, run only for a Layout audit pull request). | `audit:Layout/layout` |+| FR7 | `Layout.test.tsx` ref, className, style, passthrough, event-handler, and owned-metadata tests | Ref; caller inputs; event props; colliding `data-height` | A ref on another element, a dropped caller input or event handler, or a caller `data-height` that wins fails. Gap: no test pins the `xstyle` merge order. | `audit:Layout/api` |+| FR8 | `layoutReset.test.tsx`, which fails when Layout or Section writes a layout custom property the reset does not stop, and reads each reset value back inside a padded Section; the docsite's `example-layout-root.test.ts`, which fails when the docsite example root's mirror differs from the reset | Every custom property Layout and Section write; a padded Section host | A property written but not reset, a reset value an ancestor still overrides, or a docsite mirror that differs from the reset, fails. | `audit:Layout/layout` |+| AR1, AR2, PR1 | Source review | Every slot | Gap: no automated check fails if Layout adds a role, reorders slots, or adds a listener or measurement. | `audit:Layout/accessibility` |+| Theming anatomy map | `scripts/check-knowledge.mjs` | Consumer anatomy and current targets | Missing, extra, or stale mappings fail repository validation. | `audit:Layout/theming` |## Decision logdiff --git a/packages/core/src/Layout/Layout.tsx b/packages/core/src/Layout/Layout.tsxindex 9ad91ef020..73bea724b5 100644--- a/packages/core/src/Layout/Layout.tsx+++ b/packages/core/src/Layout/Layout.tsx@@ -79,9 +79,11 @@ const styles = stylex.create({'--container-padding-inline-end': '0px','--container-padding-block-start': '0px','--container-padding-block-end': '0px',- // Reset inherited width so nested Layouts without contentWidth keep their- // released padding. An explicit contentWidth overrides this on the same node.- '--layout-content-width': '100cqi',+ // A Layout without contentWidth caps no region: `initial` makes every+ // var(--layout-content-width, none) fall back to none. The alignment width+ // is read only inside the middle row's query container, where 100cqi is+ // its own width. An explicit contentWidth overrides both on this node.+ '--layout-content-width': 'initial','--layout-alignment-width': '100cqi',// A Layout's `padding` belongs to its own regions. Clear an ancestor// Layout's value so a nested Layout without `padding` takes the nearestdiff --git a/packages/core/src/Layout/__tests__/LayoutContentWidthDefault.a11y.chromium.spec.ts b/packages/core/src/Layout/__tests__/LayoutContentWidthDefault.a11y.chromium.spec.tsnew file mode 100644index 0000000000..864df310cc--- /dev/null+++ b/packages/core/src/Layout/__tests__/LayoutContentWidthDefault.a11y.chromium.spec.ts@@ -0,0 +1,69 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @pr-a11y scope ^(packages/core/src/Layout/|apps/storybook/stories/Layout\.stories)++/**+ * @file LayoutContentWidthDefault.a11y.chromium.spec.ts+ * @input The checked-in `core-layout--wider-than-viewport` story in real Chromium+ * @output Evidence that a Layout with no `contentWidth` caps no region+ * @position Real-browser check of `component:Layout`'s default content width:+ * only a browser resolves container-query units against the right container.+ */++import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++const STORY_ID = 'core-layout--wider-than-viewport';+const VIEWPORT = {width: 1280, height: 800};++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({viewport: VIEWPORT});++/** The border-box widths of a region and of the inner wrapper it pads. */+async function widths(+ page: Page,+ testId: string,+): Promise<{region: number; inner: number}> {+ return page.getByTestId(testId).evaluate(region => {+ const inner = region.firstElementChild;+ return {+ region: region.getBoundingClientRect().width,+ inner: inner?.getBoundingClientRect().width ?? 0,+ };+ });+}++test.describe('Layout with no contentWidth in a frame wider than the viewport', () => {+ for (const testId of ['wide-header', 'wide-footer']) {+ test(`${testId}: the inner wrapper spans the region, past the viewport`, async ({+ page,+ }) => {+ await page.goto(+ `${storybook.origin}/iframe.html?id=${STORY_ID}&viewMode=story`,+ {waitUntil: 'load'},+ );+ await page.getByTestId(testId).waitFor({state: 'attached'});+ const frame = await page+ .getByTestId('wide-frame')+ .evaluate(element => element.getBoundingClientRect().width);+ expect(frame).toBeGreaterThan(VIEWPORT.width);+ const {region, inner} = await widths(page, testId);+ expect(Math.round(region)).toBe(Math.round(frame));+ expect(Math.round(inner)).toBe(Math.round(region));+ });+ }+});diff --git a/packages/core/src/Layout/__tests__/contentWidth.test.tsx b/packages/core/src/Layout/__tests__/contentWidth.test.tsxindex 43ea88c03f..35e2e73673 100644--- a/packages/core/src/Layout/__tests__/contentWidth.test.tsx+++ b/packages/core/src/Layout/__tests__/contentWidth.test.tsx@@ -189,7 +189,7 @@ describe('Layout contentWidth', () => {getComputedStyle(nestedInner).getPropertyValue('--layout-content-width',),- ).toBe('100cqi');+ ).toBe('initial');expect(container).toHaveTextContent('Nested');});