🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@dragndrop/vue-draggable

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dragndrop/vue-draggable

Draggable component for VueJS

0.0.4
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Draggable

Draggable component for VueJS 2+ which implements @dragndrop/draggable component.

Design & API Documentation

  • Demos

Installation

npm install @dragndrop/vue-draggable

Usage

Draggable element can be used for different functionalities - from moving elements around to make sortable list or draggable grid elements.

Typescript support

Component has its declarations (*.d.ts) for Typescript available.

Registration

import {VueDraggable} from '@dragndrop/vue-draggable';

Vue.component('VueDraggable', VueDraggable);

Registration as plugin

import Vue from 'vue';
import VueDraggable from '@dragndrop/vue-draggable';

Vue.use(VueDraggable);

Simple example

<template>
    <VueDraggable 
        :data="dataTransfer"
        :avatar="avatar"
        @onDrag="onDrag"
    >
        <div>Example element</div>
    </VueDraggable>
</template>
<script>
    export default {
        data() {
            return {
                dataTransfer: 'example data',
                avatar: new Avatar.clone(),
            }
        },
        methods: {
            onDrag(event) {
                console.log(event.dragInfo.data); // 'example data'
            }
        }
    }
</script>

CSS Classes (they can be changed)

CSS ClassDescription
draggable--draggingSets this class to element when dragging
draggable--occurringSets this class to body element when dragging

Shadow DOM

If you want to use dragndrop in Shadow DOM you need to add draggable--retarget attribute to your host element so events will be bubble through Shoadow DOM and recursive elementFromPoint() calls will work correctly.

Events

EventsTypeDataDescription
onDragStartCustomEvent{originalEvent, dragInfo, dropzoneElement}Event dispatched when dragging starts
onDragCustomEvent{originalEvent, dragInfo, dropzoneElement}Event dispatched when dragging
onDragEndCustomEvent{originalEvent, dragInfo, dropzoneElement}Event dispatched when dragging ends

DragInfo

DragInfoTypeDescription
draggableIdNumberId of draggable element
elementElementDraggable element
dataType GenericData attached to draggable with data property
startPositionPointStart position
avatarAvatarAvatar attached to draggable with avatar property
axisAxisAxis which dragging is handled 'horizontal', 'vertical' and 'both'
positionPointCurrent position of cursor
shiftPointDistance from start position to elements top-left corner

Props

PropertyValue TypeDescription
dataGeneric TypeData which is attached to draggable
draggableBooleanTurn on / off draggable functionality
avatarAvatarElement which is rendered when element is dragging
axisAxis ('both', 'horizontal', 'vertical')Axis the dragging is available for
handleStringSelector on which dragging is available (children of element are included)
cancelStringSelectors on which draggins is not available (children of element are included)
draggingClassStringClass which is set on element when dragging (draggable--dragging default)
draggingClassBodyStringClass which is set on body element when dragging (draggable--occurring default)
minDragStartDistancenumberMin distance to start dragStart state (4 default)
touchActionString or nullMakes touch-action property set on element when drag is started (undefined default)
customScroll((startPosition: Point, currentPosition: Point) => void) or booleanAllows to specify customScroll behavior with function or when set with false prevents from custom scroll which is set by default

Methods

Method SignatureDescription
abort() => voidAborts current dragging
destroy() => voidClean up method. Is used on beforeDestroy hook.

Keywords

vue draggable

FAQs

Package last updated on 16 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts