Usage
ThecreateSortable primitive combines draggable and droppable behavior with sorting logic. Import it from @dnd-kit/svelte/sortable.
When using
createSortable inside an {#each} block, pass reactive values like index as getter properties (e.g. get index() { return index; }) to maintain reactivity as items are reordered. Visual sorting during drag is driven by calling move() in onDragOver. The onDragEnd handler only needs to restore the snapshot when the drag is canceled.Without the move helper
The example above uses themove helper from @dnd-kit/helpers, a convenience function that takes your items and a drag event and returns a new array with the item moved to its new position. It supports flat arrays and grouped records, handles canceled drags, and works with multiple lists.
If you need more control over state updates, you can manage state manually using the isSortable type guard and the sortable properties (initialIndex, index).
Call move() in onDragOver for live visual sorting, and restore the snapshot in onDragEnd only when the drag is canceled:
Learn more about type guards and manual state management in the Sortable concepts page.
Input
All input properties accept plain values or getter functions for reactivity.A unique identifier for this sortable instance.
The current index of this item in the sorted list.
The group this sortable belongs to. Used for sorting across multiple lists.
The types of draggable elements this sortable accepts.
The type of this sortable element.
An array of plugin descriptors for per-entity plugin configuration. Use
Plugin.configure() to create descriptors. For example, Feedback.configure({ feedback: 'clone' }).Animation transition configuration for sort operations.
Modifiers to apply to this sortable instance.
Sensors to use for this sortable instance.
A custom collision detection algorithm.
The collision priority of this sortable element. Higher values take precedence when multiple droppable elements overlap.
Whether the sortable is disabled.
Custom data to attach to this sortable instance.
Output
Whether this element is currently being dragged.
Whether this element is in the process of being dropped.
Whether this element is the source of the current drag operation.
Whether this element is currently a drop target.
The underlying
Sortable instance.Attachment function for the sortable element. Use with
{@attach}.Attachment function for a drag handle. Use with
{@attach}.Attachment function for the drag source element (when different from the sortable element).
Attachment function for the drop target element (when different from the sortable element).