Components

Drag-to-Reorder List

Grab a card and the others glide out of the way live. The dragged card follows the pointer with a raw translate (easing there reads as lag), each displaced sibling shifts exactly one slot on a retargetable transition, and the drop plays a FLIP: measure, reorder, invert, glide. Drag past the ends and it turns to rubber, friction instead of a wall. Fully keyboard operable too: focus a grip, Space grabs, ↑↓ move with the same glide, Escape puts it back. Tick Hard snap to feel the same math with zero interpolation.

  • Design reviewfigma
  • Ship mention popoverlab
  • Deploy stagingvercel
  • Write changelognotion
  • Announce releasesocial

Last move: none · drag a card or click a grip

Install

npx moumenlab add drag-to-reorder-list

For AI

Open .md

Usage

"use client";

import { useState } from "react";
import DragReorderList, { type ReorderItem } from "./drag-to-reorder-list";

const TASKS: ReorderItem[] = [
  { id: "design", label: "Design review", meta: "figma" },
  { id: "mention", label: "Ship mention popover", meta: "lab" },
  { id: "staging", label: "Deploy staging", meta: "vercel" },
  { id: "changelog", label: "Write changelog", meta: "notion" },
  { id: "announce", label: "Announce release", meta: "social" },
];

export default function DragReorderListExample() {
  // Controlled: hold the order yourself and persist it in onReorder.
  const [items, setItems] = useState(TASKS);
  return (
    <div className="flex flex-col items-center gap-6">
      <DragReorderList items={items} onReorder={setItems} />

      {/* flip={false} is the hard-snap comparison — same math, no glides. */}
      <DragReorderList defaultItems={TASKS.slice(0, 3)} flip={false} />
    </div>
  );
}