Repository navigation
feat(lab): BottomSheet peek detent, snap points, and swipe-to-dismiss - #4519
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsBottomSheet (@astryxdesign/lab) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 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.
9ecd79c to
64063c8
Compare
…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.
| medium: '50dvh', | ||
| tall: '90dvh', | ||
| auto: '90dvh', | ||
| hug: '90dvh', // upper bound only; the sheet hugs its content beneath it |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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, |
| // 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; |
There was a problem hiding this comment.
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'), |
There was a problem hiding this comment.
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="" |
There was a problem hiding this comment.
Why a data attribute?
| }, | ||
| )}> | ||
| <div | ||
| data-astryx-sheet-handle="" |
There was a problem hiding this comment.
Why all these attributes?
Why
The lab
BottomSheetneeded 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
[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 theheightstarting budget.hug | capped | tall(defaultcapped) —hugfits its content up to a 92dvh ceiling,cappedis a scrolling mid-height panel,tallis pinned near-full at 92dvh. Also accepts a raw px/CSS length.data-autofocus).Risk
Public API unchanged (
isOpen/onOpenChange/label/children/height); the gesture logic stays in the internaluseSheetGestureshook, not exported. Lab is pre-1.0 and private, so no changeset.Testing
vitest run packages/lab/src/BottomSheet/— 52 passtypecheck:docs, build, and eslint — cleanReference #575.