Skip to content
All posts

Engineering

React Bottom Sheet with Snap Points for shadcn/ui

Build a React bottom sheet with snap points for shadcn/ui on Base UI Dialog, with velocity flick, rubber-band physics, Vaul migration, and full a11y.

SS
Sourabh Soni

A React bottom sheet with snap points has to reconcile two systems that normally fight each other: a dialog primitive that owns focus trapping, Esc, and scroll locking, and a continuous pointer gesture that slides between heights, hands off to inner scrolling, and dismisses on a flick. Most custom drawers get one side right and break the other.

With Vaul no longer maintained, shadcn/ui projects that relied on its drawer snap points need a source-owned replacement built on modern primitives. TentUI's Snap Sheet is a free and source-available React bottom sheet for shadcn/ui built on Base UI Dialog and Motion. It covers Vaul's core drawer API, projects release velocity into the nearest snap point, rubber-bands past full height, and switches to a dialog or side sheet on desktop.

Loading…

Drag the sheet inside the phone frame between peek (148px), half (0.5), and full (1), pull past the top edge to feel the rubber band, or scroll the ride options once the sheet reaches full height.

Quick start

Add the @tentui registry to components.json if you have not already (see the installation guide), then install Snap Sheet with the shadcn CLI:

pnpm dlx shadcn@latest add @tentui/snap-sheet

You can also install directly from its registry URL without configuring the namespace:

pnpm dlx shadcn@latest add https://tentui.com/r/snap-sheet.json

The CLI copies snap-sheet.tsx into your project and installs @base-ui/react, motion, lucide-react, web-haptics, and @rexa-developer/tiks.

Then compose the sheet with your snap points listed lowest first:

"use client";
 
import { SnapSheet } from "@/components/snap-sheet";
 
export function RidePickerSheet() {
  return (
    <SnapSheet snapPoints={["148px", 0.5, 1]}>
      <SnapSheet.Trigger>Find a ride</SnapSheet.Trigger>
      <SnapSheet.Content>
        <SnapSheet.Handle />
        <SnapSheet.Title>3 rides nearby</SnapSheet.Title>
        <SnapSheet.Description>Pickup at Market St in 2 min</SnapSheet.Description>
        <div className="min-h-0 flex-1 overflow-y-auto overscroll-contain">
          {/* Scrollable sheet body */}
        </div>
      </SnapSheet.Content>
    </SnapSheet>
  );
}

Numbers are fractions of the available viewport (or container) height, and pixel strings such as "148px" are fixed heights. At 1, the sheet leaves a 24 px gap at the top so the surface reads clearly as an overlay rather than a full-screen navigation change.

How snap points map to y coordinates

Measuring a bottom sheet once on mount breaks as soon as the user rotates a phone, collapses the iOS Safari address bar, or opens the virtual keyboard. Snap Sheet avoids hardcoded viewport math by measuring the rendered sheet height with a ResizeObserver and computing every snap point relative to it:

type SnapPoint = number | `${number}px`;
 
function toPx(point: SnapPoint, frame: number) {
  return typeof point === "number" ? point * frame : Number.parseFloat(point);
}

For each snap point, the component converts the target visible height into a translateY offset where 0 is full height and closed sits 24 px past the bottom edge so the sheet's upward drop shadow disappears completely off-screen. Before the first measurement completes, y starts at 10_000 so the sheet never flashes at full height on mount.

On mobile browsers, a second listener subscribes to window.visualViewport resize and scroll events and writes the virtual keyboard height to --snap-sheet-keyboard. While pinch-zoomed (viewport.scale > 1.01), it ignores the offset so zoomed pages do not jump.

Velocity projection, flick-to-close, and rubber-band physics

A bottom sheet that snaps purely by nearest distance feels sticky: a brisk flick from half height should cross into full height or close the sheet even if the finger only traveled 40 px. Snap Sheet projects the release position 200 ms ahead using Motion's pointer velocity:

const PROJECTION_SECONDS = 0.2;
const DISMISS_VELOCITY = 1000; // px/s
const MAX_VELOCITY = 4000; // px/s
const RUBBER_BAND = 0.3;
 
const velocity = clamp(y.getVelocity(), -MAX_VELOCITY, MAX_VELOCITY);
const projected = current + velocity * PROJECTION_SECONDS;

Three small safeguards make that projection reliable across trackpads and touch screens:

  • Clamped peak velocity. Capping release speed at 4000 px/s prevents a single noisy pointer sample from flinging the sheet past every intermediate stop.
  • Flick-to-close guard. When dismissible is true, a downward flick faster than 1000 px/s closes the sheet immediately if the gesture started at the lowest snap point or has already crossed below it. That lets a fast pull down from full height land at half or peek first instead of accidentally dismissing the entire workflow.
  • Rubber-band boundaries. Dragging past full height multiplies extra travel by 0.3 instead of hitting a brick wall. When dismissible={false}, the same 0.3 resistance applies below the lowest snap point so the user feels the boundary without dismissing the sheet.

Overlay dimming, the optional iOS-style background scale (scaleBackground on [data-sheet-wrapper]), detent haptics, and landing sounds all run off the y MotionValue subscription—zero React re-renders per frame while dragging.

Reconciling drag gestures with inner scrolling

The hardest mobile bug in bottom sheets is scroll-versus-drag fighting. If you capture the pointer on pointerdown, buttons inside the sheet lose clicks and nested carousels stop swiping. If you let the browser handle touch freely, iOS Safari starts scrolling the body before the sheet moves.

Snap Sheet resolves the gesture after a 4 px dead zone (DRAG_SLOP):

  1. Horizontal axis lock. If horizontal travel exceeds vertical travel (Math.abs(dx) > Math.abs(dy)), the sheet yields immediately so horizontal carousels or Swipe Actions inside the sheet work untouched.
  2. Scroll handoff at full height. findScroller walks up from the pointer target to the nearest overflow-y: auto | scroll container with real overflow. While the sheet is below full height, vertical drags move the sheet. Once the sheet is at full height, dragging up scrolls the content, and dragging down only reclaims the sheet once scroller.scrollTop === 0.
  3. Interactive exclusions. Drags that start on input, textarea, select, [contenteditable], or any element marked data-sheet-no-drag never hijack the sheet, unless the drag begins on SnapSheet.Handle.
  4. Non-passive touchmove. A targeted { passive: false } touchmove listener cancels browser scroll only after the gesture is decided as "sheet", preventing Safari rubber-banding while preserving normal scroll everywhere else.

Base UI Dialog underneath: focus trap, scroll lock, and non-modal mode

Instead of hand-rolling portal stacking, inert background trees, and focus restoration, Snap Sheet wraps @base-ui/react/dialog (DialogPrimitive.Root, Portal, Backdrop, Popup, Title, Description, and Close).

Because the dialog primitive stays mounted while the close spring plays—driven by a separate rendered state that flips to false only after the exit animation settles—focus returns cleanly to the trigger without cutting off the motion.

That foundation gives you two distinct modes from one prop:

  • Modal sheets (modal={true}, default). Focus is trapped inside the sheet, page scroll is locked, Esc and outside clicks close the sheet when dismissible is true, and the backdrop dims continuously from closed to full height.
  • Non-modal sheets (modal={false}). Ideal for map, music player, or filter overlays. Focus is not trapped, the page stays interactive behind a pointer-events-none backdrop, clicking outside does not dismiss the sheet, and the overlay only fades in between the last two snap points.

On larger screens (md breakpoint and up, 768px), pass desktop="dialog" to render a centered modal or desktop="sheet" for a right-hand side sheet. If you want a card or button that physically morphs into a centered dialog instead of rising from the bottom edge, pair this with Morph Dialog.

Migrating from Vaul to Snap Sheet

Most Vaul props translate directly to Snap Sheet. The biggest behavioral difference is that controlled snap state uses a zero-based index (activeSnap) instead of repeating the raw snap point value ("148px" or 0.5), which avoids floating-point or string-comparison mismatches when snap arrays change.

Vaul APISnap Sheet APINotes
Drawer.RootSnapSheetOwns open state, snap points, and physics
Drawer.TriggerSnapSheet.TriggerBase UI Dialog trigger
Drawer.Portal + Drawer.OverlayBuilt into SnapSheet.ContentStyle backdrop via overlayClassName
Drawer.ContentSnapSheet.ContentSupports variant="attached" | "floating" and container
Drawer.HandleSnapSheet.HandleFocusable role="slider" with keyboard support
Drawer.Title / Drawer.DescriptionSnapSheet.Title / .DescriptionWired to dialog ARIA attributes
Drawer.CloseSnapSheet.CloseRenders an accessible close button by default
open / onOpenChangeopen / onOpenChangeIdentical controlled visibility contract
snapPoints={["148px", 0.5, 1]}snapPoints={["148px", 0.5, 1]}Numbers are viewport fractions; strings are px
activeSnapPoint / setActiveSnapPointactiveSnap / onSnapChangeUses zero-based index into snapPoints
shouldScaleBackgroundscaleBackgroundTargets [data-sheet-wrapper]
[data-vaul-drawer-wrapper][data-sheet-wrapper]Scales to 0.94 with 12px radius at full height
[data-vaul-no-drag][data-sheet-no-drag]Opts nested interactive elements out of sheet drag
modal, dismissible, handleOnlymodal, dismissible, handleOnlySame names and behavior
direction="right"desktop="sheet"Renders a side sheet at md (>=768px)

Controlled updates follow a strict precedence rule: an active pointer drag always wins over an incoming activeSnap prop change, and programmatic open or activeSnap updates animate silently unless you opt in with soundOnProgrammatic.

Keyboard navigation and reduced motion

Pointer gestures cannot be the only way to resize a bottom sheet. SnapSheet.Handle renders a native <button type="button"> with role="slider", aria-orientation="vertical", aria-label="Resize sheet", and human-readable aria-valuetext labels ("Peek height", "Half height", "Full height", or percentage labels):

InputAction
ArrowUp / ArrowRightMove up one snap point
ArrowDown / ArrowLeftMove down one snap point
Home / EndJump to the lowest or highest snap point
Enter / Space / Tap on handleCycle to the next snap point
EscapeClose the sheet (when dismissible is true)

Every snap change also updates a polite aria-live="polite" region inside SnapSheet.Content (for example, "Sheet at half height"). Always render a SnapSheet.Title and include SnapSheet.Close in modal sheets so touch screen-reader users always have an explicit exit control.

When prefers-reduced-motion: reduce is active, SnapSheet replaces its open and settle springs with a 120 ms easeOut tween and turns off background scaling. Direct dragging still works, and sound and haptics stay enabled as non-visual confirmation unless you pass sound={false} or haptics={false}.

If you are evaluating other missing or specialized shadcn/ui primitives beyond bottom sheets, see the guide to finding and installing missing shadcn components safely.

FAQ

How do I add a bottom sheet with snap points to shadcn/ui?

Add the @tentui registry to components.json and run npx shadcn@latest add @tentui/snap-sheet, or install it directly from https://tentui.com/r/snap-sheet.json. Pass an ascending snapPoints array such as ["148px", 0.5, 1] to <SnapSheet> and wrap scrollable body content in a min-h-0 flex-1 overflow-y-auto container.

Is Snap Sheet a drop-in replacement for Vaul?

Snap Sheet covers Vaul's core drawer API—including snapPoints, modal, dismissible, handleOnly, and background scaling—on top of Base UI Dialog and Motion. Most props map one to one; the main migration change is switching activeSnapPoint (a value) to activeSnap (a zero-based index) and [data-vaul-drawer-wrapper] to [data-sheet-wrapper].

How do snap points work with scrollable content inside the sheet?

Drag gestures inside a scrollable container move the sheet until it reaches its highest snap point. Once at full height, dragging upward scrolls the inner container, and dragging downward only pulls the sheet back down after scrollTop reaches zero. Horizontal swipes lock out vertical dragging so carousels inside the sheet keep working.

How can keyboard and screen-reader users resize the bottom sheet?

SnapSheet.Handle is a focusable vertical slider (role="slider") labeled "Resize sheet" with descriptive aria-valuetext values. Users can move between snap points with ArrowUp, ArrowDown, Home, and End, cycle snaps with Enter or a tap, and close modal sheets with Escape or SnapSheet.Close.

Can the bottom sheet become a dialog or side sheet on desktop?

Yes. Pass desktop="dialog" to render a centered modal or desktop="sheet" to render a side sheet from the md breakpoint (768px) upward, while keeping the draggable bottom sheet on mobile viewports.

What happens when reduced motion is enabled?

When prefers-reduced-motion: reduce is set, Snap Sheet replaces its spring animations with a 120 ms easeOut tween and disables background page scaling. Dragging, keyboard resizing, and Base UI focus management continue working normally, and sound or haptics can be toggled independently with sound={false} and haptics={false}.

Components in this guide

All components
All posts
Follow new React and shadcn/ui component releases.