Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sortable-dnd

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sortable-dnd

JS library for drag-and-drop lists, supports sortable and draggable

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Downloads Version

A JS Library for Drag and Drop, supports Sortable and Draggable

Demo

Usage

HTML

<ul id="group">
  <li>
    <i class="drag">drag me</i>
    <p>1</p>
  </li>
  <li>
    <i class="drag">drag me</i>
    <p>2</p>
  </li>
  <li>
    <i class="drag">drag me</i>
    <p>3</p>
  </li>
</ul>

JavaScript

import Sortable from 'sortable-dnd'

var DND = new Sortable(
  document.getElementById('group'),
  {
    chosenClass: 'chosen',
    draggable: (e) => e.target.tagName === 'I' ? true : false, // use function
    // draggable: 'i' // use tagName 
    // draggable: '.drag' // use class
    // draggable: '#drag' // use id
    // draggable: (e) => e.target.parentNode // use fundtion to set drag Element
    onDrag: ({ dragEl, event, originalEvent }) => {
      // code
    },
    onMove: ({ from, ghostEl, event, originalEvent }) => {
      // code
    },
    onDrop: ({ changed, event, originalEvent }) => {
      // code
    },
    onChange: ({ from, to, event, originalEvent }) => {
      // code
    }
  }
)

Methods

MethodDescription
destroy()Manually clear all the state of the component, using this method the component will not be draggable

Options

Common used

OptionTypeDefaultDescription
draggableString/FunctionundefinedSpecifies which items inside the element should be draggable
groupString/Object-string: 'name' or object: { name: 'group', put: true/false, pull: true/false }
onDragFunctionundefinedThe callback function when the drag is started
onMoveFunctionundefinedThe callback function when the dragged element is moving
onDropFunctionundefinedThe callback function when the drag is completed
onChangeFunctionundefinedThe callback function when the dragged element changes position
animationNumber150Animation speed moving items when sorting
disabledBooleanfalseDisables the sortable if set to true

Others

OptionTypeDefaultDescription
autoScrollBooleantrueAutomatic scrolling when moving to the edge of the container, for browsers that do not support HTML5 drag events
scrollStepNumber5The distance to scroll each frame when autoscrolling
scrollThresholdNumber15Threshold to trigger autoscroll
delayNumber0time in milliseconds to define when the sorting should start
delayOnTouchOnlyBooleanfalseonly delay if user is using touch
chosenClassString{}The class of the selected element when dragging
ghostStyleObject{}The style of the mask element when dragging
ghostClassString''The class of the mask element when dragging
forceFallbackBooleanfalsetrue: ignore the HTML5 DnD behaviour and force the fallback to kick in
stopPropagationBooleanfalseThe stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases

LICENSE

MIT

Keywords

FAQs

Package last updated on 03 Aug 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc