Ir al contenido
Español
Cajón con anclajes viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

During a drag the offset is written straight to CSS variables, so no React render happens per frame. On release the position is projected 220ms ahead with the release velocity and the nearest snap point wins; a flick always moves at least one point. Past the top edge the drag resists with a rubber-band curve. The second-highest point to full drives --ds-snap-p, which scales the background to 0.93, rounds its corners and dims a scrim.

Úsalo para

  • Map, media or list screens on phones where the content behind should stay visible.
  • Progressive detail: a peek summary that expands into the full list.

Busca otra opción cuando

  • A short choice or confirmation: use a simple bottom sheet or dialog.
  • Wide desktop layouts: use a side panel.

Uso

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

export function MapScreen() {
  const [open, setOpen] = useState(true)
  return (
    <SnapDrawer
      open={open}
      onOpenChange={setOpen}
      snapPoints={[0.22, 0.55, 0.92]}
      background={<Map />}
      header={<h2>Nearby</h2>}
    >
      <PlaceList />
    </SnapDrawer>
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
openbooleantrueWhether the drawer is shown.
onOpenChange(open: boolean) => void—Called when it is swiped away or Escape is pressed.
snapPointsnumber[][0.22, 0.55, 0.92]Visible heights as fractions of the frame, lowest first.
snap / defaultSnap / onSnapChangenumberdefaultSnap 1The current snap index, controlled or not.
snapLabelsstring[]['Peek', 'Half', 'Full']Spoken names of the snap points.
backgroundReactNode—The screen behind the drawer; it scales back as the drawer reaches full.
headerReactNode—Always-visible top part; it is also a drag area.
childrenReactNode—The body; it scrolls only at full height.
dismissiblebooleantrueAllow swiping below the lowest point to close.
scaleBackgroundbooleantruePush the background back near full height.
containedbooleanfalseFill the nearest positioned ancestor instead of the viewport.
label / handleLabelstringhandleLabel 'Resize sheet'Accessible names of the drawer (defaults to the header) and its handle.

Accesibilidad

  • The drawer is role dialog (modal only at full height) labelled by its header.
  • The handle is a vertical role slider with aria-valuetext naming the snap point; Up and Down move between points, Home and End jump, Enter cycles.
  • Escape closes it when dismissible; a closed drawer is inert and aria-hidden.
  • Drag areas use touch-action none, while the body scrolls natively at full height; the handle is 88 by 26 px plus the header area.
  • With reduced motion snapping is instant and only the scrim fades.

Movimiento

Snap 520ms cubic-bezier(0.32, 0.72, 0, 1); velocity projection 220ms; rubber band (1 − 1/(0.55·d/D + 1))·D with D = 15% of the frame; background scale 1 → 0.93, radius 0 → 18px, scrim 0 → 30%.

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.

SnapDrawer.jsxsnap-drawer.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
Panel inferior viene con Pro. La vista previa aparece al desbloquearlo.