Skip to content
On this page

Drag

The drag component is meant to define an area from which data can be exported.

Events

Event NameDescription
@dragstartTriggered when a drag operation starts
@dragendTriggered when a drag operation terminates (whether successfully or not)
@cut / @copyTriggered when a drag operation completes successfully on a Drop component that requires the data to be removed / copied (event name is dependant on the selected drop mode prop)

Props

Prop NameType / DefaultDescription
tagAnyThis prop can be used to customize the root of the template, Can refer to a custom Vue component, including its props, slots and listeners.
typeString (null)Refer to Types section below
dataAnyAny data associated with this drag which will be sent with the emit event
drag-image-opacityNumber (0.7)0-1 defining the opacity of the drag image
disabledBoolean (false)Whether to temporarily disable dragging this component
go-backBoolean (false)If a drag is not successful, the drag image will animate back to where the drag originated (demo below)
handleString (undefined)A handle / grabber for this Drag component (eg: .drag-handle)
deltaNumber (3px)A pixel-distance which defines whether a drag has begun
delayNumber (0ms)The number of milliseconds of which the user must hold down the Drag element until it is recognised as a drag (useful for allowing scrolling on Touch devices without it automatically trying to drag the element) (0 = no delay)
drag-classString (null)A class to bind to the image / ghost being dragged around
vibrationNumber (0ms)Vibration feedback on supported mobile devices when a Drag event has started (0 = no feedback)
scrolling-edge-sizeNumber (100px)When dragging this element to the edge of its bounding container/list, the pixel amount defines how close to the edge of the container it will automatically scroll up/down/left/right (0 = no scrolling on its bounding container)

Slots

Slot NameDescription
defaultDefault content to add at the end of the DropList. Make sure to define a key prop for each element directly inside this slot.
drag-imageRefer to Drag Image section below

Demo

An example of go-back prop

https://codesandbox.io/s/example-1-l6p54

demo

CSS classes

Depending on the mode of the Drop component currently under the mouse cursor, the source Drag component is assigned the classes drag-mode-copy, drag-mode-cut and drag-mode-reordering.

If a drag is in progress, dnd-ghost will be bound to the ghost. The Drag component can also optionally accept an additional class (drag-class prop) to bind to the ghost. When using a DropList, the dnd-ghost class and drag-class prop will both NOT be bound if the drag-image slot is defined.

To prevent dragging your Draggable component from a child element, you may attach the class dnd-no-drag to the child. That way the entire element remains draggable, whereas specific sub-children can have dragging from themselves disabled.

Types

A drag operation may have a type. The type is a data structure (can be a simple string) that defines the kind of data being transfered. The type of a drag operation is defined by the Drag component that initiates it using the type prop.

A Drop component is said to participate in a drag operation if it accepts its type (the default is to accept any type). The type(s) a Drop component accepts can be defined by mean of the accepts-type prop (can be a string, an array of strings or a function that takes the type as parameter and returns a boolean).

The following demo illustrates the use of types. There are two types in use : 'string' and 'number'. The Drag components that contain '1' and '2' are of type 'number', the ones containing 'a' and 'b' are of type 'string'. The two Drop components on the left accept numbers, the ones on the right accept strings. When you drag a number/string (respectively), only Drop components that accept numbers/strings (respectively) react (i.e. drag images, CSS classes, cursors are applied). The other ones are left alone.

https://codesandbox.io/s/example-3-g7io8

demo

Drag image

During the drag, an image may move along the mouse cursor. Easy-DnD makes it so that this image is always on top of everything else.

Drag components provide the drag-image slot that can be used to set the default image displayed during the drag operation :

  • if the slot isn't defined, the image is a clone of the Drag component.
  • if the slot is defined and empty, there is no image.
  • if the slot is not empty, a clone of its content is used.

Drop and DropList components provide the drag-image slot (props : data and type) that can be used to set the image to be displayed when the mouse is over them, if they participates in the current drag operation (i.e. accept its type) :

  • if the slot isn't defined, the default image set by the Drag component is used.
  • if the slot is defined and empty, there is no image.
  • if the slot is not empty, a clone of its content is used.

DropList components additionaly provide the reordering-drag-image slot (prop : item subject to reordering) that behaves the same way as drag-image but controls the drag image to be displayed during list reordering.

The position of the drag image relative to the mouse cursor can be controlled by CSS using the transform property.

The following demo illustrate the use of custom drag images, nested Drop components and a mask :

https://codesandbox.io/s/example-4-6h8zy

demo