Skip to content
This repository was archived by the owner on Jan 28, 2020. It is now read-only.

Commit d8077dc

Browse files
committed
Draggable: Ensure parent is correct after dragging through sortable
Fixes #10669
1 parent 4e860dc commit d8077dc

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

tests/unit/draggable/draggable_options.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,29 @@ test( "connectToSortable, dragging through one sortable to a second", function()
405405
element.simulate( "drag", dragParams );
406406
});
407407

408+
test( "connectToSortable, dragging through a sortable", function() {
409+
expect( 1 );
410+
411+
var draggable = $( "#draggableSortable" ).draggable({
412+
scroll: false,
413+
connectToSortable: "#sortable2"
414+
}),
415+
sortable = $( "#sortable2" ).sortable(),
416+
sortableOffset = sortable.offset();
417+
418+
// http://bugs.jqueryui.com/ticket/10669
419+
// Draggable: Position issue with connectToSortable
420+
draggable.one( "dragstop", function() {
421+
equal( draggable.parent().attr( "id" ), "sortable", "restored draggable to original parent" );
422+
});
423+
424+
draggable.simulate( "drag", {
425+
x: sortableOffset.left + 25,
426+
y: sortableOffset.top + sortable.outerHeight() + 400,
427+
moves: 20
428+
});
429+
});
430+
408431
test( "{ containment: Element }", function() {
409432
expect( 1 );
410433

ui/draggable.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,9 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
800800
if ( !sortable.isOver ) {
801801
sortable.isOver = 1;
802802

803+
// Store draggable's parent in case we need to reappend to it later.
804+
draggable._parent = ui.helper.parent();
805+
803806
sortable.currentItem = ui.helper
804807
.appendTo( sortable.element )
805808
.data( "ui-sortable-item", true );
@@ -876,8 +879,9 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
876879
sortable.placeholder.remove();
877880
}
878881

879-
// Recalculate the draggable's offset considering the sortable
880-
// may have modified them in unexpected ways (#8809)
882+
// Restore and recalculate the draggable's offset considering the sortable
883+
// may have modified them in unexpected ways. (#8809, #10669)
884+
ui.helper.appendTo( draggable._parent );
881885
draggable._refreshOffsets( event );
882886
ui.position = draggable._generatePosition( event, true );
883887

0 commit comments

Comments
 (0)