A drag tile that answers copy or move: hold Alt and it splits into twin tiles, its copy key lit; a move-only target holds the twin back; a drop throws its count into Undo.
DragDrag
drag-twin, lively
Use Drag Twin where people drag rows or cards to a place and the question is "copy or move?": file managers, kanban boards, media libraries, table rows into groups. The tile under the pointer says "3 · Move"; hold Alt / Option (or press C, or tap the "Copy" pill on touch) and it pinches at its waist and splits into twin tiles that say "Copy"; let go and they fuse back. Over a target that takes moves only, the twin cannot get away: the neck stretches, holds and snaps back, and the tile says "Move only here". The tile carries its own copy key (⌥ / Alt with a mouse, C with the keyboard) that lights while copy is on, so the shortcut is found without reading instructions. With onUndo, a drop throws the count ball into an Undo pill, so every drop is reversible. People know what the drop will do before they let go, and can take it back after. For reordering inside one list, use a sortable list; for a single upload area, use a dropzone.
pnpm dlx shadcn@latest add @motionkit-pro/drag-twinnpx shadcn@latest add @motionkit-pro/drag-twinyarn dlx shadcn@latest add @motionkit-pro/drag-twinbunx --bun shadcn@latest add @motionkit-pro/drag-twinRequires a Pro license and the @motionkit-pro registry with your token. See Installation.
import {
DragTwin,
DragTwinHandle,
DragTwinSource,
DragTwinStatus,
DragTwinTarget,
DragTwinUndo,
} from "@/components/ui/drag-twin"
export function Drive() {
return (
<DragTwin
onDrop={({ source, target, mode }) => transfer(source, target, mode)}
onUndo={({ source, target, mode }) => revert(source, target, mode)}
>
{folders.map((f) => (
<DragTwinTarget key={f.id} value={f.id} label={f.name} allowCopy={!f.archive}>
{f.name}
</DragTwinTarget>
))}
<ul>
{files.map((f) => (
<DragTwinSource key={f.id} value={f.id} count={selection.size} asChild>
<li>
<DragTwinHandle aria-label={`Drag ${f.name}`} />
{f.name}
</li>
</DragTwinSource>
))}
</ul>
<footer>
<DragTwinStatus />
<DragTwinUndo />
</footer>
</DragTwin>
)
}DragTwin holds the drag, draws the tile and announces every state. A DragTwinSource is a row or card: mouse drags start anywhere on it (except on its controls), after 5 px. Its DragTwinHandle is a grip button where touch drags and the keyboard path start. A DragTwinTarget gets data-over="move" | "copy" | "only" while the tile is over it, so you style the highlight; allowCopy={false} makes it move-only. onDrop receives { source, target, mode, count }; nothing is moved for you. DragTwinStatus shows the status line ("Release to copy 3 files to Design."); useDragTwin() gives the drag state for your own hints, such as a lit Alt key.
Undo: pass onUndo and place DragTwinUndo where the eyes land after a drop (next to the status line). Its space is always kept, so nothing shifts when it appears. On a drop the count ball leaves the tile, arcs into the pill and pops there; Undo, or Ctrl / Cmd + Z anywhere inside the area outside a text field, calls onUndo(drop) with the same object onDrop got, and you revert it. Undo stays for undoWindow ms (default 6000), paused while it is hovered or focused. Without onUndo nothing changes from earlier versions.
copy forces copy while true (for a modifier read by another library), noun names the items in announcements and labels changes the tile's words. Presets: stack (default, a tile right of the pointer, the twin down and right), capsule (a pill) and mirror (the tile left of the pointer, the twin down and left, for drags toward a right-hand panel). shape and side override the preset.
Set the character for the whole app with MotionKitProvider, or per instance with temperament (calm, lively, playful). It changes motion intensity only (overshoot, squash, kick), never the drawing.
Prop
Type
Also accepts all props of Omit<ComponentProps<"div">, "onDrop">.
Prop
Type
Also accepts all props of ComponentProps<"div">.
Prop
Type
Also accepts all props of ComponentProps<"div">.
The default demo: three folders (Archive takes moves only), the files of a folder with two selected, a locked file that cannot be dragged, a status line and Undo. On first view the selection is picked up, carried to Design, split with Alt, fused back and put down. Drop it for real and the count ball lands in Undo.
DragDrag
drag-twin, lively
A kanban board with the capsule preset: Alt copies a card as a template; Shipped takes moves only.
DragDrag
drag-twin, lively
Assets go to a collections panel on the right with the mirror preset, so the tile and its twin open away from the panel.
DragDrag
drag-twin, lively
aria-hidden layer with pointer-events: none; it never takes focus or hides the targets from the pointer.DragTwinStatus shows the same text and is hidden from screen readers so it is not read twice.aria-pressed button, 36 px tall) appears beside the grab point while dragging; a second finger taps it.aria-hidden); the handle's description and the live region say the same.DragTwinUndo is a native button named "Undo move of 3 files to Design". While closed it is inert and hidden from assistive tech. After a keyboard drop that removed the focused row, focus moves to Undo; after Undo, focus returns to the restored item's handle. The undo window pauses while the button is hovered or focused.popover with a hairline rim, a tinted soft shadow and a primary count ball, at least 4.5:1 in both themes. Handles show a 3 px focus ring.| Key | Action |
|---|---|
| Enter / Space | On a handle: picks the items up and points at the first target; then drops |
| Arrow keys | While a keyboard drag is live: chooses the previous or next target |
| Alt / Option (hold), C | While dragging: copy instead of move; the tile splits in two (C toggles) |
| Escape / Tab | Cancels the drag; nothing changes |
| Ctrl / Cmd + Z | After a drop, with onUndo: undoes it (outside text fields) |
No pinch, neck, split, squash or follow lag: the second tile fades in behind the first (160 ms), the label cross-fades, the tile sits on the pointer and a drop fades out. The ball does not fly to Undo: the pill fades in with its ball already in place.
requestAnimationFrame loop runs while the tile follows the pointer or a beat plays, and stops when it rests.@radix-ui/react-slot (about 1 kB gzip) for asChild.Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, @radix-ui/react-slot.
drag, a keyboard shortcut, press
No pinch, neck, split, squash or follow lag: the second tile fades in behind the first, the label cross-fades and the tile sits on the pointer. No flight to Undo: the pill fades in with its ball in place.
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)