Drag and drop with dnd-kit

5231
0

Drag and drop UIs feel natural for reordering lists or organizing content. The dnd-kit library provides accessible, performant drag and drop with full keyboard support. I use DndContext to wrap draggable areas, useSortable for sortable list items, and SortableContext to manage ordering. The library handles touch events, mouse events, and keyboard navigation automatically. When items are dropped, I update local state optimistically and persist the new order to Rails via API. Animations during drag make interactions feel smooth. The accessibility features mean keyboard-only users can reorder items with arrow keys and space/enter, meeting WCAG standards.