FragiolaDnD
Documentation
API (@fragiola/dnd-react)

Droppable

The wrapper that makes its single child a drop target, with no provider. Every prop, what accepts takes, its state, attributes and events.

Droppable makes the one element it wraps a drop target in its document's drag space. It renders no element of its own and adds data-dnd-* attributes saying what a drag in progress would do there.

folder.tsx
import { Droppable } from "@fragiola/dnd-react/droppable";

<Droppable id="images" accepts={["image"]} onDrop={(event) => moveFile(event.operation.source.id, "images")}>
    <section aria-label="Images">{files}</section>
</Droppable>;

Props

proptypedefault
idstring | numberrequiredunique within its scope; reported as operation.target.id
dataunknownanything the app wants back (operation.target.data)
scopestringthe default scopeonly draggables of the same scope meet it
spaceDragSpaceits document'san explicit space from createDragSpace
acceptsstring[] | (source: DragSource) => booleaneverythingthe draggable types it takes, or a predicate of the source
disabledbooleanfalsenever a target
onDragEnter(event: DroppableEvent<"drag-enter">) => voida drag entered it, or started over it (right after the draggable's onDragStart)
onDragOver(event: DroppableEvent<"drag-over">) => voida drag moved over it, once per frame
onDragLeave(event: DroppableEvent<"drag-leave">) => voida drag left it
onDrop(event: DroppableEvent<"drop">) => voidan accepted source was released over it, before the draggable's onDragEnd
className, style, render, ref, childrenas on Draggable, with the droppable's state

Any other prop is forwarded to the element.

Accepting and refusing

accepts is a list of draggable types (a draggable with no type matches no list) or a predicate of the source { id, type, data }. A predicate that throws refuses. Then the space's drop middleware runs (space.use), as a dry run on each hover and for real on the release: a veto refuses too. A refused source hovering the droppable marks it data-dnd-refused and never reports onDrop. The hover callbacks still run for a refused source; event.operation.target is undefined then.

Typed sources, refusing targets
Gallery

State

{ over: boolean; active: boolean; refused: boolean; disabled: boolean }, given to className, style and render.

Attributes

attributewhen
data-dnd-part="droppable"always
data-dnd-idalways: the id, as a string
data-dnd-activea drag runs that it would accept
data-dnd-overan accepted source hovers it
data-dnd-refuseda refused (or vetoed) source hovers it
data-dnd-disabled, aria-disabled="true"disabled

A droppable re-renders when a drag it would accept starts and ends, and on enter and leave; never while a drag moves inside it.