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 DragAndDropContainer
s you will need to:
- Set the
DragAndDrop
component'stype
prop to becanvas
. - Add two or more
DragAndDropContainer
components inside a singleDragAndDrop
component - Give each
DragAndDropContainer
a unique ID that matches the container key used in the data passed to theDragAndDrop
component'sitems
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
DragAndDropItem
s into eachDragAndDropContainer
.
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'sitems
prop. - Use the
DragAndDrop
component'sonDragEnd
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'sitems
prop. - Use the
DragAndDrop
component'sonDragEnd
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
Name | Type | Default Value | Required | Description |
---|---|---|---|---|
announcements | Announcements | No | ||
autoScroll | boolean | Options | No | ||
cancelDrop | CancelDrop | No | ||
collisionDetection | CollisionDetection | No | ||
handlePosition | "center" | "top" | "bottom" | center | No | Set where the drag handle is positioned relative to the height of the <a href="/#/Components/DragAndDropItem">DragAndDropItem</a>. |
id | string | No | ||
items | ItemsFromProps | Yes | An 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 ``` | |
measuring | MeasuringConfiguration | No | ||
modifiers | Modifiers | No | ||
onDragCancel | (event: DragCancelEvent) => void | No | ||
onDragEnd | (event: DragEndEvent, payload: ItemsFromProps) => void | () => {} | No | Called 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) => void | No | ||
onDragOver | (event: DragOverEvent) => void | No | ||
onDragStart | (event: DragStartEvent) => void | No | ||
overlayComponent | React.ElementType | No | ||
screenReaderInstructions | ScreenReaderInstructions | No | ||
sensors | SensorDescriptor<any>[] | No | ||
theme | "default" | "border" | "borderless" | default | No | `default` - No border around each DragAndDropItem. `border` - Display border around each DragAndDropItem. `borderless` - No border, focus, or hover styles. |
type | "canvas" | "list" | "column" | list | No | `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
Name | Type | Default Value | Required | Description |
---|---|---|---|---|
key | Key | No | ||
ref | Ref<unknown> | No |
DragAndDropItem
Name | Type | Default Value | Required | Description |
---|---|---|---|---|
disabled | boolean | No | ||
handlePosition | "center" | "top" | "bottom" | No | Set where the drag handle is positioned relative to the height of the item. | |
id | string | Yes | ||
renderIcon | () => Element | No |