Skip to content

feat(lab): reselecting a TabBar tab scrolls its panel to the top - #9966

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:tabbar/lab-reselect-scroll-top
Nov 10, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:tabbar/lab-reselect-scroll-top

Conversation

@vjeux

@vjeux vjeux commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

User need

On iOS, tapping the current tab brings its section back to the top. Today each app must find and animate that section's scroll area, and a wrong guess scrolls the page.

Problem and solution fit

Choosing the selected tab again (tap, click or key) scrolls that tab's own scroll area to its top. TabBar finds the panel by the tab's panelId: the panel itself if it scrolls vertically, else the first element inside that does. Core's scroll test skips a row that overflows by a pixel or less, or only sideways. Nothing else scrolls. It glides; under Reduce Motion it jumps. onReselect still fires, so an app can also reset its navigation stack.

Current specification

Public delta and caller burden

No new props. A tab naming its panel (panelId) scrolls it on reselect; others behave as before. Put each section in a ScrollableArea inside its panel, or make the panel scroll:

<div id="panel-home" role="tabpanel" aria-label="Home">
  <ScrollableArea label="Home">{rows}</ScrollableArea>
</div>
<TabBarItem value="home" label="Home" icon={<Icon icon={HomeIcon} />} panelId="panel-home" />

Design and alternatives

  • It uses the browser's smooth scroll, as Core's Carousel does.
  • Core's scroll test (measureLogicalScrollAxis, as ScrollableArea uses) finds it.
  • Rejected: a ref per tab (panelId already names the panel) and scrolling the document (it moves scrollers outside the tab).

Evidence

Desktop Chrome 149, a mouse at normal speed, the story #10922 added (then named Scroll To Top). It was recorded at b661856, whose TabBar.tsx and panelScroll.ts equal this head's. Home's list is scrolled down, then a click, Enter and Space each choose Home again. Main never scrolls; this change glides it to the top each time, its pinned rows still. The page draws the pointer, which headless recordings lack.

Before: main, desktop Chrome
After: this change, desktop Chrome

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

Local gates at c72f46e, on main 713d9ce, node 24.22.1 from .nvmrc:

  1. Red-first, built Storybook, 1 worker: main's TabBar with this PR's tests (6b7f9b8) leaves the reselected panel where it was. The four scroll cases fail in each engine; choosing another tab still passes. Its four new unit cases fail too.
  2. Red-first, unit: a lookup that takes the first element taller than its box (cff48b9) takes a chip row that overflows by a pixel. The list below never scrolls (2 failed).
  3. Interaction specs, 1 worker: the reselect cases 5/5 in Chromium and 5/5 in WebKit. The whole TabBar spec: Chromium 68 passed, WebKit 58 passed and 10 skipped.
  4. Units: 74 in Lab's TabBar and TabBarMoreList.
  5. Static: Lab typecheck; ESLint and Prettier on the changed files; pnpm check:repo; review:pre, no findings.

@vercel

vercel Bot commented Nov 4, 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 Nov 10, 2026 5:56am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 4, 2026
@astracat-bot

astracat-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 10, 2026, 6:10 AM UTC

@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.

This needs an engineering owner's decision before it can be approved, and it needs changes either way.

No current record governs Lab TabBar or its new reselect rule (choosing the selected tab again scrolls the panel named by panelId, or its first vertically scrolling element, to the top, and still calls onReselect). The Lab exemption does not apply because the diff against main also changes Core. An engineering owner, the author included, can approve that direction by commenting /approve-spec with the full head commit SHA, or name the record that must govern it first.

Blocking findings:

  • Merged with current main, the createMotionAnimator to createMotionEngine rename leaves packages/core/src/DateInput/wheelStrip.ts (lines 19 and 135) and a new call at packages/core/src/motion/animator.test.ts:4370 importing a removed export, and packages/lab/src/index.ts conflicts, so rebase onto the current #9754 head or main.
  • The diff against main is 6,099 authored lines from four separable pull requests with no Stack: line here, so put one identical Stack: #9754 → #9699 → #9700 → #9966 line in every listed description, with each head built on the one below, or land the lower pull requests first.
  • TabBar turns off the shared action-group tracker's press paint (useTabBarLens.ts:607) and repaints the same tab with its own data-tab-bar-pressed attribute (useTabBarLens.ts:80-90), so pass paintsHighlight: !isTouch || selectedIndex < 0 and style the shared data-astryx-press attribute instead, or extend the shared tracker and say why it cannot serve.
  • TabBar.doc.mjs (lines 46 and 118) tells builders to use a NavigationStack that no package provides, and implies the panel scrolls only at a stack's root, while TabBar scrolls on every reselect.

The reselect scroll itself works as described in the Scroll To Top story, but CI has not run on this head yet.

[Automated review]

Comment thread packages/core/src/motion/animator.ts Resolved
Comment thread packages/lab/src/TabBar/TabBar.doc.mjs Resolved
@vjeux

vjeux commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Restacked onto #9700's new head. The docs now say "return the tab's navigation stack to its root" without naming a component, and that TabBar scrolls the tab's panel to its top on every reselect.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · c72f46e

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC
lab/TabBar 77.5 kB (+492 B) · 1.8 kB CSS (0) —
lab/TabBarItem 3.8 kB (0) · 1.8 kB CSS (0) —

Package size: no published package changed; no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 29 rows, core 36 rows; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/approve-spec de5fe68

@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.

Changes are needed in #9754, and #9700 and #9966 wait on an engineering owner's decision.

#9754: changes requested

  • .changeset/core-internal-touch-entry-lab-animator.md says Lab's PageControl and NavigationStack read the new internal-entry names, but no package ships either component, so name only TabBar (or "Lab components") in that release note.

#9699: can be approved on its own.

#9700: waiting on an owner decision

  • No current record governs Lab TabBar and TabBarItem, and the stack also changes Core and the Storybook app, so the Lab exemption does not apply: an engineering owner approves this direction by commenting /approve-spec with the full head SHA, or names the record that must govern it, and the author may do so if they are an engineering owner.

#9966: waiting on the same decision

  • No current record governs the reselect rule (choosing the selected tab again scrolls the panel panelId names, or its first vertically scrolling element, to the top, and still calls onReselect), and the same /approve-spec covers it.

Whole stack: changes requested, because of the #9754 changeset. A pull request lands only when it and every pull request below it are approved, and CI has not run on this head yet.

[Automated review]

@vjeux
vjeux force-pushed the tabbar/lab-reselect-scroll-top branch from de5fe68 to 372e68f Compare November 5, 2026 09:07
@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 372e68f

@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.

This stack waits on an engineering owner's decision; no code changes are needed.

#9754: can be approved on its own. The internal rename and re-exports stay on Core's internal entry, and the release note now names no component the stack does not ship.

#9699: can be approved on its own. The tracker's new options are optional, and AlertDialog's path is unchanged.

#9700: waits on an engineering owner's decision.

  • No current spec record governs Lab TabBar and TabBarItem (the selection lens, press tracking and badges), so an engineering owner needs to approve them as Lab direction.

#9966: waits on an engineering owner's decision.

  • No current spec record governs the reselect rule: choosing the selected tab again scrolls the panel its panelId names (the panel itself if it scrolls vertically, else the first vertically scrolling element inside it) to the top, smoothly or as a jump under Reduce Motion, and still calls onReselect.

Whole stack: the cumulative change has no blocking issue. A pull request lands only when it and every pull request below it are approved.

This direction was approved at the stack's previous head, but the restack reset that approval. An engineering owner records it again by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner. CI has not run on this head yet.

[Automated review]

Comment thread packages/lab/src/TabBar/TabBar.tsx Resolved
@cixzhang

cixzhang commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Specs & Decisions agent for Cindy: approved under the Lab grant and Cindy's tap-to-top go: choosing the selected tab again scrolls the panel its panelId names (the panel itself if it scrolls vertically, else the first vertically scrolling element inside it) to the top, smoothly, or as a jump under Reduce Motion, and still calls onReselect. (Core changes in this diff belong to #9754 and #9699 beneath it, approved separately.) /approve-spec 372e68f

@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.

Approved pending CI: CI has not run on this head yet. It runs once these drafts are marked ready for review and a maintainer adds the ci:run label.

#9754: approve. No blocking findings.

#9699: approve. No blocking findings.

#9700: approve. No blocking findings; an engineering owner approved Lab TabBar and TabBarItem as Lab direction at this pull request's head.

#9966: approve. No blocking findings; an engineering owner approved the reselect-to-top rule at this head, and it behaves as approved.

Whole stack: no blocking issue. A pull request lands only when it and every pull request below it are approved.

[Automated review]

@vjeux
vjeux marked this pull request as ready for review November 5, 2026 09:59
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 5, 2026
@cixzhang
cixzhang marked this pull request as draft November 5, 2026 10:05
@cixzhang
cixzhang marked this pull request as ready for review November 5, 2026 10:05

@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.

This stack waits on an engineering owner's decision; no code changes are needed.

#9754: can be approved on its own. No blocking findings.

#9699: can be approved on its own. No blocking findings.

#9700: waits on an engineering owner's decision.

  • No current spec record governs Lab TabBar and TabBarItem (the selection lens, press tracking and badges), so an engineering owner needs to approve them as Lab direction at this pull request's current head.

#9966: waits on an engineering owner's decision.

  • No current spec record governs the reselect rule: choosing the selected tab again scrolls the panel its panelId names (the panel itself if it scrolls vertically, else the first vertically scrolling element inside it) to the top, smoothly or as a jump under Reduce Motion, and still calls onReselect.

Whole stack: no blocking issue. A pull request lands only when it and every pull request below it are approved.

Merging main into each pull request made new heads, and an approval counts only at its exact head. An engineering owner records the direction again by commenting /approve-spec <full head SHA> on #9700 and on this pull request; the author may do so as an engineering owner.

[Automated review]

@cixzhang

cixzhang commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Specs & Decisions agent for Cindy: approved under the Lab grant and Cindy's tap-to-top go: choosing the selected tab again scrolls the panel its panelId names (the panel itself if it scrolls vertically, else the first vertically scrolling element inside it) to the top, smoothly, or as a jump under Reduce Motion, and still calls onReselect. (Core changes in this diff belong to #9754 and #9699 beneath it, approved separately.) /approve-spec 5af8812

@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.

Changes are needed in #9966; #9754, #9699 and #9700 can be approved.

#9754: approve. No blocking findings.

#9699: approve. No blocking findings.

#9700: approve. No blocking findings; an engineering owner approved Lab TabBar and TabBarItem as Lab direction at this pull request's current head.

#9966: changes requested.

  • Miss: panelScrollArea in packages/lab/src/TabBar/panelScroll.ts (lines 29-34) tests for a scroller with its own scrollHeight > clientHeight instead of Core's shared effective-scroll test in packages/core/src/hooks/scrollGeometry.ts, which needs content more than 1 px taller than the box, so a sideways chip row whose chips are 1 px taller than the row is taken and choosing Home again leaves Home's list where it was; re-export Core's test through the internal entry and call it, with a unit case for that row, or say in the code why it cannot serve.

Whole stack: no further blocking issue. A pull request lands only when it and every pull request below it are approved.

[Automated review]

Comment thread packages/lab/src/TabBar/panelScroll.ts Resolved
@vjeux
vjeux marked this pull request as draft November 5, 2026 12:07
@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Specs & Decisions agent for Cindy: approved under the Lab grant and Cindy's tap-to-top go: choosing the selected tab again scrolls the panel its panelId names (the panel itself if it scrolls vertically, else the first vertically scrolling element inside it) to the top, smoothly, or as a jump under Reduce Motion, and still calls onReselect. (Core changes in this diff belong to #9754 and #9699 beneath it, approved separately.) This head also adds an internal-only Core re-export of measureLogicalScrollAxis for Lab TabBar (no public API change). /approve-spec 76a2f2a

@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.

This pull request waits on an engineering owner's decision, and it needs one change either way.

  • No current spec record governs Lab TabBar and TabBarItem or the reselect rule: choosing the selected tab again scrolls the panel its panelId names (or the first vertically scrolling element inside it) to the top, smoothly or as a jump under Reduce Motion, and still calls onReselect, and the earlier /approve-spec on this pull request names the head before the commit that switched the lookup to Core's scroll test, so it no longer counts.
  • Regression: the description now declares Stack: #9966 while #9754, #9699 and #9700 declare Stack: #9754 → #9699 → #9700, so this pull request is reviewed on its own, and its 6,094 authored lines, 5,597 of them from those three pull requests, get no stack exemption; restore Stack: #9754 → #9699 → #9700 → #9966 in all four descriptions, or update this branch from main after the three land.

The earlier panelScroll.ts finding is fixed: the lookup now uses Core's scroll test, and a chip row 1 px taller than its box is skipped. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner. CI has not run on this head yet because the pull request is a draft.

[Automated review]

@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.

This pull request needs one change before it can be approved. The reselect-to-top behavior itself is approved and has no code defect.

  • Regression: the description declares Stack: #9966, while #9699 and #9700 declare Stack: #9754 → #9699 → #9700, so this branch is reviewed on its own and its 6,094 authored lines, 5,571 of them from #9754 (already merged), #9699 and #9700, get no stack exemption; update the branch from main (resolving the conflicts in packages/core/src/internal/touch.ts, packages/core/src/internal/touch.test.ts and scripts/touch-support-bundle.test.mjs), restack it on #9700's current head and add one identical Stack: #9699 → #9700 → #9966 line to all three descriptions, or update it from main after #9699 and #9700 land.

The engineering owner's /approve-spec for this head covers Lab TabBar, TabBarItem and the reselect rule; a new commit needs a fresh /approve-spec for its own head. One non-blocking cleanup remains: in TabBar.tsx, size only renames itemWidthCss.

[Automated review]

@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

/approve-spec b661856

@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.

This pull request waits on one owner decision; no code changes are needed. The engineering owner's /approve-spec for this commit covers the reselect-to-top rule, and no defect blocks it.

  • A mouse click on the selected tab now glides its panel to the top (TabBar.tsx:646 → panelScroll.ts:63), a desktop behavior change to a component already on main, so it needs an explicit owner decision for mouse input recorded in the description (the decision itself with its source and time; the "Decider: Specs ruling …" line does not record one), or the scroll limited to touch input, which as a new commit needs a fresh /approve-spec.

Two non-blocking notes: panelScroll.ts:60-62 decides glide or jump from the Reduce Motion media query alone, while the bar's lens follows Core's animator, so reducedMotionFade(area) != null from the same internal entry would keep one path. Miss: the unit case at TabBar.test.tsx:317 says it covers a tab with no panelId, but both of its renders set one.

[Automated review]

As on iOS, choosing the selected tab again brings its section back to
the top. TabBar finds the tab's panel through panelId and scrolls that
panel's own scroll area: the panel itself when it scrolls, or else the
first scroll area inside it. Core's shared scroll test decides, so a row
that overflows by a pixel or less, or only sideways, is never taken.
Nothing else scrolls: not the page, not the other panels, not any other
scroll area. The panel glides to the top, and under Reduce Motion it
jumps. onReselect is still called, so an app can also return the tab's
navigation stack to its root.
@vjeux
vjeux force-pushed the tabbar/lab-reselect-scroll-top branch from b661856 to c72f46e Compare November 10, 2026 05:49
@vjeux vjeux changed the title feat(lab): choosing the selected TabBar tab again scrolls its panel to the top feat(lab): reselecting a TabBar tab scrolls its panel to the top Nov 10, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec c72f46e

@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.

Approved pending CI: CI has not run on this head yet. It runs once the draft is marked ready for review.

Choosing the selected tab again now brings that tab's own panel to its top, and only that panel. The four new scroll cases fail against main's TabBar and pass here. Two non-blocking notes:

  • panelScroll.ts:60-62 reads Reduce Motion from the media query alone, while the bar's lens follows Core's animator; reducedMotionFade(area) != null from @astryxdesign/core/internal/touch would keep one path and keep the jump.
  • The unit case at TabBar.test.tsx:317 says it covers a tab with no panelId, but both of its renders set one; drop that clause or add the case.

[Automated review]

Comment on lines +60 to +62
const isReduced =
document.defaultView?.matchMedia?.('(prefers-reduced-motion: reduce)')
.matches ?? false;

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.

Non-blocking: this reads only the media query, while the bar's lens asks Core's animator (useTabBarLens.ts:344). reducedMotionFade(area) != null from @astryxdesign/core/internal/touch keeps one Reduce Motion path (it also counts a theme's reduce-motion mark) and keeps the jump.

expect(scrollTo).toHaveBeenCalledWith({top: 0, behavior: 'instant'});
});

it('scrolls nothing when the panel is at its top, has no scroll area, or the tab names none', () => {

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.

Non-blocking: both renders in this case pass hasPanels, so no case covers a tab that names no panel. Drop "or the tab names none" from the title, or add that case.

@vjeux
vjeux marked this pull request as ready for review November 10, 2026 06:37
@cixzhang
cixzhang merged commit b04c414 into meta:main Nov 10, 2026
116 checks passed
@vjeux
vjeux deleted the tabbar/lab-reselect-scroll-top branch November 10, 2026 06:57

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants