From 3eb35640f095a716782fa5e4f476e1b3a73c3751 Mon Sep 17 00:00:00 2001 From: code4fan Date: Mon, 23 Aug 2021 23:14:14 +0800 Subject: [PATCH] fix the drag position problem when existing non draggable elements at the end of the list When dragging an element to the end of the list, and existing non draggable elements at the end of the list. Appending it to the end of the list is not incorrect, It should be inserted before the next sibling of the last draggable element. --- src/Sortable.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Sortable.js b/src/Sortable.js index d66b8e7f6..431679173 100644 --- a/src/Sortable.js +++ b/src/Sortable.js @@ -1188,7 +1188,12 @@ Sortable.prototype = /** @lends Sortable.prototype */ { if (onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, !!target) !== false) { capture(); - el.appendChild(dragEl); + if (elLastChild && elLastChild.nextSibling) { // the last draggable element is not the last node + el.insertBefore(dragEl, elLastChild.nextSibling); + } + else { + el.appendChild(dragEl); + } parentEl = el; // actualization changed();