Draggable

Default


The Draggable kit gives you a full subcomponent structure that allows it to be used with almost any kits.

DraggableProvider = This provider manages all settings that allows drag and drop to function and must be used as the outermost wrapper. It has 2 REQUIRED props: initialItems (initial data) and onReorder (function that returns mutated data as items are reordered via drag and drop). Devs must manage state as shown.

Draggable.Container = This specifies the container within which items can be dropped.
Draggable.Item = This specifies the items that can be dragged and dropped. dragId is a REQUIRED prop for Draggable.Item.

Draggable with List Kit


For a simplified version of the Draggable API for the List kit, you can do the following:

Use DraggableProvider and manage state as shown.

The List kit is optimized to work with the draggable kit. To enable drag, use the enableDrag prop on List kit AND dragId prop on ListItem. An additional optional boolean prop (set to true by default) of dragHandle is also available on List kit to show the drag handle icon.

Draggable with SelectableList Kit


For a simplified version of the Draggable API for the SelectableList kit, you can do the following:

Use DraggableProvider and manage state as shown.

The SelectableList kit is optimized to work with the draggable kit. To enable drag, use the enableDrag prop on SelectableList kit AND dragId prop on SelectableList.Item. An additional optional boolean prop (set to true by default) of dragHandle is also available on SelectableList kit to show the drag handle icon.

Draggable with Cards


For a simplified version of the Draggable API for the Card kit, you can do the following:

Use DraggableProvider and manage state as shown.

Draggable.Container creates the container within which the cards can be dragged and dropped.

The Card kit is optimized to work with the draggable kit. To enable drag, use the draggableItem and dragId props on the Card kit as shown. An additional optional boolean prop (set to true by default) of dragHandle is also available to show the drag handle icon.

Draggable with Table


The draggable kit can also be used in conjunction with the table kit to create draggable table rows. To do this:

  • Wrap the Table with the DraggableProvider and manage state as shown.
  • use the draggableContainer prop on the Table.Body to designate it as the Draggable Container
  • use the draggableItem prop on the Table.Row to designate it as the Draggable Item. Make sure to also pass id to the dragId prop here.

We recommending using the default dropZone type with the Table kit.

Dragging Across Multiple Containers


The Draggable kit can also be used to achieve more complex, multiple container functionality as shown here. This complex usage requires the full subcomponent structure.

Draggable Drop Zones


The Draggable kit lets you customize the style of drop zones that appear when dragging an item.

By default, drop zones are in the "ghost" style, but you can also choose from "shadow," "outline," and "line."

When using the "line" type, make sure to set the appropriate direction attribute within the dropZone prop based on the orientation of your draggable view. By default, this is set to "vertical," but it can also be adjusted to "horizontal." Note that the direction attribute only applies to the "line" type and does not affect other drop zone styles. For more on the "line" style in particular, check out the Draggable Drop Zones Line doc example.

Draggable Drop Zones Colors


The default color for Draggable kit drop zones is "neutral", with "primary" or "purple" as additional options. When type is set to "line", the default color is "primary" and "purple" is the only other option.

Draggable Drop Zones Line


When using the "line" style, make sure to set the appropriate direction attribute within the dropZone prop based on the orientation of your draggable view. By default, this is set to "vertical," but it can also be adjusted to "horizontal." Note that the direction attribute only applies to the "line" style and does not affect other drop zone styles. The default color for "line" is "primary" and "purple" is the only alternative color option.

The length of the line is calculated based off of the width (for "vertical") or height (for "horizontal") of the parent container holding the draggable items.

Additionally, if the parent container of the DraggableProvider/DraggableContainer (or a subcontainer within) does not have a set height (for "vertical") or width (for "horizontal"), like the Draggable Drop Zones doc example does, elements on the page may jump up (for "vertical") or to the left (for "horizontal") when an item is actively being dragged. To prevent this, give a parent element a fixed height (for "vertical") or width (for "horizontal") as demonstrated in this doc example.


Available Props