Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(AppShell): stretch content area in auto mode for sticky footer (#2440)

Cindy Zhangd1d2c923174f
diff --git a/apps/storybook/stories/AppShell.stories.tsx b/apps/storybook/stories/AppShell.stories.tsx
index 0e7b3b0d7c..63ba0d444a 100644
--- a/apps/storybook/stories/AppShell.stories.tsx
+++ b/apps/storybook/stories/AppShell.stories.tsx
@@ -53,6 +53,22 @@ const styles = stylex.create({
flexDirection: 'column' as const,
gap: 16,
},
+ footer: {
+ borderTop: '1px solid var(--xds-color-border-default, #e0e0e0)',
+ paddingBlock: 16,
+ paddingInline: 24,
+ display: 'flex',
+ justifyContent: 'space-between',
+ alignItems: 'center',
+ },
+ stickyFooterLayout: {
+ display: 'flex',
+ flexDirection: 'column' as const,
+ flex: 1,
+ },
+ stickyFooterContent: {
+ flex: '1 0 auto',
+ },
});
// =============================================================================
@@ -654,3 +670,93 @@ export const WithMobileNav: Story = {
);
},
};
+
+// =============================================================================
+// Sticky Footer — Auto Height
+// =============================================================================
+
+/**
+ * Demonstrates the sticky footer pattern in auto height mode.
+ * The footer pins to the bottom of the viewport when page content
+ * is shorter than the screen — no manual calc() or height hacks needed.
+ */
+export const AutoHeightStickyFooter: Story = {
+ render: () => (
+ <XDSAppShell contentPadding={6} topNav={<AppTopNav />} height="auto">
+ <div {...stylex.props(styles.stickyFooterLayout)}>
+ <div {...stylex.props(styles.stickyFooterContent)}>
+ <XDSText type="large">Short Page</XDSText>
+ <XDSText type="body">
+ This page has very little content, but the footer still pins to the
+ bottom of the viewport thanks to the auto-height flex stretch.
+ </XDSText>
+ </div>
+ <div {...stylex.props(styles.footer)}>
+ <XDSText type="supporting" color="secondary">
+ © 2025 Acme Inc.
+ </XDSText>
+ <XDSText type="supporting" color="secondary">
+ Privacy · Terms · Status
+ </XDSText>
+ </div>
+ </div>
+ </XDSAppShell>
+ ),
+};
+
+/**
+ * Auto height with sticky footer AND a side nav.
+ * Verifies the sticky footer works alongside the sticky sideNav behavior.
+ */
+export const AutoHeightStickyFooterWithSideNav: Story = {
+ render: () => (
+ <XDSAppShell
+ contentPadding={6}
+ topNav={<AppTopNav />}
+ sideNav={<SideNavWithoutHeader />}
+ height="auto">
+ <div {...stylex.props(styles.stickyFooterLayout)}>
+ <div {...stylex.props(styles.stickyFooterContent)}>
+ <XDSText type="large">Dashboard</XDSText>
+ <XDSText type="body">
+ Minimal content here — the footer stays at the bottom of the
+ viewport regardless.
+ </XDSText>
+ </div>
+ <div {...stylex.props(styles.footer)}>
+ <XDSText type="supporting" color="secondary">
+ © 2025 Acme Inc. All rights reserved.
+ </XDSText>
+ <XDSText type="supporting" color="secondary">
+ v2.4.1
+ </XDSText>
+ </div>
+ </div>
+ </XDSAppShell>
+ ),
+};
+
+/**
+ * Auto height with a long page — footer naturally appears after content.
+ * When content exceeds the viewport, the footer flows naturally below the
+ * content (no fixed pinning). This confirms the fix doesn't break scrolling.
+ */
+export const AutoHeightLongPageWithFooter: Story = {
+ render: () => (
+ <XDSAppShell contentPadding={6} topNav={<AppTopNav />} height="auto">
+ <div {...stylex.props(styles.stickyFooterLayout)}>
+ <div {...stylex.props(styles.stickyFooterContent)}>
+ <MockContent paragraphs={20} />
+ </div>
+ <div {...stylex.props(styles.footer)}>
+ <XDSText type="supporting" color="secondary">
+ © 2025 Acme Inc.
+ </XDSText>
+ <XDSText type="supporting" color="secondary">
+ Privacy · Terms · Status
+ </XDSText>
+ </div>
+ </div>
+ </XDSAppShell>
+ ),
+};
diff --git a/packages/core/src/AppShell/XDSAppShell.test.tsx b/packages/core/src/AppShell/XDSAppShell.test.tsx
index 92b034c6a2..47cf00b47d 100644
--- a/packages/core/src/AppShell/XDSAppShell.test.tsx
+++ b/packages/core/src/AppShell/XDSAppShell.test.tsx
@@ -602,6 +602,32 @@ describe('XDSAppShell', () => {
expect(observeSpy).not.toHaveBeenCalled();
});
+ it('applies flex column stretch to content area in auto mode', () => {
+ render(
+ <XDSAppShell height="auto" data-testid="shell">
+ <div data-testid="child">Content</div>
+ </XDSAppShell>,
+ );
+ // The content area (role="main") should be a flex column in auto mode
+ const main = screen.getByRole('main');
+ const style = getComputedStyle(main);
+ expect(style.display).toBe('flex');
+ expect(style.flexDirection).toBe('column');
+ });
+
+ it('does not apply flex column stretch to content area in fill mode', () => {
+ render(
+ <XDSAppShell height="fill" data-testid="shell">
+ <div data-testid="child">Content</div>
+ </XDSAppShell>,
+ );
+ const main = screen.getByRole('main');
+ const style = getComputedStyle(main);
+ // In fill mode, content area should NOT have flex-direction column
+ // (it uses default block layout with scroll containment)
+ expect(style.flexDirection).not.toBe('column');
+ });
+
// ===========================================================================
// Mobile nav slot
// ===========================================================================
diff --git a/packages/core/src/AppShell/XDSAppShell.tsx b/packages/core/src/AppShell/XDSAppShell.tsx
index 7ff82d1830..7f756180f1 100644
--- a/packages/core/src/AppShell/XDSAppShell.tsx
+++ b/packages/core/src/AppShell/XDSAppShell.tsx
@@ -429,6 +429,17 @@ const styles = stylex.create({
flex: 1,
overflow: 'auto',
},
+ // Content area fix for auto mode — makes the content a flex column so that
+ // children can use flex-grow to fill remaining vertical space (sticky footer
+ // pattern). Overrides height/overflow from XDSLayoutContent's default styles
+ // which assume fill-mode (fixed-height, internally scrollable) behavior.
+ contentAutoStretch: {
+ display: 'flex',
+ flexDirection: 'column' as const,
+ height: 'auto',
+ minHeight: '100%',
+ overflow: 'visible',
+ },
});
// =============================================================================
@@ -718,7 +729,7 @@ export function XDSAppShell({
role="main"
id={MAIN_CONTENT_ID}
isScrollable={isFill}
- xstyle={contentAreaStyle}>
+ xstyle={[contentAreaStyle, isAuto && styles.contentAutoStretch]}>
{children}
</XDSLayoutContent>
);