Back to Explore
THE PLAYGROUND · GESTURES

Drag-and-drop

Grab an item and move it into a new position.

Drag-and-dropGestures · Grab an item and move it into a new position.
DRAG
  • Design the motion
  • Build the interaction
  • Polish the details
DRAG TO INTERACT · 600 ms
1import { useState } from "react";2import { Reorder } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function DragDropDemo() {7  const [items, setItems] = useState(["Design", "Build", "Polish"]);8  return <Reorder.Group axis="y" values={items} onReorder={setItems}>9    {items.map(item => <Reorder.Item key={item} value={item} style={{...surface, width: 260, height: 48, margin: 8}}>10      {item}<button onClick={() => setItems([item, ...items.filter(v => v !== item)])}>Move to top</button>11    </Reorder.Item>)}12  </Reorder.Group>;13}

Install: npm install motion. Use a drag handle and a keyboard reorder alternative. This compact example illustrates the core technique; the styled playground contains additional presentation details.