Overview
The Sortable class combines Draggable and Droppable functionality to create sortable lists, grids, and other reorderable collections. It handles index tracking, smooth transitions, and optimistic updates automatically.
Installation
Constructor
Parameters
Configuration for the sortable item Unique identifier for this sortable item
Current index within the sortable group
The DOM element to make sortable
Group identifier for multi-list sorting. Items in the same group can be sorted together. Items without a group can only sort within their own list.
The element to use as the droppable target. By default, uses the same element. Useful for drop zones that differ from the visual element.
transition SortableTransition | null
Transition configuration for position changes. Set to null to disable transitions. Plugins specific to this sortable item. Default includes SortableKeyboardPlugin and OptimisticSortingPlugin.
Custom data attached to this sortable
Drag handle element. If not provided, the entire element is draggable.
Whether this sortable is disabled
Type identifier for filtering drag-drop interactions
accept Type | Type[] | (draggable) => boolean
Types this sortable accepts as drop targets. Override sensors for this sortable
Position modifiers for this sortable
Custom collision detection algorithm
Priority for collision resolution. Higher values win.
The DragDropManager instance
Properties
index
Current index within the sortable group. Updating this triggers a transition animation.
initialIndex
The index when the current drag operation started. Read-only.
group
Group identifier. Items in the same group can be sorted together.
initialGroup
The group when the current drag operation started. Read-only.
element
The sortable’s DOM element.
target
The droppable target element. Defaults to element.
isDragSource
Whether this sortable is the source of the current drag. Read-only.
isDragging
Whether this sortable is currently being dragged. Read-only.
isDropTarget
Whether something is being dragged over this sortable. Read-only.
disabled
Disable both dragging and dropping for this sortable.
Methods
register()
Register the sortable with the manager. Returns a function to unregister.
unregister()
Unregister the sortable from the manager.
destroy()
Destroy the sortable and clean up resources.
refreshShape()
Refresh the sortable’s bounding rectangle. Useful after layout changes.
Default Transition
Basic Example
Multi-List Example
Grid Example
Custom Transitions
Built-in Plugins
Sortable includes two plugins by default:
SortableKeyboardPlugin
Enhances keyboard navigation for sortable lists:
Up/Down arrow keys move between items
Automatically reorders on arrow key press
Works with screen readers
OptimisticSortingPlugin
Provides optimistic updates during dragging:
Items animate to their new positions before drop
Smooth reordering as you drag over items
Automatically reverts if drag is canceled
Type Definitions
Additional Exports
SortableDraggable
A specialized Draggable class optimized for sortable items:
SortableDroppable
A specialized Droppable class optimized for sortable drop targets:
defaultSortableTransition
The default transition configuration for sortable items:
Utility Functions
isSortable
Type guard to check if an entity is a sortable:
isSortableOperation
Type guard to check if a drag operation involves sortables: