Skip to content

feat(SideNav): collapse to a custom width, including zero, with optional animation (#2331) - #3890

Closed
AKnassa wants to merge 8 commits into
meta:mainfrom
AKnassa:feat/2331-sidenav-collapsed-width
Closed

AKnassa wants to merge 8 commits into
meta:mainfrom
AKnassa:feat/2331-sidenav-collapsed-width

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2331.

Problem

SideNav can only collapse to a 48px icon rail (rootCollapsed: {width: --spacing-12}), and it hard-snaps. Focused single-pane UIs (chat, editors) want the nav to slide away entirely, which the rail cannot express. Consumers are reduced to width: 0 !important overrides.

API

collapsible gains two keys:

const [isCollapsed, setIsCollapsed] = useState(false);
const collapsible = {isCollapsed, onCollapsedChange: setIsCollapsed};

<TopNav endContent={<SideNavCollapseButton collapsible={collapsible} />} />
<SideNav
  collapsible={{
    ...collapsible,
    hasButton: false,
    collapsedWidth: 0,   // px. defaults to the icon rail; 0 = fully hidden
    isAnimated: true,    // slide the content out and back in (collapsedWidth: 0 only)
  }}
/>

Defaults are untouched. Without collapsedWidth the nav still collapses to the icon rail; without isAnimated it still snaps.

Notes for review

Only transform animates (review item 1). The nav's width never tweens. For collapsedWidth: 0 the zones render inside a slide layer that translateXes out through the root's existing overflow: hidden, mirrored under RTL exactly like MobileNav's drawer. The box holds its expanded width for exactly the slide via a width transition on a step-end curve (transition: width var(--duration-fast) step-end), which computes no intermediate width, then snaps shut in a single reflow; the expanded state declares no width transition, so expanding snaps the box open and the layer slides back in. No JS and no transitionend, so interrupts are safe: re-expanding mid-slide cancels the pending snap (the width never moved) and the transform reverses from wherever it was. The icon rail always snaps, since animating it would mean animating width; isAnimated without collapsedWidth: 0 still snaps, and now warns once in development naming the width it got (a type-level union was ruled out: a hoisted config widens 0 to number). Hidden mode also reports isCollapsed: false through context, so items keep their expanded layout while they slide instead of morphing into the rail's icon-only form (the "inner fixed-width wrapper" from the review, done at the source).

Read from Chrome's animation engine, seeking the paused transitions: on collapse the nav carries exactly one CSSTransition: width, 175ms, steps(1) and the layer one CSSTransition: transform, 175ms; at 0/50/100/150/174.9ms the box is still 260px wide while the layer sits at 0/-173/-238/-258/-260px, and at 175ms the box is 0. Expanding at 80ms puts the box back at 260px at once with no width animation left on it, while the layer slides back. The only 0s duration in the emitted CSS is under prefers-reduced-motion, so scripts/build-css.test.mjs passes on a fresh build.

Focus is parked before inert lands (review item 2). The first fully-hidden render leaves inert off; a pre-paint layout effect moves focus, if it is inside the nav, to a SideNavCollapseButton rendered outside the nav (or blurs it explicitly when there is none), and inert lands in the synchronous follow-up commit, still before paint. Outside buttons register their element in a small module-level registry on mount, together with the collapse state they share with their nav: the controlled onCollapsedChange, or the deprecated handleRef. The nav parks focus only on a toggle that shares its state, so with two navs on a page each lands on its own toggle; with no match it blurs and warns once in development. The association is written on every render rather than re-registered when the callback identity changes, because a re-registration is detached in the mutation phase and re-attached in the layout phase, and a toggle placed after its nav would be missing when the nav's layout effect looks. The outside button is the right target because collapsedWidth: 0 needs one anyway: the built-in button hides with the nav. Verified in Chrome: focus a link inside the nav, collapse programmatically (no click, so nothing else moves focus), and focus ends on the toggle with the nav inert.

A resizable nav keeps its wrapper while collapsed. Dropping the resizableContainer on collapse moved the nav to a new parent, which remounted it and detached whatever had focus inside before any parking could run; the plain rail collapse of a resizable nav loses focus the same way on main today. Only the handle is conditional now, and the wrapper inherits the background so the nav's own background-color: inherit reaches the surface as it does without resize.

collapsedWidth has to beat the resizable width. Unchanged from round one: useResizable drives its size to 0 on collapse but SideNav always discarded that so the rail class could win; an explicit collapsedWidth takes precedence over both, pinned by a test.

No new tokens. --duration-fast / --ease-standard, which SideNavCollapseButton already animates its chevron with; reduced motion collapses both the slide and the stepped snap to 0s.

The issue's first proposed API is not implemented, on purpose. It suggests sideNavCollapsedWidth / sideNavTransition on XDSAppShell, but the v0.0.6 codemod deliberately migrated collapse config off AppShell onto SideNav.collapsible, so that is the surface this builds on.

Test plan

  • 41 tests in SideNav.test.tsx for this feature: the 8 width/inert/precedence tests, 12 for the slide (compiled StyleX rules read back from document.styleSheets: transform-only on the layer, step-end on the token duration for the collapsed root with no 0s outside the reduced-motion query, nothing on the expanded root, the RTL mirror, the slide under resizable-owned state, a byte-identical rail, and the isAnimated warning: fires for the rail and for a custom width, once per mount, silent for the supported pair), 18 for focus (the six from round two plus: two navs each land on their own toggle, a nav without a toggle never borrows the other's, per-nav handleRef and mixed wirings, a toggle through resizable-owned state, a toggle rendered after its nav with a callback recreated every render, a shared toggle for two navs, an unmounted toggle, an in-nav toggle handed the config, and the release-and-warn path warning once) and 3 for the resize wrapper (same nav element and parent across collapse, no wrapper without resize, background passed through).
  • Mutation-tested: the 10 mutations from round two plus an association that matches every toggle (4 tests fail) and step-end swapped for ease (2 tests fail).
  • SideNav.test.tsx: 235 passing after merging main. Full core suite from the repo root: 8701 passing. scripts/build-css.test.mjs: 8 passing on a fresh packages/core build.
  • pnpm -F @astryxdesign/core typecheck, CI=true eslint on the changed files and pnpm check:repo: clean.
  • Verified in Chrome (numbers above).

https://claude.ai/code/session_012JEJSAwvsxWNW4t6NnYWgR

…nal animation (meta#2331)

SideNav could only collapse to a 48px icon rail, and it hard-snapped. Focused
single-pane UIs — chat, editors — want the nav to slide away entirely, which
the rail cannot express.

`collapsible` gains two keys:

  collapsedWidth  collapsed width in px. Defaults to the icon rail; 0 hides the
                  nav entirely.
  isAnimated      animate the width change.

The animation reuses `--duration-fast` / `--ease-standard`, the tokens
SideNavCollapseButton already animates its chevron with — the same values the
issue asked for — so no new tokens are introduced. It honours
`prefers-reduced-motion`.

Two things worth calling out for review:

`collapsedWidth` has to beat the resizable width. useResizable already drives
its own size to 0 on collapse, but SideNav has always discarded that
(`width: collapsed ? undefined : size`) so the rail class could win. An
explicit collapsedWidth is the consumer overriding the rail, so it now takes
precedence over both.

A nav collapsed to zero width is invisible but still in the DOM: its links
would keep taking keyboard focus and stay in the a11y tree, stranding focus on
something the user cannot see. A fully hidden nav is therefore also `inert`.
The icon rail is visible, so it stays interactive — unchanged.

The issue's first proposed API (sideNavCollapsedWidth / sideNavTransition on
AppShell) is not implemented: AppShell has no collapse props, and the v0.0.6
codemod deliberately migrated them off it onto SideNav.collapsible. The
issue's second shape is the live surface, and is what this implements.

Defaults are untouched — without collapsedWidth the nav still collapses to the
icon rail, and without isAnimated it still snaps.

Claude-Session: https://claude.ai/code/session_01VYm8FsvUjk3xwDmonZRYeE
@vercel

vercel Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 26, 2026 4:29am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 12, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 12, 2026
@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

1 of 420 shot(s) changed. View the report

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
SideNav Resizable in AppShell probe dark 3,208
SideNav — Resizable in AppShell — probe dark
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@AKnassa
AKnassa marked this pull request as ready for review July 13, 2026 01:15

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this — it's a genuinely thoughtful PR, and the careful parts really show. Keeping the nav mounted and using inert (rather than unmounting) to drop the zero-width nav out of the focus order and a11y tree is exactly the right instinct, honoring prefers-reduced-motion by snapping is spot on, the width-precedence logic (explicit collapsedWidth beating both the rail class and the resizable size) is well-reasoned and well-tested, and it reuses the --duration-fast / --ease-standard tokens correctly. You also flagged the inert-timing question yourself, which is the right thing to have flagged. I'd love to get this in — two things to work through first.

1. Animate transform, not width (performance + our motion convention).
rootAnimated transitions width, which is a layout-triggering property — every frame reflows the nav's subtree and can shift sibling content, and there's no will-change/containment to soften it. Our design conventions ask that only transform/opacity animate for exactly this reason. Worth noting for framing: collapse on main is currently instant (no transition), so this is introducing the first collapse animation rather than matching an existing one — which is a nice opportunity to do it the compositor-friendly way from the start. Since the nav already has overflow: hidden, a transform: translateX slide (optionally paired with an inner fixed-width content wrapper so the contents don't squish) gets you the same visual without the per-frame layout. The SideNavCollapseButton precedent you cited actually animates transform, so this would also line the two up.

2. Focus handling when collapsing while focus is inside the nav (the timing question you raised).
Right now inert is applied synchronously the moment collapse starts (isFullyHidden = collapsed && collapsedWidth === 0), while the nav is still visibly sliding out. For the normal case that's fine. The sharp edge is: if a keyboard user's focus is inside the nav when they collapse it, putting inert on an ancestor of the focused element yanks focus to <body> immediately — a "where did my focus go" moment, and it happens before the visual has caught up. The usual fix is to move focus somewhere deliberate first (e.g. the collapse toggle / trigger) and then apply inert, so focus never gets orphaned. Could you add handling + a test for the "focus was inside the nav at collapse time" case? That closes the loop on the exact concern you called out.

Neither of these is a knock on the design — the API shape (collapsedWidth incl. 0, isAnimated) reads well and is consistent with the component's existing *Width config. Once the animation moves to transform and the focus-on-collapse case is handled, I'm happy to approve. Thanks again for the care you put into this.

@cixzhang

Copy link
Copy Markdown
Contributor

Checking in — it's been a month, and the review above is still the only thing between this and landing.

Outstanding: animate transform rather than width, and move focus somewhere deliberate before inert lands when the nav collapses with focus still inside it.

Still want to carry it? Happy to take either piece on myself with credit if you'd rather not, or to close it if you've moved on — it'd be welcome back any time.

[Reviewed by Robohands]

…ollapsed-width

# Conflicts:
#	packages/core/src/SideNav/SideNav.doc.mjs
#	packages/core/src/SideNav/SideNav.test.tsx
#	packages/core/src/SideNav/SideNav.tsx
…re inert (meta#2331)

Addresses the review on meta#3890.

Animate transform, not width. `isAnimated` no longer transitions the nav's
width (layout-triggering; the motion convention allows only transform and
opacity). For `collapsedWidth: 0` the zones render inside a slide layer that
translates out through the root's overflow clip, mirrored under RTL exactly
like MobileNav's drawer. The box itself never tweens: while collapsed it
declares a zero-duration width transition delayed by the slide's own
duration token, so it holds the expanded width for exactly the slide and
then snaps shut in one reflow; the expanded state declares no width
transition, so expanding snaps the box open and the layer slides back in.
No JS, no transitionend, and interrupts are safe: re-expanding mid-slide
cancels the pending snap and the transform reverses from wherever it was.
The icon rail always snaps, since animating it would mean animating width,
so `isAnimated` without `collapsedWidth: 0` is a no-op. Hidden mode also
reports `isCollapsed: false` through context, so items keep their expanded
layout while they slide instead of morphing into the rail's icon-only form.

Park focus before inert lands. Applying `inert` to an ancestor of the
focused element yanks focus to <body>. The first fully-hidden render now
leaves inert off; a pre-paint layout effect moves focus, if it is inside
the nav, to a SideNavCollapseButton rendered outside the nav (or blurs it
explicitly when there is none), and inert lands in the synchronous
follow-up commit, still before paint. Outside buttons register their
element in a module-level registry on mount, whichever way they are wired
(the controlled `collapsible` config or the deprecated `handleRef`), so
nothing is added to the deprecated handle.

Tests read the compiled StyleX rules back from document.styleSheets to pin
the choreography (transform-only on the layer; width 0s plus delay on the
collapsed root; nothing on the expanded root) and spy on focus() to pin
that inert is not yet present when focus moves. Ten mutations of the
implementation each fail exactly the test aimed at them. A `Hidden
Collapse` story wires an outside toggle to a `collapsedWidth: 0` nav.
…ollapsed-width

# Conflicts:
#	packages/core/src/SideNav/SideNav.test.tsx
#	packages/core/src/SideNav/SideNav.tsx
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Aug 27, 2026
@AKnassa

AKnassa commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Still carrying it, thanks for the nudge. Both are in cf06135: the hidden collapse now animates transform only (the box holds its width for the slide through a zero-duration, delayed width transition, then snaps once), and a fully hidden collapse parks focus on the outside SideNavCollapseButton, or blurs, before inert lands. Also merged main. Details and the Chrome measurements are in the updated description.

github-actions Bot added a commit that referenced this pull request Aug 27, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the original review. Three current-head blockers remain:

  • With two SideNav instances, collapsing the second moves focus to the first toggle; keyboard users land on the wrong control. Please associate each nav with its own toggle.
  • isAnimated: true silently does nothing unless collapsedWidth is exactly 0. Please prevent or warn on unsupported combinations, or make the promise hold across accepted values.
  • The zero-duration width rule fails scripts/build-css.test.mjs on this exact head. Please preserve the transform-only result without emitting the rejected production rule.

[Reviewed by Robohands]

…pping isAnimated, hold the box on step-end (meta#2331)

Review round 2 on meta#3890.

- The outside SideNavCollapseButton registers with the collapse state it
  shares with its nav (the controlled onCollapsedChange, or the deprecated
  handleRef), and the nav parks focus only on a toggle that matches. With
  two navs on a page the first registered toggle no longer wins. No match
  blurs and warns once in development.
- isAnimated without collapsedWidth: 0 warns in development, naming the
  width it got, instead of silently snapping.
- The width hold is a step-end transition on --duration-fast rather than a
  zero-duration delayed one: no intermediate width is computed and the only
  0s lives under prefers-reduced-motion, which scripts/build-css.test.mjs
  requires.
- A resizable nav keeps its wrapper while collapsed, so collapsing no longer
  remounts the nav and drops the focus inside it; the wrapper inherits the
  background so the nav's own inherit reaches the surface.

Claude-Session: https://claude.ai/code/session_012JEJSAwvsxWNW4t6NnYWgR
@github-actions
github-actions Bot requested a review from cixzhang September 3, 2026 02:26
@AKnassa

AKnassa commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all three addressed in 1529fd9, on top of a fresh merge of main.

  • Two navs: the outside button now registers with the collapse state it shares with its nav (the controlled onCollapsedChange, or the deprecated handleRef), and the nav only parks focus on a toggle that matches. No match means a deliberate blur plus a one-time dev warning, never another nav's control.
  • isAnimated without collapsedWidth: 0 warns in development, naming the width it got. A type-level union was ruled out because a hoisted config widens 0 to number.
  • The width hold is now transition: width var(--duration-fast) step-end. No intermediate width is computed and the only 0s is under the reduced-motion query, so scripts/build-css.test.mjs passes on a fresh build. Measured in Chrome: the box holds 260 through 174.9ms and snaps at 175ms; expanding mid-slide snaps it open at once.

One more thing surfaced by the two-nav test: a resizable nav dropped its wrapper on collapse, which remounted the nav and sent focus to body before anything could park it (the plain rail collapse loses focus the same way today). The wrapper now stays and only the handle goes; it also inherits the background so the nav's own inherit reaches the surface.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for building this — the opt-in shape preserves the default rail, and the transform slide, per-nav focus parking, and resize-wrapper fix are well tested.

Approval is waiting on a maintainer decision: please provide or identify the governing spec for the new SideNav semantics — collapsedWidth defaulting to the 48px rail, 0 meaning fully hidden, non-zero meaning a visible custom rail, precedence over the resizable width, isAnimated effective only at 0 with a development warning otherwise, hidden content keeping its expanded layout, and focus parked on the outside toggle that shares the nav's collapse state. Name that record and confirm it settles the semantics as implemented.

One independent fix is also needed before approval: a fully hidden nav must stay inert even if a caller passes inert={false}. Today the consumer prop is spread after the computed inert attribute, so it can leave an invisible nav focusable. Please make the hidden state win and add a regression test for that override.

[Automated review]

Resolved conflicts (both sides kept):
- packages/core/src/SideNav/SideNav.tsx: tokens import now carries the
  PR's durationVars/easeVars plus main's focusVars (meta#6196).
- packages/core/src/SideNav/SideNav.tsx: resizableContainer keeps the PR's
  backgroundColor: 'inherit' plus main's overflow: 'clip', and main's new
  resizableHandle style (meta#6196).
- packages/core/src/SideNav/SideNav.tsx: the PR's conditional
  {showResizeHandle && <ResizeHandle .../>} (wrapper stays mounted while
  collapsed) now passes main's xstyle={styles.resizableHandle}.
- apps/storybook/stories/SideNav.stories.tsx: imports keep the PR's
  useState plus main's AppShell.
…ta#2331)

Addresses astracat-bot review 5298959005:

- F2 (fix): the computed `inert` sat before `{...props}`, so a caller's
  `inert={false}` (or a wrapper forwarding `inert={undefined}`) replaced it
  and left an invisible, collapsedWidth: 0 nav focusable. The attribute now
  renders after the spread as
  `(isFullyHidden && isInertApplied) || props.inert || undefined`: the hidden
  state always wins, a consumer `inert` on an expanded nav still passes
  through, and the pre-paint focus-parking gate is unchanged.
  Tests: "keeps a fully hidden nav inert when the caller passes
  inert={false}" (red before: expected attribute inert, received null);
  "still honors a consumer inert on an expanded nav" (guards against simply
  moving the old expression after the spread); "still parks focus, then
  goes inert, when the caller passes inert={false}". The focus Harness now
  forwards an optional `inert`, which also turned the existing "moves focus
  to the outside collapse toggle before inert lands" red before the fix
  (the forwarded `inert={undefined}` overrode the hidden state).
- F1 (governing spec) is a maintainer decision and is not addressed here.
@AKnassa

AKnassa commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Pushed b35d6d0, on top of a merge of main (810a494).

  • Merged main: it conflicted with fix(SideNav): prevent resizable overflow #6196 in the resizable wrapper. The wrapper now keeps main's overflow: 'clip' and resizableHandle style alongside this PR's backgroundColor: 'inherit'.
  • Hidden nav vs. a consumer inert: the computed inert was rendered before {...props}, so passing inert={false}, or a wrapper forwarding inert={undefined}, left a collapsed collapsedWidth: 0 nav focusable. It now renders after the spread as (isFullyHidden && isInertApplied) || props.inert || undefined. A fully hidden nav is always inert, a consumer inert on an expanded nav still passes through, and focus still moves to the outside toggle before inert lands. Three tests cover those cases (b35d6d0).

On the governing spec: I haven't written a SideNav spec, since AGENTS.md leaves missing authority to maintainers. @cixzhang, in your first review you said the collapsedWidth / isAnimated shape was consistent with the existing *Width config. Could you name or approve the record that should govern these semantics? They are: the rail default, 0 = hidden and inert, non-zero = a visible custom rail, precedence over the resizable width, isAnimated only at 0 with a dev warning, the expanded layout kept while hidden, and focus parked on the matching outside toggle. I'm happy to adjust to whatever it settles. Your 09-02 blockers were addressed in 1529fd9. Could you take another look when you have a moment?

Still to do on my side: add a line to the PR body saying a fully hidden nav stays inert whatever inert is passed, and confirm the build-css suite passes in CI on this head.

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for carrying this through several rounds: the opt-in shape keeps the default rail, and the inert precedence and per-nav toggle pairing hold up. Approval is waiting on an engineering owner to provide or identify the governing spec for the new semantics: collapsedWidth (rail default, custom rail width, 0 hides the nav, precedence over the resizable width) and the hidden state (always inert, children see isCollapsed: false, focus moved first to the matching outside toggle). An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are one. Independently, these need changes:

  • main now requires every edge reveal in Core to use one shared edge reveal (AST-105 FR9) and gives the rail its own collapse motion (SideNav FR6). Please rebase (the branch conflicts in SideNav.tsx), rebuild isAnimated on the shared reveal or drop it, and update the "the rail always snaps" warning and changeset text.
  • An outside toggle that mounts with the collapse after the nav is not found, so focus drops to <body> with a misleading warning. Retrying the lookup one commit later, with a test for that order, would fix it.
  • Switching collapsedWidth or isAnimated at runtime remounts the nav's content; keeping the zones under one stable element would avoid that.

[Automated review]

cixzhang pushed a commit that referenced this pull request Nov 1, 2026
…ch the SideNav rail moves onto (#8721)

Implements the records #8783 put on main: `spec:AST-105` FR2 and FR9, `architecture:react-component-runtime` INV12, `component:SideNav` FR6, `component:Resizable` FR8, `component:LayoutPanel` FR7 and AR2, and `component:Table` FR15. Resizable's and LayoutPanel's slide and LayoutPanel's focus rule (AR2: focus moves to the ResizeHandle only when a collapsing pane holds it) are built on this path in #9197 and #9202. This PR moves no focus anywhere.

Behavior-module PR: `packages/core/src/motion/animatedLayout.ts` (FR9's shared edge reveal).

## User need

A panel that collapses beside content, a Collapsible closed while it opens, a resizable pane sliding shut: each reveals or conceals an element from one of its edges while the content beside it moves. Before this change Core had one such reveal of its own per component. The SideNav rail clipped and rode its content in its own code. Collapsible's reveal could only open downward, and a close while it opened restarted the conceal from fully shown while the content below kept gliding, so a gap opened. Nothing a resize controller could reuse existed. #8783 made these one shared edge reveal in the animated-layout module.

## Problem and solution fit

The animated-layout module now produces `spec:AST-105` FR9's edge reveal, in three forms over one ride:

- **One-state** (`playLayoutChange`, `holdLayoutExit`): reveals and conceals from the block-end edge by default, or from the block-start or an inline edge it is given, mirrored right to left. Once the content on that edge's side glides, the moving edge rides that glide frame by frame (its keyframes replaced, its clock the glide's), so no gap opens. It rides the content's offset relative to the element: when the same batch also moves the element itself, such as an item above them closing in a single-open CollapsibleGroup, the edge follows only the difference. A conceal by a start edge frees the element's space on that edge's side, so the element stays where it shows while the content before it moves; a layout where that would move the element itself is not held, and the element goes at once. A reversal starts from what the element shows. Collapsible, TreeList and Table's row expansion already play this block-end form, so they gain the ride, and Collapsible and TreeList, which hold their exits, the reversal too.
- **Two-state** (`holdLayoutEdge`, `playLayoutEdge`): holds the old state as FR8's swap copy, clips the larger state on the edge from the extent it shows, rides a gliding element, and raises the element above the copy while it conceals. The SideNav rail now plays through it on its inline-end edge and keeps only its labels' and icons' fades (`component:SideNav` FR6); its frames are unchanged.
- **A resized element with no copy** (`reportLayoutEdge`): measured before a size change commits and played after the new size applies. A larger extent reveals from the extent shown. A smaller one holds the element at the extent it was laid out at, freeing the difference by the margin on that edge's side so what lies beyond stays where the new size puts it, then clips down to the new extent. This is the path a resize controller's pane uses (`component:Resizable` FR8 and `component:LayoutPanel` FR7 in #9197 and #9202).

Reduce Motion follows `design:reduced-motion` DR2 under a coarse primary pointer and DR3 otherwise.

## Current specification

`spec:AST-105` FR9 ("One shared edge reveal") and FR2, `architecture:react-component-runtime` INV12, `component:SideNav` FR6, `component:Resizable` FR8, `component:LayoutPanel` FR7 and AR2, and `component:Table` FR15, all current on main since #8783. A LayoutPanel given a hand-built `ResizableProps` gets no slide, and the hook's own `props` passed through `resizable` slide; both are #9197 and #9202's to implement.

## Public delta and caller burden

None. The new functions and types stay internal: no entry point exports them (`animatedLayout.boundary.test.ts` checks this), and `useAnimatedLayout`'s contract is unchanged. The visible changes are Collapsible's and TreeList's: content closed while it opens, or opened while it closes, continues from what it shows, and its edge stays on the content after it (`[fix]` changeset). Table's row expansion reveal rides the rows after it.

## Design and alternatives

- **Riding:** the edge's keyframes are sampled on the glide's own sample grid and clock, so the clip and the glide are complementary by construction. The alternative, a separate spring tuned to match, drifts whenever the glide carries a running motion.
- **Resized element without a copy:** holding the old extent keeps the pane's content laid out as it was. Clipping a pane already at its new size would need its content to overflow, or a copy, which the runtime record rules out for a resize controller.
- **Morph routing** of the glide stays out until the shared rect morph lands (#8329), as INV12's "until then" clause says.

## Evidence

Status at this head: rebased onto main 8a03d75 after the component records moved to `docs/specs/components/`; the patch is byte-identical to 70ebcc7's. Here, build, type check, CI-strict lint, `check:knowledge`, the record-path tests (knowledge paths, check-knowledge, specs-for-file), `check:changesets` and the motion, SideNav and AppShell unit suites (1,020) pass, and `specs:for` still returns `component:SideNav` and `spec:AST-105` for the changed files. At 70ebcc7 every gate finished: `test:ui`, `check:repo`, the node suites (only the two `cache.test.mjs` lock cases that fail on main), and the three motion specs ×10 in WebKit under the CI job's command (740, with 100 Chromium-only skips) and in Chromium pinned to 2 cores at 4 workers (840). **Still running:** `test:ui`, the node suites, `check:repo` and the three motion specs ×10 in both engines at this head.

Each new proof failed on main first:
- `animatedLayout.edge.test.ts`: 17 of the 18 one- and two-state cases fail on main (the block-end default passes there and guards it), and the resized-element cases have no function there.
- `SideNavRailMotion.test.tsx`: a new case asserts the rail plays through the module's two-state form with no clip, copy or ride of its own. It fails on main; the rail's existing cases pass unchanged with the rail moved.
- `animatedLayout.interaction.browser.spec.ts` (FR9): a block-end reveal reversed into a conceal, an inline-end reveal and conceal (LTR and RTL), the two-state form, and a resized pane (start pane LTR to 48 px, start pane RTL to 0, end pane LTR to 48), each with a reversal. On every frame the moving edge stays within 1.5 px of what it rides. All fail on main: the block-end reversal jumped 40 px, the inline edge was clipped from the bottom, and the other forms don't exist there.
- `animatedLayoutAdopters.interaction.browser.spec.ts`: a Collapsible closed while it opens, and a TreeList row collapsed while it expands, keep their edge on the content after them. On main each conceal restarted from fully shown: −16 px and −36 px gaps.

Two more cases guard this PR's own paths. A block-start reveal and conceal in a column that stacks from its end keep the edge on the content before it, with the element staying where it shows; before the start-edge fix the conceal freed its space at its end, so the element jumped by its 80 px and an 80 px gap opened. And in a single-open CollapsibleGroup switching from a taller item to a shorter one below it, the opening item's edge stays on the next item on every frame; before the ride was taken relative to the element, the content showed 31 px over the next item.

How the proofs read a ride: both sides on the module's clock, the edge from its clip animation's keyframes and what it rides from its layout position plus its glide's keyframes, at the animations' current time. Chromium also asserts that its evaluated clip and rect equal those (under 0.5 px). In WebKit the two run a little apart, and that skew is reported per test, not hidden: a compositor-run `translate` is evaluated a little ahead of the frame and, on a late first frame, a main-thread clip reads one frame behind. Under the CI WebKit job's command (`LP_NUM_THREADS=4`), the summed skew per frame reached 0.7 to 3.4 px depending on the test. The reversals pause and seek every animation to 120 ms, and the adopters' wait for the component to commit the close before playing on, so neither a late first frame nor a component committing in a later task moves the moment they test.

## Scope

- [x] One capability is added (FR9's shared edge reveal), with its adopters in this PR's scope (the SideNav rail; Collapsible, TreeList and Table's row expansion keeping their form).
- [x] Unrelated fixes, cleanup, and policy changes were removed or split. Resizable's and LayoutPanel's adoption is #9197 and #9202.
- [x] Consumer docs, focused tests, and migration evidence ship with the feature.
- [x] Public text and artifacts contain no internal Meta context.

Overlaps: #8677 also edits `motion/animatedLayout.ts` (the theme's motion knobs), and #3890 edits `SideNav/SideNav.tsx`. This PR leaves `SideNav.tsx` unchanged.

## Testing

```
pnpm exec vitest run --project ui packages/core/src/motion packages/core/src/SideNav packages/core/src/AppShell packages/core/src/Collapsible packages/core/src/TreeList packages/core/src/Table
pnpm build && pnpm storybook:build
pnpm test:interaction packages/core/src/motion/__tests__/animatedLayout.interaction.browser.spec.ts packages/core/src/motion/__tests__/animatedLayoutAdopters.interaction.browser.spec.ts packages/core/src/SideNav/__tests__/SideNavRailMotion.interaction.browser.spec.ts --project chromium
```
For WebKit, use the CI WebKit job's container command (`internal/interaction-harness/scripts/webkit-container.mjs`) with podman `--cpus=4`, `CI=1`, `LP_NUM_THREADS=4` and 1 worker.
@cixzhang

Copy link
Copy Markdown
Contributor

(Posted by Cindy's agent.) Thank you, @AKnassa, for this! Your work on hiding the side nav while keeping it mounted directly shaped #10312, which builds the hide-and-keep part on AppShell's hiddenRegions and credits you as co-author. We're closing this version because the SideNav spec keeps a collapse to an instant snap to the icon rail (no width animation), so collapsedWidth and isAnimated don't fit there. #10312 carries the idea forward.

This branch was successfully deployed

1 active deployment
Preview — b35d6d00 Deployed Sep 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AppShell: support collapsing sidenav to zero width with animation

2 participants