Skip to main content

DragAndDrop

Result
Item 1
Item 2
With Other Content
Item 3
With Other Content
With Other Content
Item 4
With Other Content
With Other Content
With Other Content
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
Item 1
Item 2
Item 3
Item 4
Live Editor

Theme

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

Result
Item 1
Item 2
Item 3
Item 4
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

Container A

Item 1 a
Item 2 a
Item 3 a

Container B

Place an item here

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
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
Item 1
Item 2
Item 3
Item 4
Live Editor

Props

DragAndDrop

NameTypeDefault ValueRequiredDescription
announcementsAnnouncementsNo
autoScrollboolean | OptionsNo
cancelDropCancelDropNo
collisionDetectionCollisionDetectionNo
handlePosition"center" | "top" | "bottom"centerNoSet where the drag handle is positioned relative to the height of the <a href="/#/Components/DragAndDropItem">DragAndDropItem</a>.
idstringNo
itemsItemsFromPropsYesAn object where the key matches the `id` of a child <a href="/#/Components/DragAndDropContainer">DragAndDropContainer</a> and the value is an array of objects representing the <a href="/#/Components/DragAndDropItem">DragAndDropItem</a>s inside that container. Each object in the array has a unique `id` key/value pair and and additional `props` key/value pair for storing data for that <a href="/#/Components/DragAndDropItem">DragAndDropItem</a>. ``` 'drag-and-drop-container-id': [ { 'id': 1, 'props': { // ...data for this item } }, // ...additional items ], //..additional containers ```
measuringMeasuringConfigurationNo
modifiersModifiersNo
onDragCancel(event: DragCancelEvent) => voidNo
onDragEnd(event: DragEndEvent, payload: ItemsFromProps) => void() => {}NoCalled when an <a href="/#/Components/DragAndDropItem">DragAndDropItem</a> is sorted. Returns an array of the item IDs in the new sorted order.
onDragMove(event: DragMoveEvent) => voidNo
onDragOver(event: DragOverEvent) => voidNo
onDragStart(event: DragStartEvent) => voidNo
overlayComponentReact.ElementTypeNo
screenReaderInstructionsScreenReaderInstructionsNo
sensorsSensorDescriptor<any>[]No
theme"default" | "border" | "borderless"defaultNo`default` - No border around each DragAndDropItem. `border` - Display border around each DragAndDropItem. `borderless` - No border, focus, or hover styles.
type"canvas" | "list" | "column"listNo`list` - <a href="/#/Components/DragAndDropItem">DragAndDropItem</a> can only be sorted vertically within a single DragAndDrop component. `canvas` - <a href="/#/Components/DragAndDropItem">DragAndDropItem</a> can be moved between <a href="/#/Components/DragAndDropContainer">DragAndDropContainer</a> components. `column` - <a href="/#/Components/DragAndDropItem">DragAndDropItems</a> will have their drag behavior locked to the horizontal axis.

DragAndDropContainer

NameTypeDefault ValueRequiredDescription
keyKeyNo
refRef<unknown>No

DragAndDropItem

NameTypeDefault ValueRequiredDescription
disabledbooleanNo
handlePosition"center" | "top" | "bottom"NoSet where the drag handle is positioned relative to the height of the item.
idstringYes
renderIcon() => ElementNo