diff --git a/src/Sortable.js b/src/Sortable.js index 72f571c82..99fdcb28a 100644 --- a/src/Sortable.js +++ b/src/Sortable.js @@ -1603,7 +1603,8 @@ Sortable.prototype = /** @lends Sortable.prototype */ { for (; i < n; i++) { el = children[i]; - if (closest(el, options.draggable, this.el, false)) { + // The fallback ghost is a clone of dragEl that may live inside the list (#2456) + if (el !== Sortable.ghost && closest(el, options.draggable, this.el, false)) { order.push(el.getAttribute(options.dataIdAttr) || _generateId(el)); } } diff --git a/tests/Sortable.test.js b/tests/Sortable.test.js index 59ce11f46..c0d3fa923 100644 --- a/tests/Sortable.test.js +++ b/tests/Sortable.test.js @@ -384,3 +384,18 @@ test('Do not insert into empty list if outside emptyInsertThreshold', async brow }) .expect(dragStartPosition.innerText).eql(dragEl.innerText); }); + + +fixture `Fallback` + .page `./fallback.html`; + +test('toArray does not include the fallback ghost', async browser => { + const dragEl = await list1.child(0)(); + const target = await list1.child(2)(); + + await browser + .dragToElement(dragEl, target) + .expect(list1.child(2).innerText).eql(dragEl.innerText) + .expect(browser.eval(() => window.orderOnStart)).eql(['a', 'b', 'c', 'd', 'e']) + .expect(browser.eval(() => window.orderOnEnd)).eql(['b', 'c', 'a', 'd', 'e']); +}); diff --git a/tests/fallback.html b/tests/fallback.html new file mode 100644 index 000000000..44fb8a281 --- /dev/null +++ b/tests/fallback.html @@ -0,0 +1,36 @@ + + + + + + + + +
+
Item 1.1
+
Item 1.2
+
Item 1.3
+
Item 1.4
+
Item 1.5
+
+ + + + + + + +