Back to Explore
THE PLAYGROUND · GESTURES

Swipe-to-reveal Actions

Slide a list item aside to uncover contextual actions.

Swipe-to-reveal ActionsGestures · Slide a list item aside to uncover contextual actions.
DRAG
A little good newsYour ideas are taking shape.
DRAG TO INTERACT · 600 ms
1import { useState } from "react";2import { motion } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function SwipeRevealDemo() {7  const [dismissed, setDismissed] = useState(false);8  const [rotation, setRotation] = useState(0);9  return <div style={{width: 320, overflow: "hidden"}}>10    <button onClick={() => {setDismissed(false); setRotation(0);}}>Reset</button>11    {!dismissed && <motion.div style={surface} drag="x" dragConstraints={{left: -100, right: 0, top: 0, bottom: 0}} dragElastic={0.25} animate={{rotate: rotation}} transition={{ type: "spring", stiffness: 180, damping: 14, mass: 1 }}12      onDrag={(_, info) => undefined}13      onDragEnd={(_, info) => {  }}>Drag me</motion.div>}14    <button onClick={() => setDismissed(true)}>Delete item</button>15  </div>;16}

Install: npm install motion. Keep a keyboard-accessible action alternative. This compact example illustrates the core technique; the styled playground contains additional presentation details.