#430
Sortable list
A checklist whose rows reorder by dragging a grip, by touch press-and-hold, or with the keyboard (Space, arrows, Enter).
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Sortable list" pattern (@codeatlasdev/ui demo #430, foundation/drag-and-drop) in my app.
Call get_demo({ ids: ["#430"] }) first and keep its structure. It needs @codeatlasdev/[email protected].
Use: Any short ordered list the user curates: checklists, playlists, priorities, form field order.
Keep these library parts, with the props and tokens the demo uses:
- applyMove, DndLayer, useDnd, DndDropEvent from "@codeatlasdev/ui"
Behaviour to keep:
- `const dnd = useDnd();` once per component; `{@attach dnd.sortable(() => ({` on the `ul` with `handle: '.sl__grip'`, `getItems` and `onDrop`
- Each `li` carries `data-dnd-item={task.id}`; the grip `button` has `aria-describedby={dnd.instructionsId}` and an `aria-label` naming the task
- `onDrop` commits the move with `applyMove({ list: tasks }, e, (t) => t.id).list`; nothing re-renders while the pointer moves
- `<DndLayer {dnd} />` renders the keyboard instructions (`dnd.instructionsId`) and the drag styles once; every step is announced to screen readers
Reduced motion: the demo handles it; keep that branch.
Keyboard: operable; keep the focus order and key handling.
Change only the copy and the data. Use the theme tokens (--ca-*), never raw colours. Library parts
- DndLayer
@codeatlasdev/ui
How it is built
- `const dnd = useDnd();` once per component; `{@attach dnd.sortable(() => ({` on the `ul` with `handle: '.sl__grip'`, `getItems` and `onDrop`
- Each `li` carries `data-dnd-item={task.id}`; the grip `button` has `aria-describedby={dnd.instructionsId}` and an `aria-label` naming the task
- `onDrop` commits the move with `applyMove({ list: tasks }, e, (t) => t.id).list`; nothing re-renders while the pointer moves
- `<DndLayer {dnd} />` renders the keyboard instructions (`dnd.instructionsId`) and the drag styles once; every step is announced to screen readers
Related
Loading source.