Raft Design System

Components · Tasks

TaskDnd

The drag-and-drop parts that let people move task cards between columns and around other cards, with the drop policy and the move left to the caller.

StableAlso called Drag and drop, DnD, TaskDraggable, TaskDropZone
import { TaskDnd } from "@botiverse/raft-ui";

TaskDnd is the drag-and-drop wiring behind the TaskBoard: a provider, the cards people drag, the places they drop them, the gap a card lands in and the copy of the card that follows the pointer. It follows the one drag model (Drag and drop) and is built on its parts (Drag). It decides nothing about tasks. The caller says which drops are allowed and what a move does, such as changing #25 from Todo to In progress.

task-dnd/compositions/task-dnd

When to use

SituationUse
Moving a card to another column of a board to change its statusTaskDnd, inside a TaskBoard
Reordering a card among the cards of a columnTaskDnd, with a drop target on each card, only when the column's order is the person's. A column sorted by a field is one drop target, with no dropId on its cards (Where it will land)
Changing a status without draggingThe status chip on the card, or the property in the task's details (Tasks)
Reordering composer attachmentsThe composer's own sortable attachments (Composer)
Resizing a columnResizable

Anatomy

  • TaskDndProvider: wraps the board and its overlay. It holds isDropAllowed, the caller's policy, calls onMove when a card is dropped on an allowed target, and announces the drag from describe. Required.
  • TaskDropZone: a place a card can be dropped, usually a TaskBoardColumn through render. It reports dropState: idle, allowed or blocked. Pass dragInto when the zone is itself the place, as a column sorted by a field is, whose cards carry no dropId: while a card it allows is over it, it carries data-drag-into.
  • TaskDraggable: wraps one TaskCard and makes it draggable. With dropId it is also a drop target, so a card can land before or after it.
  • TaskDropPlaceholder: the gap where the card would land, before or after a card, or in an empty column, in the one dashed look (DropPlaceholder). It shows only while the drop there is allowed, and never next to the dragged card itself.
  • TaskDragOverlay: the copy of the card that follows the pointer, a DragLift with the card's radius. Render the dragged card inside it, and nothing when no card is dragged.

States

StateLook
DraggingThe copy in TaskDragOverlay is lifted: layer-popover, shadow-float and a line-seam ring. The card itself stays in its column at 40% (data-drag-origin)
Over an allowed targetTaskDropPlaceholder shows the dashed line-strong place on fill-subtle, with the height of the dragged card
Over a sorted columnWith dragInto, the zone itself takes fill-subtle (data-drag-into), its cards and all, and no place opens between them: dropped, the card goes where the sort puts it, so the whole column is the place
Over its own cardNo placeholder: dropping there moves nothing
Over a blocked targetNo placeholder and no fill; the target's dropState is blocked, and an empty column says why (TaskBoard). Render a DragRefusalHint with the reason, as the board composition does
Dragging turned offdisabled on the provider removes every way to drag; disabled on a TaskDraggable removes it for that card

Behavior

  • With a mouse, a drag starts once the pointer has moved 6px, so a click on the card isn't a drag (useDragSensors).
  • On a touch screen, hold the card still for 500ms, then move it: the drag starts on that move. Moving before the hold is up scrolls the board instead (Dragging on a touch screen).
  • Where the card lands follows the middle of the dragged card: above the middle of the card under it is before, below is after.
  • While a TaskDragOverlay is rendered, the dragged card stays in its place at 40% instead of moving with the pointer; keep it in its column while it is dragged. A board that still takes the card out of its column while it is dragged keeps working, as before.
  • On a drop the copy glides into the card's new place, and on a cancel back to the card, in 160ms (motion-drag-settle-*; none with reduced motion). The move is the caller's: render the card in its new place in onMove, so the copy has a place to glide to. onMove may return a promise, and onMoveError receives its rejection, so the caller can undo the change and say what went wrong.
  • A drop on the dragged card's own target, or on nothing, calls no onMove.
  • The board scrolls while the pointer is within 48px of the edge of anything that scrolls (DragLift).

Accessibility

  • The parts wrap dnd-kit, not Base UI. TaskDraggable carries dnd-kit's attributes: it is focusable, with a role description and instructions for screen readers.
  • Keyboard: Tab to a card, then Space picks it up; Enter never does, so Enter can open the card. ArrowDown and ArrowUp move it one slot down or up its column, before or after each card; ArrowLeft and ArrowRight move it to the nearest drop target in the next column, such as an empty column or the card level with it. Space drops it and Escape cancels. The keys step between drop targets, so a card moves the same way whether or not it leaves its column while it is dragged.
  • After a keyboard drop, focus stays where dnd-kit leaves it. Moving focus to the moved card, which has a new place in the DOM, is the caller's job: focus it in onMove or onDragEnd once the board has rendered the move.
  • The instructions read with each card say Space, not Enter (dragInstructions). Each step is announced by name from describe: the card's title (name), the status or column it would land in (place) and why a place refuses it (refusal), built with createDragAnnouncements; pass your translations as messages. Without describe nothing is announced: dnd-kit's own announcements, which read out ids, never ship. accessibility goes to dnd-kit's DndContext as is, over both. The TaskBoard composition shows how.
  • TaskDropPlaceholder is hidden from assistive technology.

