Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-sortable-hoc

> 前端框架
Open source

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

10.9K stars0 likes4 views
WebsiteGitHub

About

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

Warning

This library is no longer actively maintained. It will continue to receive critical security updates, but there are no new features planned. In future versions of React, the findDOMNode method will be deprecated. This method is a critical piece of the architecture of react-sortable-hoc, and the library will stop working in the future when that method is removed from react-dom.

All development efforts have been redirected towards @dnd-kit. It provides feature parity, built with a modern and extensible architecture, supports complex use-cases and has accessibility features built-in. New consumers are strongly encouraged to adopt @dnd-kit instead of adopting react-sortable-hoc.

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list

Examples available here: http://clauderic.github.io/react-sortable-hoc/

Features

  • Higher Order Components – Integrates with your existing components
  • Drag handle, auto-scrolling, locked axis, events, and more!
  • Suuuper smooth animations – Chasing the 60FPS dream
  • Works with virtualization libraries: react-virtualized, react-tiny-virtual-list, react-infinite, etc.
  • Horizontal lists, vertical lists, or a grid ↔ ↕ ⤡
  • Touch support
  • Accessible: supports keyboard sorting

Installation

Using npm:

$ npm install react-sortable-hoc --save

Then, using a module bundler that supports either CommonJS or ES2015 modules, such as webpack:

javascript
// Using an ES6 transpiler like Babel
import {SortableContainer, SortableElement} from 'react-sortable-hoc';

// Not using an ES6 transpiler
var Sortable = require('react-sortable-hoc');
var SortableContainer = Sortable.SortableContainer;
var SortableElement = Sortable.SortableElement;

Alternatively, an UMD build is also available:

xml
<script src="react-sortable-hoc/dist/react-sortable-hoc.umd.js"></script>

Usage

Basic Example

…

That's it! React Sortable does not come with any styles by default, since it's meant to enhance your existing components.

More code examples are available here.

Why should I use this?

There are already a number of great Drag & Drop libraries out there (for instance, react-dnd is fantastic). If those libraries fit your needs, you should definitely give them a try first. However, most of those libraries rely on the HTML5 Drag & Drop API, which has some severe limitations. For instance, things rapidly become tricky if you need to support touch devices, if you need to lock dragging to an axis, or want to animate the nodes as they're being sorted. React Sortable HOC aims to provide a simple set of higher-order components to fill those gaps. If you're looking for a dead-simple, mobile-friendly way to add sortable functionality to your lists, then you're in the right place.

Prop Types

SortableContainer HOC

Property Type Default Description
axis String y Items can be sorted horizontally, vertically or in a grid. Possible values: x, y or xy
lockAxis String If you'd like, you can lock movement to an axis while sorting. This is not something that is possible with HTML5 Drag & Drop. Possible values: x or y.
helperClass String You can provide a class you'd like to add to the sortable helper to add some styles to it
transitionDuration Number 300 The duration of the transition when elements shift positions. Set this to 0 if you'd like to disable transitions
keyboardSortingTransitionDuration Number transitionDuration The duration of the transition when the helper is shifted during keyboard sorting. Set this to 0 if you'd like to disable transitions for the keyboard sorting helper. Defaults to the value set for transitionDuration if undefined
keyCodes Array {
  lift: [32],
  drop: [32],
  cancel: [27],
  up: [38, 37],
  down: [40, 39]
}
An object containing an array of keycodes for each keyboard-accessible action.
pressDelay Number 0 If you'd like elements to only become sortable after being pressed for a certain time, change this property. A good sensible default value for mobile is 200. Cannot be used in conjunction with the distance prop.
pressThreshold Number 5 Number of pixels of movement to tolerate before ignoring a press event.
distance Number 0 If you'd like elements to only become sortable after being dragged a certain number of pixels. Cannot be used in conjunction with the pressDelay prop.
shouldCancelStart Function Function This function is invoked before sorting begins, and can be used to programatically cancel sorting before it begins. By default, it will cancel sorting if the event target is either an input, textarea, select, option, or button.

Issues· 289 open

View all issuesOpen on GitHub
  • #889

    No railguard for when element is null called in sortable

    Updated Apr 23, 2026
  • #887

    onClick not working

    Updated Aug 21, 2025
  • #877

    react 18.2.0 installing issue please update this package

    Updated Apr 7, 2025
  • #881

    Need to update for react 18^

    Updated Mar 6, 2025
  • #883

    Warning: findDOMNode is deprecated and will be removed in the next major release. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-find-node

    Updated Jan 22, 2025
  • #856

    not working on "react": "^18.2.0",

    Updated Jan 15, 2025
  • #885

    Incorrect type definition provided for nodes argument in onSortEnd prop

    Updated Jan 7, 2025
  • #647

    How to add event handlers to child components of SortableElement?

    Updated Dec 16, 2024
  • #882

    Is there a way to trigger the move from outside?

    Updated Oct 16, 2024
  • #388

    Cannot read property 'collection' of null

    Updated Sep 13, 2024

> Tags

JavaScriptdrag-and-dropdraggingfront-endgrid

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架