Skip to main content

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

SortableInput
required
Configuration for the sortable item
DragDropManager
required
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: