Skip to content

feat(core): let the Bottom Sheet's host choose its snap points - #5203

Merged
imdreamrunner merged 1 commit into
mainfrom
bottom-sheet-snap-points
Aug 19, 2026
Merged

imdreamrunner merged 1 commit into
mainfrom
bottom-sheet-snap-points

Conversation

@imdreamrunner

@imdreamrunner imdreamrunner commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

What

snapPoints makes the Bottom Sheet's drag-to-resize stops the host's choice.

<BottomSheet height="tall" snapPoints={[0.5]}>          // collapse to half the screen
<BottomSheet height="tall" snapPoints={['96px', '50%']}> // a peek, a working height, and full

A stop is the sheet's visible height, in the same spellings height already
takes: a bare number is a viewport fraction (0.5 = half the screen), '50%'
is that spelled in CSS, '320px' is absolute. Fractions and percentages
re-resolve against window.innerHeight when the viewport changes, so a sheet
keeps the stop the user chose across a rotation; swapping the points under a
resting sheet re-anchors it the same way. Anything else — '50', '30rem',
calc(), a number above 1 — is ignored with a dev warning naming the value.
The whitelist is deliberate: the resolver runs inside the drag loop, so every
accepted unit has to be arithmetic on the viewport height rather than a layout.

Behavior change (deliberate, not breaking)

Every sheet used to carry three built-in stops — 14%, 50% and 92% of the
viewport — so a drag could leave it resting somewhere the host never asked for.
A sheet now opens and closes unless snapPoints says otherwise.

Existing apps keep working: nothing was removed or renamed, and swipe-to-dismiss,
the height budgets, and mobile-keyboard accommodation are untouched. To keep the
old stops, pass snapPoints={[0.14, 0.5, 0.92]}. Filed [feat]/patch rather
than [breaking] on that basis — flagging it here because a changed default is
exactly the thing worth a second opinion.

The peek rule had to change with it

The shortest stop used to be a "peek" unconditionally: it kept the sheet's full
layout height, slid below the viewport instead of reflowing, and thinned the
scrim to 0.3. Right for a sliver, wrong for a working height — and [0.5], the
most likely first thing anyone writes, would have rested at half the screen
under a thinned backdrop.

A peek is now a stop that is at most a quarter of the sheet. Taller stops lay
their content out and keep the scrim full. scrimOpacityForOffset follows: full
down to the shortest working stop, thinning only onto a peek or out through the
dismiss overshoot.

Where the examples land

  • Doc site — a new BottomSheetSnapPoints block under
    packages/cli/assets/templates/blocks/components/BottomSheet/, which is what
    the docsite's example registry renders. It is the peek case
    (['96px', '50%']), alongside the existing Heights / Mobile keyboard / No
    scrim blocks. Visible rather than hidden: true, matching all 630 existing
    component blocks — the lifecycle rule's conflict with that is filed as Do new example blocks need hidden: true? Rule says yes, all 630 existing blocks say no #5206.
  • Storybook — SnapPoints ([0.5]) and SnapPointsWithPeek
    (['96px', '50%']).
  • Astryx CLI (astryx component BottomSheet) — two .doc.mjs examples,
    the snapPoints prop row, and the corrected height copy. This is the
    agent-facing surface; it does not feed the docsite.

Evidence

Unit tests cover the parser, the peek rule and the scrim curve. Beyond those, I
drove the built component in Chromium at 390×844 with real touch drags and read
back what the sheet actually did:

snapPoints drag rests at layout scrim
(none) 220px springs back to full — 1
[0.5] 340px 419px visible resized to 470px 1
['96px','50%'] 340px 419px visible resized to 470px 1
['96px','50%'] 700px 93px visible full height, translateY(680px) 0.3
['320px'] 420px 317px visible resized to 368px 1

Rows 3 and 4 are the peek rule: the same sheet keeps a full scrim and reflows at
its half stop, then thins the scrim and slides at its 96px stop.

The re-anchor-on-change test is red without the effect that implements it
(expected '448px' to be '248px').

pnpm lint:strict, pnpm test (10703 passing), pnpm build all clean.

Notes for review

  • New public API surface — snapPoints and the BottomSheetSnapPoint type.
    Worth a human call on the shape, particularly number = viewport fraction
    while height's number is px. That asymmetry is deliberate: percentages are
    what snap points overwhelmingly are, and '50%' does not resolve on height
    (the positioner has no definite block size), so the two props could not have
    been made identical anyway.
  • A new useLayoutEffect in useSheetGestures re-anchors a resting sheet
    when the points change, carrying two set-state-in-effect suppressions. The
    correction depends on a post-layout measurement, so it cannot move to render
    or to an event handler; both writes sit behind an equality guard, so a
    re-anchor that finds nothing to change sets nothing. It also moved
    snapHeightsRef out of the batched ref-refresh effect and into the render
    body: layout effects run before passive ones, so the re-anchor would
    otherwise have read the previous resolver and concluded nothing had changed
    (expected 200 to be 250 without the move).
  • A pre-existing a11y bug surfaced here, filed as Bottom Sheet: keyboard users cannot scroll the sheet body (axe serious) #5207. CI's a11y audit had
    never checked this component — no Bottom Sheet story rendered open, so the
    scroll body was never audited. My peek story did, and axe flagged
    scrollable-region-focusable (serious): a keyboard user cannot scroll the
    sheet body when its content has no focusable children. Older than this PR,
    and the fix (a conditional tabIndex) adds a tab stop to every sheet, so it
    wants its own review. I made the story closed by default, matching all nine
    siblings.
  • Nine BottomSheet.test.tsx cases now pass snapPoints explicitly. They were
    asserting detent geometry against the old built-in stops; the assertions are
    unchanged.

@vercel

vercel Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 19, 2026 6:57am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 19, 2026
@imdreamrunner
imdreamrunner force-pushed the bottom-sheet-snap-points branch from de90ac3 to 9450b13 Compare August 19, 2026 02:06
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

BottomSheet (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 3118 -
Complexity N/A Very High (249) -

Bundle Size Summary

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

Accessibility Audit

Status: No accessibility violations detected.


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

@imdreamrunner
imdreamrunner force-pushed the bottom-sheet-snap-points branch from 9450b13 to 7c743a2 Compare August 19, 2026 02:16
github-actions Bot added a commit that referenced this pull request Aug 19, 2026
github-actions Bot added a commit that referenced this pull request Aug 19, 2026
@imdreamrunner
imdreamrunner force-pushed the bottom-sheet-snap-points branch from 7c743a2 to 533f5cc Compare August 19, 2026 05:42
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Aug 19, 2026
github-actions Bot added a commit that referenced this pull request Aug 19, 2026
@imdreamrunner
imdreamrunner marked this pull request as ready for review August 19, 2026 06:05
@imdreamrunner
imdreamrunner force-pushed the bottom-sheet-snap-points branch from 533f5cc to 0cb1ebb Compare August 19, 2026 06:19
github-actions Bot added a commit that referenced this pull request Aug 19, 2026
@imdreamrunner
imdreamrunner force-pushed the bottom-sheet-snap-points branch from 0cb1ebb to c9769e5 Compare August 19, 2026 06:39
`snapPoints` makes the drag-to-resize stops the host's choice, and a sheet
now has none unless it asks. A stop is the sheet's visible height, written
as a viewport fraction (0.5), a percentage ('50%'), or a px length
('320px') — matching `height`, where a bare number is also px and a string
carries its unit.

The shortest stop used to be treated as a peek unconditionally: it kept the
sheet's full layout height, slid below the viewport, and thinned the scrim.
That is right for a sliver and wrong for a working height, so a sheet with
one 50% stop would have rested at half the screen under a thinned backdrop.
A peek is now a stop that is at most a quarter of the sheet; taller stops
lay their content out and keep the scrim full.
@imdreamrunner
imdreamrunner force-pushed the bottom-sheet-snap-points branch from c9769e5 to 90084bc Compare August 19, 2026 06:55
github-actions Bot added a commit that referenced this pull request Aug 19, 2026
github-actions Bot added a commit that referenced this pull request Aug 19, 2026
@imdreamrunner
imdreamrunner merged commit 0e8af82 into main Aug 19, 2026
19 checks passed
ernestt pushed a commit that referenced this pull request Aug 19, 2026
`snapPoints` makes the drag-to-resize stops the host's choice, and a sheet
now has none unless it asks. A stop is the sheet's visible height, written
as a viewport fraction (0.5), a percentage ('50%'), or a px length
('320px') — matching `height`, where a bare number is also px and a string
carries its unit.

The shortest stop used to be treated as a peek unconditionally: it kept the
sheet's full layout height, slid below the viewport, and thinned the scrim.
That is right for a sliver and wrong for a working height, so a sheet with
one 50% stop would have rested at half the screen under a thinned backdrop.
A peek is now a stop that is at most a quarter of the sheet; taller stops
lay their content out and keep the scrim full.
@github-actions
github-actions Bot deleted the bottom-sheet-snap-points branch August 20, 2026 06:12

This branch was successfully deployed

1 active deployment
Preview — 90084bc9 Deployed Aug 19, 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant