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.
Also 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.
When to use
Anatomy
TaskDndProvider: wraps the board and its overlay. It holdsisDropAllowed, the caller's policy, callsonMovewhen a card is dropped on an allowed target, and announces the drag fromdescribe. Required.TaskDropZone: a place a card can be dropped, usually aTaskBoardColumnthroughrender. It reportsdropState:idle,allowedorblocked. PassdragIntowhen the zone is itself the place, as a column sorted by a field is, whose cards carry nodropId: while a card it allows is over it, it carriesdata-drag-into.TaskDraggable: wraps one TaskCard and makes it draggable. WithdropIdit 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, aDragLiftwith the card's radius. Render the dragged card inside it, and nothing when no card is dragged.
States
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 isafter. - While a
TaskDragOverlayis 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 inonMove, so the copy has a place to glide to.onMovemay return a promise, andonMoveErrorreceives 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.
TaskDraggablecarries 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
onMoveoronDragEndonce the board has rendered the move. - The instructions read with each card say Space, not Enter (
dragInstructions). Each step is announced by name fromdescribe: the card's title (name), the status or column it would land in (place) and why a place refuses it (refusal), built withcreateDragAnnouncements; pass your translations asmessages. Withoutdescribenothing is announced: dnd-kit's own announcements, which read out ids, never ship.accessibilitygoes to dnd-kit'sDndContextas is, over both. The TaskBoard composition shows how. TaskDropPlaceholderis hidden from assistive technology.
Rules
- Decide in
isDropAllowedwhich 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
TaskCardinTaskDragOverlay, so the card under the pointer reads the same as the one in the column.
API
TaskDndProvider
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.
TaskDraggable
Also takes the attributes of its element.
TaskDropPlaceholder
Also takes the attributes of its element.
TaskDropZone
Also takes the attributes of its element.
Related
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 ownersContextMenuTrigger,SortableTabsTab,SortableComposerAttachmentandTaskDraggable. - 0.84.0 · FixedA sorted board column shows that it is the place while a card is over it:
TaskDropZonetakesdragInto. With it, the zone carriesdata-drag-intoand takesfill-subtlewhile a card it allows is over it, its cards and all; never at rest, and never while it refuses the card (dropStateblocked). - 0.81.0 · Fixed
DragLiftrenders the copy indocument.bodyby default: the lifted copy goes through a portal to the body unlesscontainernames another element, ornullkeeps it in place; the portal keeps the theme scope it was rendered in.TaskDragOverlayfollows, asSortableTabsListandSortableComposerAttachmentsalready 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
describeonTaskDndProviderannounces cards and places by name; without it nothing is announced (no ids).TaskDragOverlaytakescontainer. - 0.8.1 · Added
TaskDndProvidertakesaccessibility(theTaskDndAccessibilitytype), passed through to dnd-kit, so you can translate the screen-reader announcements and drag instructions. - 0.8.1 · FixedKeyboard dragging in
TaskDndProvidermoves a card between drop targets. Before, Space picked the card up but the arrow keys never moved it.