Skip to content
pyreon
Install
@pyreon/dnd
fundamentals · interaction

A sortable list in one hook. Keyboard users included.

Reorder lists, build kanban boards and take file drops on Atlassian's pragmatic-drag-and-drop. Space picks an item up, the arrows move it, a screen reader hears every step, and every drag state is a signal your JSX reads directly.

bun add @pyreon/dnd
Documentation
engine
pragmatic-drag-and-dropAtlassian's engine: native drag events, hit-testing, edges.
keyboard
Space · arrows · EscAlt+Arrow moves directly. Each step is announced.
hooks
5Sortable, draggable, droppable, file drop, monitor.
iOS and Android
sortable, draggable, droppableExperimental. SwiftUI .onDrag/.onDrop, Compose drag-and-drop. File drop and the monitor stay web.
A sortable list that keyboard users can reorder too Schematic: a sortable list of four tasks. With the keyboard, the third task is focused, picked up with Space, moved up with the arrow key and dropped with Space, and a screen reader hears each step. Then a pointer drags it back down to its place. USESORTABLE · POINTER AND KEYBOARD · EVERY STEP ANNOUNCED Write the brief Post the changelog Review the PR Ship the release keys Space↑Space screen reader “Picked up Ship the release.Current position 3 of 4. …”“Moved Ship the releaseto position 2 of 4”“Dropped Ship the releaseat position 2 of 4” pointer drag: same list,same onReorder tasks.set(next) in onReorder · drag state is a signal Space picks up · arrows move · Esc cancels · Alt+Arrow moves directly
  • 20× faster hover across 1,000 rows: isOverKey wakes the two rows involved, a hand-written overId() === key wakes every rowBENCHMARKS.md §10, dnd row · overnight run, one run, bun, happy-dom (relative only)

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

The parts of drag and drop nobody finishes.

  1. Keyboard reordering, on by default

    Focus a row, Space or Enter picks it up, the arrows move it, Space drops it and Escape puts it back. Alt+Arrow moves in one step. No sensors to configure.

  2. Screen readers hear every move

    "Picked up Fix Safari bug. Current position 4 of 4." then "Moved Fix Safari bug to position 3 of 4." Items get aria-roledescription, plus role="listitem" and keyboard instructions unless you set your own.

  3. State you read, not render props

    activeId(), overId() and overEdge() are signals, and isOverKey(id) answers per row. A drop indicator is class={() => s.isOverKey(t.id) ? s.overEdge() : ''}: when the hover moves, only the row it left and the row it entered update.

  4. Files with reasons

    useFileDrop({ accept: ['image/*'], maxFiles: 5 }) gives you the accepted files, and onReject(files, 'accept' | 'maxFiles') tells you why the rest were refused.

the difference

Delete the sensors, the contexts and arrayMove.

React + dnd-kit

Two providers, two sensors, a per-row hook with a style transform, and the reorder written by hand.

function Row({ task }: { task: Task }) {
  const { attributes, listeners, setNodeRef, transform, transition } =
    useSortable({ id: task.id })
  const style = { transform: CSS.Transform.toString(transform), transition }
  return (
    <li ref={setNodeRef} style={style} {...attributes} {...listeners}>
      {task.title}
    </li>
  )
}

function Tasks() {
  const [tasks, setTasks] = useState(initial)
  const sensors = useSensors(
    useSensor(PointerSensor),
    useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
  )
  const onDragEnd = ({ active, over }: DragEndEvent) => {
    if (!over || active.id === over.id) return
    setTasks((ts) => {
      const from = ts.findIndex((t) => t.id === active.id)
      const to = ts.findIndex((t) => t.id === over.id)
      return arrayMove(ts, from, to)
    })
  }
  return (
    <DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={onDragEnd}>
      <SortableContext items={tasks} strategy={verticalListSortingStrategy}>
        <ul>{tasks.map((t) => <Row key={t.id} task={t} />)}</ul>
      </SortableContext>
    </DndContext>
  )
}
with @pyreon/dnd

One hook. Pointer, keyboard, announcements and auto-scroll included; you get the reordered array.

import { For } from '@pyreon/core'
import { useSortable } from '@pyreon/dnd'
import { signal } from '@pyreon/reactivity'

const tasks = signal<Task[]>(initial)

const Tasks = () => {
  const { containerRef, itemRef } = useSortable({
    items: tasks,
    by: (t) => t.id,
    label: (t) => t.title,
    onReorder: (next) => tasks.set(next),
  })
  return (
    <ul ref={containerRef}>
      <For each={tasks()} by={(t) => t.id}>
        {(t) => <li ref={itemRef(t.id)}>{t.title}</li>}
      </For>
    </ul>
  )
}
coming from

Coming from react-beautiful-dnd?

Same company's engine, without the render props.

react-beautiful-dnd
<DragDropContext
  onDragEnd={(r) => {
    if (!r.destination) return
    setTasks((ts) => reorder(ts, r.source.index, r.destination!.index))
  }}
>
  <Droppable droppableId="tasks">
    {(provided) => (
      <ul ref={provided.innerRef} {...provided.droppableProps}>
        {tasks.map((t, i) => (
          <Draggable key={t.id} draggableId={t.id} index={i}>
            {(p) => (
              <li ref={p.innerRef} {...p.draggableProps} {...p.dragHandleProps}>
                {t.title}
              </li>
            )}
          </Draggable>
        ))}
        {provided.placeholder}
      </ul>
    )}
  </Droppable>
</DragDropContext>
Pyreon

react-beautiful-dnd is no longer maintained, and Atlassian points its users to Pragmatic drag and drop, the engine under @pyreon/dnd. Boards across lists: give each list the same groupId and handle onCrossListDrop / onCrossListReceive.

const { containerRef, itemRef } = useSortable({
  items: tasks,
  by: (t) => t.id,
  label: (t) => t.title,
  onReorder: (next) => tasks.set(next),
})

<ul ref={containerRef}>
  <For each={tasks()} by={(t) => t.id}>
    {(t) => <li ref={itemRef(t.id)}>{t.title}</li>}
  </For>
</ul>
try it

Reorder it. Then try the keyboard.

Drag a row, or focus one and press Space, then the arrow keys, then Space again.

  • Design review
  • Ship onboarding
  • Write release notes
  • Fix Safari bug

Escape cancels a keyboard move and puts the row back.

tasks() · live signal
[
  { id: 1, title: 'Design review' },
  { id: 2, title: 'Ship onboarding' },
  { id: 3, title: 'Write release notes' },
  { id: 4, title: 'Fix Safari bug' }
]

The line under the list mirrors the live region the package announces into: that is what a screen reader hears.

benchmarks

Hover across 1,000 rows: 20× faster.

The baseline is what you would write without the wrapper: the same engine calls, the same signals, the same cleanup. Mounting costs the same, each event and each page monitor adds a few nanoseconds, and a hover that moves across a long list is where the hooks pull ahead. happy-dom is a JavaScript DOM, so read the ratios, not the times.

vs a hand-rolled signals + raw pragmatic-drag-and-drop integration · bun, happy-domPyreonrival · lower is better
  • hover fan-out, 1,000 rows (isOverKey vs overId() === key)
    win20×
  • draggable, droppable, sortable-row mount + unmount
    tiecould not distinguish
  • per-event dispatch (drag start + drop)
    loss+5 ns
  • page monitor mount + unmount
    loss+82 ns
Apple M3 Max · record of 2026-11-05 · overnight run, one run, happy-dom: relative only · author-run, syntheticFull method, every loss →
what's included

Five hooks, every drag surface.

  • useSortable Reorder with edge detection and auto-scroll; axis: 'horizontal' for rows of cards.
  • Boards groupId links lists, onCrossListDrop and onCrossListReceive(item, index) move cards between them.
  • itemHandleRef Drag only by the grip, keep the rest of the row clickable.
  • useDraggable Typed data, a handle, a custom preview and isDragging().
  • useDroppable canDrop(source) filters, edges turns on overEdge() for which side you are on, isOver() lights the target.
  • useFileDrop Real OS files only, with accept, maxFiles and isDraggingFiles() for a page-wide hint.
  • useDragMonitor Watch every element drag on the page, with canMonitor to filter, for an overlay or analytics.
  • Keyboard and live region Pick up, move, drop and cancel with announcements through @pyreon/a11y.
  • disabled A boolean or a signal: lock a list while it saves.
  • Cleanup by design Every engine registration is torn down on unmount, and per item when its ref goes null.
