New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-virtual-sortable

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-virtual-sortable

A virtual scrolling list component that can be sorted by dragging

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

react-virtual-sortable

npm npm Software License

A virtual scrolling list component that can be sorted by dragging

Live Demo

Simple Usage

npm i react-virtual-sortable

Root component:

import VirtualList from 'react-virtual-sortable';

function Virtual() {

  const [list, setList] = useState([{id: '1', text: 'a'}, {id: '2', text: 'b'}, ...]);

  const onDrop = (event) => {
    // dnd complete
    setList(() => event.list);
  }

  // use style and className as jsx used
  return (
    <VirtualList
      dataKey="id"
      dataSource={ list }
      handle=".handle"
      onDrop={ onDrop }
      className="virtual-list"
      style={{ height: '500px' }}
    >
      {
        (record, index, dataKey) => {
          return (
            <div>
              <span className=".handle">{ index }</span>
              { record.text }
            </div>
          )
        }
      }
    </VirtualList>
  )
}

Props

Callback

EmitTypeDescription
onTopFunctionScrolling to the top of the scroller
onBottomFunctionScrolling to the bottom of the scroller
onDragFunctionDrag is started
onDropFunctionDrag is complete
onRangeChangeFunctionRange of visible items has changed

Required props

PropTypeDefaultDescription
dataKeyString-The unique identifier of each piece of data, in the form of 'a.b.c'
dataSourceArray[]The data that needs to be rendered

Common used

PropTypeDefaultDescription
headerJSX.Element-Top of list
footerJSX.Element-Bottom of list
sizeNumber-Estimated height of each row. it will be automatically calculated
keepsNumber30The number of lines rendered by the virtual scroll
handleString-Drag handle selector within list items
groupObject/String-string: 'name' or object: { name: 'group', put: true/false, pull: true/false/'clone', revertDrag: true/false }
scrollerDocument | HTMLElement-Virtual list scrolling element
directionvertical | horizontalverticalScroll direction
debounceTimeNumber0debounce time on scroll
throttleTimeNumber0debounce time on scroll
tableModeBooleanfalsedisplay with table and tbody

Uncommonly used

PropTypeDefaultDescription
bufferNumberMath.round(keeps / 3)Buffer size to detect range change
draggableString[role="item"]Specifies which items inside the element should be draggable
sortableBooleantrueWhether the current list can be sorted by dragging
lockAxisx | y-Axis on which dragging will be locked
keepOffsetBooleanfalseWhen scrolling up to load data, keep the same offset as the previous scroll
disabledBooleanfalseDisables the sortable if set to true
animationNumber150Drag-and-drop's animation delay
autoScrollBooleantrueAutomatic scrolling when moving to the edge of the container
scrollSpeedObject{ x: 10, y: 10 }Vertical&Horizontal scrolling speed (px)
scrollThresholdNumber55Threshold to trigger autoscroll
delayNumber0Time in milliseconds to define when the sorting should start
delayOnTouchOnlyBooleanfalseOnly delay on press if user is using touch
appendToBodyBooleanfalseAppends the ghost element into the document's body
dropOnAnimationEndBooleantrueDrop item on animation end
rootTagStringdivLabel type for root element
wrapTagStringdivLabel type for list wrap element
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''Class name for the chosen item
placeholderClassString''Class name for the drop placeholder

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>
)
MethodDescription
getSize(key)get the height of the specified item by key value
getOffset()get the current scroll top/left
getClientSize()Get wrapper element client viewport size (width or height)
getScrollSize()Get all scroll size (scrollHeight or scrollWidth)
scrollToTop()scroll to the top of the list
scrollToBottom()scroll to the bottom of the list
scrollToKey(key, align)scroll to the specified data-key
scrollToIndex(index, align)scroll to the specified index value
scrollToOffset(offset)scroll to the specified height

Keywords

sort

FAQs

Package last updated on 06 Feb 2026

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