Drag & Drop Agent Skill
Sortable lists, kanban boards, file drop zones with dnd-kit, touch support, and accessibility.
The Skill
Full content, every format. Copy it, download it, or install with one command.
---
description: Sortable lists, kanban boards, file drop zones with dnd-kit, touch support, and accessibility.
homepage: https://yepapi.com/skills/drag-and-drop
metadata:
tags: [dnd, kanban, sortable, dnd-kit]
---
# Drag and Drop
## Rules
- Use `@dnd-kit/core` + `@dnd-kit/sortable` — modern, accessible, touch-friendly DnD library
- Sortable lists: wrap in `<SortableContext>`, each item uses `useSortable()` hook
- Kanban boards: `<DndContext>` with multiple `<SortableContext>` containers — one per column
- File drop zones: `react-dropzone` or native `onDragOver`/`onDrop` with `e.dataTransfer.files`
- Touch support: dnd-kit handles touch natively — use `TouchSensor` and `PointerSensor` with activation constraints
- Accessibility: dnd-kit provides keyboard DnD out of the box — `KeyboardSensor` with `sortableKeyboardCoordinates`
- Optimistic reorder: update state immediately on drop, persist to server in background, rollback on error
- Drag overlay: use `<DragOverlay>` for a floating preview of the dragged item — better visual feedback
## Patterns
```tsx
import { DndContext, closestCenter, DragOverlay } from "@dnd-kit/core";
import { SortableContext, verticalListSortingStrategy, useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
function SortableItem({ id, children }: { id: string; children: React.ReactNode }) {
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
const style = { transform: CSS.Transform.toString(transform), transition };
return (
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
{children}
</div>
);
}
function SortableList({ items }: { items: Item[] }) {
const [activeId, setActiveId] = useState<string | null>(null);
return (
<DndContext
collisionDetection={closestCenter}
onDragStart={({ active }) => setActiveId(active.id)}
onDragEnd={handleDragEnd}
>
<SortableContext items={items.map((i) => i.id)} strategy={verticalListSortingStrategy}>
{items.map((item) => (
<SortableItem key={item.id} id={item.id}>{item.name}</SortableItem>
))}
</SortableContext>
<DragOverlay>{activeId ? <ItemPreview id={activeId} /> : null}</DragOverlay>
</DndContext>
);
}
```
## Avoid
- Using HTML5 drag API directly — poor touch/mobile/accessibility support
- Forgetting keyboard accessibility — always include `KeyboardSensor`
- Mutating state during drag — update only on `onDragEnd`
- Missing `DragOverlay` — without it, the original item disappears during drag with no visual feedbackInstall
Why Use the Drag & Drop Skill?
Without this skill, your AI guesses at drag & drop patterns. It might hallucinate deprecated APIs, use outdated conventions, or miss best practices entirely. With it, your AI follows a proven ruleset — every suggestion aligns with current standards.
Drop this skill into your project and your AI instantly knows the rules. Better code suggestions, fewer errors, faster shipping.
Try These Prompts
These prompts work better with the Drag & Drop skill installed. Your AI knows the context and writes code that fits.
"Build a kanban board with drag-and-drop columns and sortable cards using dnd-kit"
"Create a file drop zone with drag preview, upload progress, and image thumbnails"
"Add sortable list reordering with touch support and accessible keyboard controls"
Works Great With
Drag & Drop skill — FAQ
It provides dnd-kit patterns for sortable lists, kanban boards, and file drop zones with touch support. Your AI builds accessible drag-and-drop interfaces with proper keyboard fallbacks.
Run `npx skills add YepAPI/skills --skill drag-and-drop` in your project root. This copies the skill file into your repo where your AI coding tool can read it automatically.
Yes. The skill includes keyboard-based drag-and-drop as a fallback. dnd-kit supports screen reader announcements, keyboard activation, and ARIA attributes for sortable interactions.