Skip to main content

DragAndDrop

Result
Loading...
Live Editor

Horizontal dragging

The DragAndDrop component supports setting the type prop to column which will lock the drag behavior to the horizontal axis and change the drag icon. The DragAndDropContainer styles will need to be updated to incorporate a preferred column style.

Result
Loading...
Live Editor

Theme

Setting the theme prop to border displays a border around each DragAndDropItem.

Result
Loading...
Live Editor

Multiple DragAndDropContainers

To allow items to move between multiple DragAndDropContainers you will need to:

  • Set the DragAndDrop component's type prop to be canvas.
  • Add two or more DragAndDropContainer components inside a single DragAndDrop component
  • Give each DragAndDropContainer a unique ID that matches the container key used in the data passed to the DragAndDrop component's items prop.
  • The DragAndDrop component's child works as a function that will provide the sorted items data.
  • You can use the unique container id to render the DragAndDropItems into each DragAndDropContainer.
Result
Loading...
Live Editor

Controlled state for Inputs inside DragAndDropItems

To use form inputs inside the DragAndDropItems you will need to:

  • Add your items data into state.
  • Pass the items state down to the DragAndDrop component's items prop.
  • Use the DragAndDrop component's onDragEnd prop to set the items back into state when items are sorted.
  • Update the item state using the input's onChange event which will cause a re-render with the new data.
Result
Loading...
Live Editor

Removable items

To be able to delete DragAndDropItems you will need to:

  • Add your items data into state.
  • Pass the items state down to the DragAndDrop component's items prop.
  • Use the DragAndDrop component's onDragEnd prop to set the items back into state when items are sorted.
  • When you custom delete button is clicked remove the item from state.
Result
Loading...
Live Editor

Props

DragAndDrop

DragAndDropContainer

DragAndDropItem