drag-to-reorder

Implements @dnd-kit sortable drag-to-reorder behavior for desktop and touch layouts.

9.5k|1.0k|Updated Sep 11, 2025
One-click install
npx skills add https://github.com/openchamber/openchamber --skill drag-to-reorder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drag-to-reorder
Source: https://github.com/openchamber/openchamber/tree/main/.agents/skills/drag-to-reorder
Command: npx skills add https://github.com/openchamber/openchamber --skill drag-to-reorder

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @dnd-kit/core, @dnd-kit/sortable, @dnd-kit/utilities.

What problem does it solve?

Drag-to-reorder with @dnd-kit breaks in non-obvious ways: dragged items stretch to slot width, wrapping rows overlap instead of reflowing, touch gestures fight scrolling, and live reordering causes "Maximum update depth exceeded" loops. This Skill captures the working configuration and the bugs to avoid.

Core Features & Use Cases

  • Five core rules: Use CSS.Translate instead of CSS.Transform, pick the sorting strategy by layout (rectSortingStrategy for wrapping grids), split MouseSensor and TouchSensor, apply touch-action: none, and reorder once in onDragEnd with stable IDs and arrayMove.
  • Symptom index: Maps common symptoms (stretching, overlap, update-depth errors, touch scroll hijacking) directly to their cause and fix.
  • Use Case: When building a row of variable-width preset chips that wraps onto multiple lines and must support tap-to-activate, long-press-to-drag on mobile, and smooth reordering on desktop, apply this Skill to wire DndContext, sensors, and SortableContext correctly the first time.

Quick Start

Use the drag-to-reorder skill to add a sortable, wrapping row of chips with @dnd-kit that works on both desktop and mobile touch.

Frequently Asked Questions about drag-to-reorder

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement drag-to-reorder with @dnd-kit in React?

Wrap items in DndContext and SortableContext, use useSortable per item, and reorder state with arrayMove inside onDragEnd. Configure MouseSensor with a distance constraint and TouchSensor with a delay so clicks, taps, and scrolling still work.

Which dnd-kit sorting strategy should I use for wrapping grids?

Use rectSortingStrategy for any layout that wraps onto multiple rows or contains variable-width items. horizontalListSortingStrategy assumes a single row, so dragging across rows causes overlap instead of reflow.

Why does my dragged item stretch to the target slot width in dnd-kit?

CSS.Transform.toString emits scaleX/scaleY, and the sorting strategy applies a non-1 scale to the lifted item so it stretches to the neighbor's width. Switch to CSS.Translate.toString, which applies translation only and preserves the item's own size.

How do I make dnd-kit drag work on mobile touch devices?

Use a separate TouchSensor with an activation constraint like delay: 200 and tolerance: 6 so long-press drags while taps and swipes still work. Also add touch-action: none (Tailwind touch-none) to the draggable element so the browser does not hijack the gesture for scrolling.

Why does dnd-kit throw Maximum update depth exceeded during drag?

Live-reordering in onDragOver with variable-size items causes an oscillating A-B state loop that triggers the error. Reorder only once in onDragEnd instead, and avoid pairing live reorder with an empty DragOverlay.