Skip to content
SortableExamples

React — Copy items

comins-sortable@0.1.6React

Create copies with unique IDs in React while retaining the source, and verify cancellation and reverse rejection.

  1. Drag the Note handle from the catalog into the empty board. Both source items remain and one copy appears.
  2. Copy the same Note again. The board contains two copies with distinct IDs.
  3. Dragging a copy back into the catalog is refused; this example permits delivery only from catalog to board.
  4. Start a source drag and cancel with Escape. List membership remains unchanged.
  5. Reset restores the source order and clears the board. The ID sequence is not reused.

Dragging uses pointer input. Inspect the onAfterDrag status and displayed IDs to verify the result.

Area Setting Meaning
Source group: { name: "templates", pull: "copy", put: false } Copies out and refuses incoming items from other areas.
Destination group: { name: "templates", pull: false } Accepts the same group and does not export items.
Both Different areaId values Distinguishes area identity in the shared scope.

pull: "copy" retains source items during cross-area delivery. It does not automatically disable reordering within that same area. The source remains visible during a drag while preview and placeholder provide separate feedback.

Two SortableArea components share a scope inside SortableRoot. Connect each area’s items and onItemsChange. Supply copyItem on the source area only. Generate IDs when the copy factory runs, not on every render.

In the published 0.1.4 adapter, changing the group object identity during a copy commit can trigger an area validation error. This example keeps policy objects outside the component. Dynamically changing policies during copying is outside this example’s verified scope.

type CopyItem<T> = (item: T, context: CopyItemContext) => T;

Return a new object and a new ID. The example uses spread because items are shallow objects. Add an application-specific cloning policy if nested objects must be edited independently.

Check onAfterDrag.status === "dropped"; a list update notification alone does not confirm completion. Distinguish Escape, outside drops, and policy rejection from a committed copy. Missing or duplicate IDs and malformed copy results are not valid copies.

The ID counter is local to one demo instance. Persistence or multi-client use needs an application-wide collision-free identity policy. Alt/Option copying, custom previews, and exhaustive malformed-input testing are separate scenarios.

Copy guide · Core lifecycle · Vanilla instance · Transfer with this adapter