Rules

  • Decide in isDropAllowed which drops are allowed, so the target says while the card is over it that it can't move there (TaskBoard).
  • Offer another way to change a status: dragging is one of four (Tasks).
  • Put the dragged card's own TaskCard in TaskDragOverlay, so the card under the pointer reads the same as the one in the column.

API

TaskDndProvider

PropTypeDefault
accessibilityPassed to dnd-kit's `DndContext` as is, over the announcements built from `describe`.{ announcements?: Announcements; container?: Element; restoreFocus?: boolean; screenReaderInstructions?: ScreenReaderInstructions; }
children (required)ReactNode
describeThe card and the places it can go, in words, for the screen-reader announcements: `name` (the card's title, never its id), `place` (the status or column and the position) and `refusal`. Without it nothing is announced, so no id is ever read out.DragAnnouncementSource
disabledbooleanfalse
isDropAllowed(activeId: UniqueIdentifier, overId: UniqueIdentifier, overData: TaskDropData | undefined) => booleanallowTaskDrop
messagesYour translations of the announcements and instructions.Partial<DragMessages>
onDragCancel(event: DragCancelEvent) => void
onDragEnd(event: DragEndEvent) => void
onDragMove(event: DragMoveEvent) => void
onDragOver(event: DragOverEvent) => void
onDragStart(event: DragStartEvent) => void
onMove(details: TaskMoveDetails) => void | Promise<void>
onMoveError(error: unknown, details: TaskMoveDetails) => void

TaskDragOverlay

The copy of the dragged card that follows the hand: a `DragLift` with the card's radius. On a drop it glides into the card's new place, and on a cancel back home. While it is rendered, the dragged card stays in its place at 40% instead of moving.
PropTypeDefault
childrenReactNode
containerWhere the copy renders: `document.body` by default, so it rises above everything outside a ScrollArea the board is in. `null` renders it in place (`DragLift`'s `container`).Element | DocumentFragment

TaskDraggable

PropTypeDefault
disabledbooleanfalse
dropDataTaskDropData
dropDisabledbooleanfalse
dropIdUniqueIdentifier

Also takes the attributes of its element.

TaskDropPlaceholder

PropTypeDefault
placementTaskDropPlacement
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

TaskDropZone

PropTypeDefault
dataTaskDropData
disabledbooleanfalse
dragIntoThe zone is itself the place, as a column sorted by a field is: its cards carry no `dropId` and no placeholder opens between them. While a card it allows is over it, it carries `data-drag-into` and takes `fill-subtle`; never at rest, and never while it refuses the card. Without it the zone is never filled, and only a `TaskDropPlaceholder` says where the card lands.booleanfalse
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

Changes

  • 0.104.0 · Design SystemTooltips on a touch screen, and who owns a long press ([Tooltip › Touch screens](https://raft-design.botiverse.build/components/tooltip/#touch-screens), [States › Dragging on a touch screen](https://raft-design.botiverse.build/foundations/states/#dragging-on-a-touch-screen)): on a touch screen a tooltip opens on a press and hold, on a disabled button too (focusableWhenDisabled); a long press belongs to the layer that owns it (a long-press menu, a touch drag, a link), and the tooltip takes it only when nothing else wants it. Changed in this release: TooltipTrigger, and the long-press owners ContextMenuTrigger, SortableTabsTab, SortableComposerAttachment and TaskDraggable.
  • 0.84.0 · FixedA sorted board column shows that it is the place while a card is over it: TaskDropZone takes dragInto. With it, the zone carries data-drag-into and takes fill-subtle while a card it allows is over it, its cards and all; never at rest, and never while it refuses the card (dropState blocked).
  • 0.81.0 · FixedDragLift renders the copy in document.body by default: the lifted copy goes through a portal to the body unless container names another element, or null keeps it in place; the portal keeps the theme scope it was rendered in. TaskDragOverlay follows, as SortableTabsList and SortableComposerAttachments already did.
  • 0.36.0 · ChangedTaskDnd: the lifted card is a copy that glides into place on a drop and back on a cancel; the card stays in its column at 40% instead of collapsing, and a drop on its own place moves nothing. A mouse drag starts after 6px (was 5px) and Enter no longer starts a keyboard drag. New describe on TaskDndProvider announces cards and places by name; without it nothing is announced (no ids). TaskDragOverlay takes container.
  • 0.8.1 · AddedTaskDndProvider takes accessibility (the TaskDndAccessibility type), passed through to dnd-kit, so you can translate the screen-reader announcements and drag instructions.
  • 0.8.1 · FixedKeyboard dragging in TaskDndProvider moves a card between drop targets. Before, Space picked the card up but the arrow keys never moved it.