recipes

Things to build with it.

A drop indicator that touches two rows, not all of them

isOverKey(id) and overEdge() are signals. The line appears above or below the hovered card, and a hover move updates only the row it left and the row it entered.

const s = useSortable({
  items: tasks,
  by: (t) => t.id,
  label: (t) => t.title,
  onReorder: (next) => tasks.set(next),
})

<ul ref={s.containerRef}>
  <For each={tasks()} by={(t) => t.id}>
    {(t) => (
      <li
        ref={s.itemRef(t.id)}
        class={() => (s.isOverKey(t.id) ? `drop-${s.overEdge()}` : '')}
        data-active={() => s.isActive(t.id)}
      >
        {t.title}
      </li>
    )}
  </For>
</ul>
An avatar drop zone that says no politely

One image at a time. Rejections come with a reason you can show.

import { signal } from '@pyreon/reactivity'
import { useFileDrop } from '@pyreon/dnd'

const Avatar = () => {
  const error = signal('')
  const drop = useFileDrop({
    accept: ['image/*'],
    maxFiles: 1,
    onDrop: (files) => upload(files[0]!),
    onReject: (_files, reason) =>
      error.set(reason === 'accept' ? 'Images only' : 'One file at a time'),
  })
  return (
    <div ref={drop.ref} class={() => (drop.isOver() ? 'zone over' : 'zone')}>
      Drop a photo <span role="alert">{error()}</span>
    </div>
  )
}
api

Five hooks.

Every export has a reference page with its signature, an example and the mistakes people make with it.

hooks · 5
  • useSortable
  • useDraggable
  • useDroppable
  • useFileDrop
  • useDragMonitor
sortable state · 8
  • containerRef
  • itemRef
  • itemHandleRef
  • activeId
  • overId
  • overEdge
  • isActive
  • isOverKey
types · 10
  • UseSortableOptions
  • UseDraggableOptions
  • UseDroppableOptions
  • UseFileDropOptions
  • UseDragMonitorOptions
  • DragData
  • DropEdge
  • DropLocation
  • DragPreviewOptions
  • FileRejectReason
good to know

Good to know before you start.

Give items as a signal or getter

useSortable reads items() when a drop lands. A captured array goes stale after the first reorder.

Match by with <For by>

Use the same key in the hook's by, in itemRef(key) and in <For by>: the hook finds the dragged row by that key, and <For> moves the existing DOM node instead of rebuilding it.

File drop is for OS files

useFileDrop reacts to files dragged in from the desktop, not to in-app drags. Use useDroppable for those.

On native, the gesture hooks only

iOS and Android lower useSortable, useDraggable and useDroppable to the platform drag engines. The page-wide monitor and OS file drop stay web. Native targets are experimental.

questions

What people ask first.

Is it accessible without extra work?

Sortable lists are. Items become focusable with list semantics and instructions, the keyboard flow is built in, and every pick-up, move, drop and cancel is announced. label(item) makes the announcement say "Fix Safari bug" instead of an id.

Why pragmatic-drag-and-drop?

It is built on the browser's native drag events, which is also what lets files arrive from the desktop, and it is the engine behind Trello and Jira. @pyreon/dnd adapts its state into signals and its teardown into onCleanup.

What does the wrapper cost?

Against a hand-rolled signals + pragmatic-drag-and-drop integration, measured in one run under happy-dom: mount and unmount tie, each drag start and drop adds about 5 ns, registering a page monitor about 82 ns, and a hover move across 1,000 rows is 20× cheaper with isOverKey than with a per-row overId() === key. happy-dom times are relative, not browser times.

How do I build a kanban board?

One useSortable per column with the same groupId. Reordering inside a column calls onReorder; a card dropped into another column calls onCrossListDrop(item) on the source and onCrossListReceive(item, index) on the target, where you move it between your signals.

Drag it, or press Space. Both work.

bun add @pyreon/dnd
Read the drag and drop guide