Socket
Socket
Sign inDemoInstall

sortable-dnd-lock-axis-fork

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sortable-dnd-lock-axis-fork

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


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

npm npm Software License

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

Live Demo

Usage

HTML

<ul id="group">
  <li class="item">
    <i id="handle" class="handle">drag me</i>
    <p>1</p>
  </li>
  <li class="item">
    <i id="handle" class="handle">drag me</i>
    <p>2</p>
  </li>
  <li class="item">
    <i id="handle" class="handle">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 === 'LI' ? true : false, // use function
    // draggable: 'li' // use tagName 
    // draggable: '.item' // use class
    // draggable: '#item' // use id
    // draggable: (e) => e.target // use function to set drag Element
    handle: (e) => e.target.tagName === 'I' ? true : false, // use function
    // handle: 'I', // use tagName
    // handle: '.handle', // use class
    // handle: '#handle', // use id
    onDrag: ({ from, event }) => {
      // code
    },
    onMove: ({ from, event }) => {
      // code
    },
    onDrop: ({ from, to, changed, event }) => {
      // code
    },
    onAdd: ({ from, to, event }) => {
      // code
    },
    onRemove: ({ from, to, event }) => {
      // code
    },
    onChange: ({ from, to, event }) => {
      // code
    },
    onSelect: (params) => {
      // code
    },
    onDeselect: (params) => {
      // code
    }
  }
)

Methods

MethodDescription
destroy()Manually clear all the state of the component, using this method the component will not be draggable
option(key, value?)Get or set the option value, depending on whether the value is passed in

Options

Common used

OptionTypeDefaultDescription
draggableString/Function-Specifies which items inside the element should be draggable
handleString/Funnction-Drag handle selector within list items
groupString/Object-string: 'name' or object: { name: 'group', put: true/false, pull: true/false }
multipleBooleanfalseEnable multiple drag
animationNumber150Animation speed moving items when sorting
onDragFunction-The callback function when the drag is started
onMoveFunction-The callback function when the dragged element is moving
onDropFunction-The callback function when the drag is completed
onAddFunction-The callback function when element is dropped into the list from another list
onRemoveFunction-The callback function when element is removed from the list into another list
onChangeFunction-The callback function when the dragged element changes position in the list
onSelectFunction-The callback function when element is selected
onDeselectFunction-The callback function when element is unselected

Others

OptionTypeDefaultDescription
disabledBooleanfalseDisables the sortable if set to true
chosenClassString''Class name for the dragging item
selectedClassString''The class of the element when it is selected, it is usually used when multiple drag
ghostStyleObject{}The style of the mask element when dragging
ghostClassString''The class of the mask element when dragging
autoScrollBooleantrueAutomatic scrolling when moving to the edge of the container
scrollThresholdNumber55Threshold to trigger autoscroll
delayNumber0Time in milliseconds to define when the sorting should start
delayOnTouchOnlyBooleanfalseOnly delay if user is using touch
fallbackOnBodyBooleanfalseAppends the cloned DOM Element into the Document's Body
stopPropagationBooleanfalseThe stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases
swapOnDropBooleantrueWhen the value is false, the dragged element will return to the starting position of the drag

Keywords

FAQs

Last updated on 19 Oct 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc