Add make_sortable() for drag-and-drop sorting on container elements#5855
Add make_sortable() for drag-and-drop sorting on container elements#5855falkoschindler wants to merge 10 commits intomainfrom
make_sortable() for drag-and-drop sorting on container elements#5855Conversation
Use cursor-grab/cursor-grabbing instead of cursor-pointer in demos, document custom HTML ID limitation and options override behavior, add cross-container on_end note, and sync test comment with JS source. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
There are still two review comments from Claude I need to look into. Apart from that the PR is complete. Should be good for early 3.11.
|
Motivation
Feature request: #932
Supersedes PRs #4656 and #5464
Users have long requested built-in drag-and-drop sorting support. PR #4656 introduced SortableJS as a dedicated
ui.sortableelement, and #5464 was another experiment along the same lines. After extensive discussion in #932, we concluded that "sortable" is a feature, not an element — aui.columnthat can be reordered is still a column.This PR implements that conclusion: a
.make_sortable()method on container elements (ui.column,ui.row,ui.card,ui.grid,ui.list,ui.expansion,ui.scroll_area). It wraps SortableJS and keeps the server-side element tree in sync automatically. The container keeps its original type — aui.columnstays aui.column.Implementation
SortableElementmixin addsmake_sortable()to container elements, returning aSortablecontroller withenable(),disable(),, and read/write properties (destroy()animation,handle,group,ghost_class).Anoptionsproperty (backed byObservableDict) auto-pushes changes to the client, following the same pattern as AG Grid.Sortablecontrollerinitializes SortableJS on the client, syncs the client-side element tree on drop (preventing snap-back), and fires ais a hidden Vue component (sortendevent with element references (item,source,target) and indices.Elementsubclass) that manages SortableJS via a.jscomponent file. Options are synced reactively through props. The JS-sideonEndcallback syncs the client-side element tree (preventing snap-back) and dispatches asortendCustomEvent on the container element with element references (item,source,target) and indices.SortableEventArgumentsdataclass provides typed event args.destroying the container element automatically destroys the sortable.Vue'sunmounted()lifecycle hook automatically destroys the SortableJS instance — no manual cleanup needed.make_sortable()twice raisesRuntimeError.Progress