Skip to content

feat(lab): BottomSheet peek detent, snap points, and swipe-to-dismiss - #4519

Merged
cixzhang merged 10 commits into
mainfrom
feat/bottomsheet-snap-points
Jul 31, 2026
Merged

cixzhang merged 10 commits into
mainfrom
feat/bottomsheet-snap-points

Conversation

@cixzhang

@cixzhang cixzhang commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

The lab BottomSheet needed to match the mobile design spec: a glance-able peek state, viewport-relative snap detents, and a handle/scrim/radius that read as a native sheet. This tracks that spec and tightens the gesture feel.

What

  • Snap detents [0.14, 0.5, 0.92] of the viewport — a glance peek, ~half, and ~full. The measured sheet height is always the tallest detent; shorter detents are filtered to those below it, so a short sheet has one rest point while a taller one gains the peek and mid detents beneath it. Detents are viewport-relative, independent of the height starting budget.
  • Two distinct handle gestures — a slow drag settles to the nearest detent (drag places), a fast flick down dismisses and a fast flick up expands (swipe closes). Magnetic settle, direction-clamped snapping, damped overscroll, and a haptic tick on settle where supported.
  • Peek reveals the content behind — the scrim fades to hidden as the sheet collapses onto its shortest peek detent (and on the dismiss overshoot), full at the mid/full detents. The sheet stays modal — the background is inert until dismissed; the fade is a glance affordance, not interact-behind.
  • Body scroll ↔ drag handoff at both edges — a pull-down at the top collapses the sheet, a pull-up at the bottom expands it, with native scrolling untouched in between.
  • Heights hug | capped | tall (default capped) — hug fits its content up to a 92dvh ceiling, capped is a scrolling mid-height panel, tall is pinned near-full at 92dvh. Also accepts a raw px/CSS length.
  • Surface polish — 48px grab-handle target, container radius on the top corners, safe-area padding for the home indicator, animated close, and a dialog focus contract (panel focused on open unless a descendant opts in with data-autofocus).

Risk

Public API unchanged (isOpen / onOpenChange / label / children / height); the gesture logic stays in the internal useSheetGestures hook, not exported. Lab is pre-1.0 and private, so no changeset.

Testing

  • vitest run packages/lab/src/BottomSheet/ — 52 pass
  • typecheck:docs, build, and eslint — clean

Reference #575.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 29, 2026
@vercel

vercel Bot commented Jul 29, 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 Jul 31, 2026 3:06pm

Request Review

@github-actions

github-actions Bot commented Jul 29, 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/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 874 -
Complexity N/A High (30) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/lab N/A 3.4KB 1.4KB

Accessibility Audit

Status: No accessibility violations detected.


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

A mobile touch sheet built on the lab Drawer <dialog side="bottom"> engine:
Drawer owns the open/close slide, focus trap, scroll lock, and Escape/scrim
contract; BottomSheet adds the grab handle and drag machinery on top.

- Height budgets hug (fits content, max 90%), capped (62%), tall (92%), or a
  freeform number/CSS length, mirroring Drawer size / Dialog maxHeight.
- Drag-to-resize snap points (viewport fractions 0.5, 0.92): a slow drag
  settles to the nearest detent, a flick down dismisses, a flick up expands.
  Magnetic ease onto detents, rubber-band resistance past the top, and a
  haptic tick on settle where supported.
- Pulling down on content scrolled to the top drags the sheet (larger target);
  the scrim fades as a drag nears dismissal to hint that releasing will close.
- Gesture logic lives in an internal useSheetGestures hook (not exported).

Resolves #575.
@cixzhang
cixzhang force-pushed the feat/bottomsheet-snap-points branch from 9ecd79c to 64063c8 Compare July 30, 2026 19:49
github-actions Bot added a commit that referenced this pull request Jul 30, 2026
…eight

Extract snap-point geometry into a pure, unit-tested snapOffsets module
(fraction->height, height->translateY offsets, de-dup of near-equal detents,
direction-clamped settle). Lock the fully-open height on open and track it
with a ResizeObserver so detents stay correct across rotation/viewport change
without re-measuring mid-drag.

Fixes the feel bugs: clamp upward overscroll to a reserved bottom-padding
allowance (no more top clipping on a tall sheet); widen the default detents to
a reachable peek/mid/full set; de-dup detents that land within ~48px so a
content-hugging height and a nearby snap collapse to one stop; skip the magnet
in the dismiss zone so a drag-to-close isn't yanked back up.
…ependency

BottomSheet no longer renders a Drawer; it owns a native modal <dialog>
directly and composes core primitives (useScrollLock, showModal() for the top
layer + focus trap, a ::backdrop scrim). The dialog is a full-viewport
transparent shell with the visible sheet bottom-anchored inside and
overflow:visible, so the sheet can translate freely — including a little past
fully-open — without clipping against a fixed dialog edge. It only used a
handful of Drawer props and overrode the rest, so owning a thin dialog is less
code and makes the scrim drag-fade and the transparent shell first-class
rather than style overrides.
…ocus contract

- Enlarge the grab target to a full, honest 48px strip (no negative-margin
  overlap that undercut it and made it inconsistent to hit after an overscroll).
- Fix the overdrag zone: the reserved bottom padding is now negated by an equal
  negative margin so it sits below the fold at rest (the true sheet stays
  pinned to the bottom edge), with the height budget growing to match so the
  visible height is unchanged.
- Animate the sheet out on programmatic close: wait for the slide-down
  transition (with a timeout backstop) before releasing the modal top layer.
- Match Dialog's focus contract: initial focus lands on the sheet panel (so AT
  reads from the label) unless a descendant sets data-autofocus; enforce a
  non-empty accessible label with a dev warning.
When the sheet content is scrolled to an edge, a pull that can no longer scroll
hands off to the sheet drag: at the top, a pull-down collapses; at the bottom, a
pull-up expands. Implemented with a non-passive touchmove listener (pointer
events are cancelled once the browser starts a native pan, so they can't drive
this on touch devices), reusing the same drag/snap math. The body no longer
does its own overscroll bounce, so the edge pull is a clean handoff.
Self-review cleanup: inline single-use layout constants (max width, handle
height token, close-animation backstop) into the styles rather than named
consts; keep only the reused OVERSCROLL_PADDING. The gesture hook now measures
the sheet via the element it already tracks (ResizeObserver ref) instead of
querying data-astryx-sheet with closest(), so the drag/measure path does no DOM
lookups. Drop the unused data-astryx-sheet-body attribute.
The theme class now sits on the painted sheet surface rather than the
transparent dialog shell, so `astryx-bottom-sheet` targets what actually
renders. Trim narration comments down to docblocks and the non-obvious why
(transparent-shell rationale, overdrag negation, non-passive touch handoff,
focus-contract override), letting the code speak for itself elsewhere.
Adopt the reference snap set [0.14, 0.5, 0.92]: the shortest is a glance
"peek" detent. Fade the scrim to hidden as the sheet collapses onto the
peek so the content behind is visible at a glance (the sheet stays modal —
background inert until dismissed), full at the mid/full detents. The fade
curve is a pure, tested helper; the hook now reports scrim opacity directly
(owner mirrors it), replacing the dismiss-progress signal.

Drop the two test-only data attributes; tests target the stable
astryx-bottom-sheet class and DOM structure instead.
@cixzhang
cixzhang marked this pull request as draft July 31, 2026 10:26
github-actions Bot added a commit that referenced this pull request Jul 31, 2026
@cixzhang
cixzhang marked this pull request as ready for review July 31, 2026 14:56
medium: '50dvh',
tall: '90dvh',
auto: '90dvh',
hug: '90dvh', // upper bound only; the sheet hugs its content beneath it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm why different from tall as a max height then?

// height that lands next to one of these) are de-duped downstream, so it's
// safe to offer a full set; the gesture hook keeps only those shorter than
// the rendered sheet.
const SNAP_FRACTIONS = [0.3, 0.6, 0.92];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

0.3 for smallest snap -- does that match @rubyycheung's sketch?

// Backstop for the slide-out transition when releasing the modal on close, a
// touch above `--duration-medium` (410ms) so `transitionend` normally fires
// first and this only covers environments that don't emit it.
const CLOSE_ANIMATION_MS = 450;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this need to live in JS? Can we use the tokens?

paddingBlock: spacingVars['--spacing-2'],
// The full strip is the drag target — tall and centered so it's easy to
// grab and reads clearly as the resize affordance.
height: HANDLE_HIT_HEIGHT,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Use tokens

// Sheets on wide touch devices (tablets) shouldn't stretch edge to edge; cap
// and center them. On phones the viewport is narrower than this, so the sheet
// stays full-width.
const MAX_SHEET_WIDTH = 640;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's likely many of these constants can just be in the style and don't need this indirection. If we need to reuse consider setting internal vars for it

xstyle={[styles.dialogSurface, height === 'auto' && styles.autoHeight]}
<dialog
{...mergeProps(
themeProps('bottom-sheet'),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Double check and make sure this is still the rational theme target.

aria-hidden="true">
<div {...stylex.props(styles.handlePill)} />
ref={mergeRefs(sheetRef, sheetNodeRef)}
data-astryx-sheet=""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why a data attribute?

},
)}>
<div
data-astryx-sheet-handle=""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why all these attributes?

@cixzhang cixzhang changed the title feat(lab): BottomSheet snap points + larger drag handle target feat(lab): BottomSheet peek detent, snap points, and swipe-to-dismiss Jul 31, 2026
github-actions Bot added a commit that referenced this pull request Jul 31, 2026
@cixzhang
cixzhang merged commit 7467659 into main Jul 31, 2026
18 checks passed
@github-actions
github-actions Bot deleted the feat/bottomsheet-snap-points branch August 1, 2026 06:54

This branch was successfully deployed

1 active deployment
Preview — adccb84e Deployed Jul 31, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant