Ir al contenido
Español
Panel inferior viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

Position is the distance of the panel top below the highest snap point, written to transform every frame while dragging, so React never re-renders. At rest the panel height equals the snap height; during a gesture it is stretched to full height and compensated with translateY, then shrunk once settled. The footer stays pinned to the visible bottom. On release the last 100ms of velocity decides a one-step flick, and the snap curve is built from that velocity so motion continues smoothly. Only the handle area drags; content keeps native scrolling. The backdrop dims and lightly blurs the page behind (override with --ds-sheet-backdrop); the panel is a borderless card with 28px top corners and a soft upward shadow, and the footer has no divider.

Úsalo para

  • Mobile choices that keep people on the current page: payment method, options, coupons.
  • Action menus such as share and more.
  • Detail panels over a map or list: half open to peek, pull up for everything.

Busca otra opción cuando

  • Desktop: use a centered dialog or a side drawer; a bottom sheet is too far from the eyes on large screens.
  • Dangerous confirmations that must be handled, such as deleting an account: use a centered dialog that is harder to dismiss by mistake.
  • Long content that needs its own browsing: open a new page.

Uso

import { useState } from 'react'
import { BottomSheet } from './BottomSheet.jsx'

export function BuyButton() {
  const [open, setOpen] = useState(false)
  return (
    <>
      <button onClick={() => setOpen(true)}>Buy now</button>
      <BottomSheet
        open={open}
        onClose={() => setOpen(false)}
        title="Choose payment method"
        snapPoints={[0.8, 0.96]}
        footer={<button onClick={() => setOpen(false)}>Pay $25.60</button>}
      >
        <PaymentMethodList />
      </BottomSheet>
    </>
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
openboolean—Whether the sheet is open.
onClose() => void—Requests closing (pull down, backdrop click, Esc). You set open to false; if you do not, the sheet springs back.
titleReactNode—Title, also the dialog's accessible name (aria-labelledby).
footerReactNode—Action area pinned to the bottom, visible at every snap height.
snapPointsnumber[][0.5, 0.9]Snap points as fractions of the container height. A single value means a fixed height.
defaultSnapnumber0Index (low to high) of the snap point to open at.
onSnapChange(index: number) => void—Called when the snap point changes.
closeThresholdnumber0.25Releasing after pulling down more than the lowest snap height times this fraction closes the sheet.
velocityThresholdnumber0.5Release speed (px/ms) above which a drag counts as a flick.
dismissiblebooleantrueWhether pulling down, a backdrop click and Esc can close it. When false, pulling down also resists.
containedbooleanfalseConfines the sheet to the nearest positioned ancestor (absolute). By default it is portaled to the body and fills the viewport.
initialFocusRefRefObject<HTMLElement>—Element to focus first after opening. Defaults to the panel itself.
labelsobject—Replaces built-in text (lowerSheet, raiseSheet), the handle button's names. Shallow-merged over the English defaults.
childrenReactNode—Content; it scrolls inside the content area when too tall.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the panel (the role=dialog element), such as aria-label and className.

Accesibilidad

  • The panel is role="dialog" with aria-modal="true" and its title linked by aria-labelledby.
  • Focus moves into the panel (or initialFocusRef) on open, Tab cycles inside it, and focus returns to the opener on close.
  • While open, siblings are inert: unreadable, unreachable by Tab and not clickable; outside contained mode, page scrolling is locked.
  • Esc closes; the handle is a real button: Enter and Space switch snap points, Up and Down move one step, and the hit area is 44px.
  • Reduced motion makes opening, closing and snapping jump into place while dragging still follows the finger.

Movimiento

Open 300ms ease-out, close 200ms ease-in, handle snap 320ms ease-in-out. Release snaps take 200 to 400ms by distance on a curve built from the release velocity. The dimmed, blurred backdrop follows the same curve. Reduced motion jumps into place.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

BottomSheet.jsxbottom-sheet.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Capas