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

react-virtual-drag-list

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-virtual-drag-list

A virtual scrolling list component that can be sorted by dragging

  • 2.5.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-virtual-drag-list

npm npm Software License

A virtual scrolling list component that can be sorted by dragging

Live Demo

Simple Usage

npm i react-virtual-drag-list

Root component:

import VirtualList from 'react-virtual-drag-list'

function Virtual() {

  const list = [{id: '1', text: 'asd'}, {id: '2', text: 'fgh'}, ...]

  const handleToTop = () => {
    console.log('istop')
  }
  const handleToBottom = () => {
    console.log('isbottom')
  }
  const handleDragEnd = (params) => {
    console.log(params, 'new state after drag end')
  }

  // use style and className as jsx used
  return (
    <VirtualList
      className="virtual-list"
      style={{ height: '500px' }}
      dataKey="id"
      dataSource={ list }
      handle=".handle"
      header={ <div className="loading">top loading...</div> }
      footer={ <div className="loading">bottom loading...</div> }
      v-top={ handleToTop }
      v-bottom={ handleToBottom }
      v-drop={ handleDragEnd }
    >
      {
        (record, index, dataKey) => {
          return (
            <div>
              <span class=".handle">{ index }</span>
              { record.text }
            </div>
          )
        }
      }
    </VirtualList>
  )
}

Props

Callback

EmitTypeRequired?DefaultDescription
v-topFunction-Callback function that fires when scrolling to the top
v-bottomFunction-Callback function that fires when scrolling to the bottom
v-dragFunction-Callback function when drag is started
v-dropFunction-Callback function when drag is complete
v-addFunction-Callback function when element is dropped into the list from another
v-removeFunction-Callback function when element is removed from the list into another

Common used

PropTypeRequired?DefaultDescription
headerJSX.Element-Top of list
footerJSX.Element-Bottom of list
dataKeyString-The unique identifier of each piece of data, in the form of 'a.b.c'
dataSourceArray[]Data list
sizeNumber-Estimated height of each row
keepsNumber30The number of lines rendered by the virtual scroll
handleFunction/String-Drag handle selector within list items
groupObject/String-string: 'name' or object: { name: 'group', put: true/false, pull: true/false }
directionStringverticalvertical/horizontal, scroll direction
keepOffsetBooleanfalseWhen scrolling up to load data, keep the same offset as the previous scroll

Uncommonly used

PropTypeRequired?DefaultDescription
draggableFunction/String-Specifies which items inside the element should be draggable. If does not set a value, the default list element can be dragged
disabledBooleanfalseDisables the sortable if set to true
delayNumber10Delay time of debounce function
animationNumber150Drag-and-drop's animation delay
autoScrollBooleantrueAutomatic scrolling when moving to the edge of the container
scrollThresholdNumber55Threshold to trigger autoscroll
pressDelayNumber0Time in milliseconds to define when the sorting should start
pressDelayOnTouchOnlyBooleanfalseOnly delay on press if user is using touch
fallbackOnBodyBooleanfalseAppends the ghost element into the document's body
rootTagStringdivLabel type for root element
wrapTagStringdivLabel type for list wrap element
itemTagStringdivLabel type for list item element
headerTagStringdivLabel type for header slot element
footerTagStringdivLabel type for footer slot element
itemStyleObject{}Style for each line
itemClassString''Class for each line
wrapStyleObject{}List wrapper element style
wrapClassString''List wrapper element class
ghostStyleObject{}The style of the mask element when dragging
ghostClassString''The class of the mask element when dragging
chosenClassString''The class of the selected element when dragging

Methods

Use the methods exposed in the component by setting ref

...

const virtualRef = useRef()

const scrollToBottom = () => {
  virtualRef.current.scrollToBottom()
}

return (
  <button onClick={ scrollToBottom }></button>
  <virtualList
    ref={ virtualRef }
    ...
  >
    {
      (record) => <div>{ record.text }</div>
    }
  </virtualList>
)
PropDescription
reset()reset to initial
getSize(key)get the height of the specified item by key value
getOffset()get the current scroll height
scrollToTop()scroll to the top of the list
scrollToBottom()scroll to the bottom of the list
scrollToIndex(index)scroll to the specified index value
scrollToOffset(offset)scroll to the specified height

Keywords

FAQs

Package last updated on 03 Jun 2023

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