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

Commit b3fb1ba

Browse files
committed
Fix for the case that a drag is reverted, when the helper: 'clone' option is used.
1 parent 30757e3 commit b3fb1ba

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/sortable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ angular.module('ui.sortable', [])
151151
} else {
152152
// if the item was not moved, then restore the elements
153153
// so that the ngRepeat's comment are correct.
154-
if(!('dropindex' in ui.item.sortable) || ui.item.sortable.isCanceled()) {
154+
if((!('dropindex' in ui.item.sortable) || ui.item.sortable.isCanceled()) && element.sortable('option','helper') !== 'clone') {
155155
savedNodes.detach().appendTo(element);
156156
}
157157
}

test/sortable.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,47 @@ describe('uiSortable', function() {
374374
});
375375
});
376376

377+
it('should work when "helper: clone" option is used and a drag is reverted', function() {
378+
inject(function($compile, $rootScope) {
379+
var element;
380+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
381+
$rootScope.$apply(function() {
382+
$rootScope.opts = {
383+
helper: 'clone',
384+
};
385+
$rootScope.items = ['One', 'Two', 'Three'];
386+
});
387+
388+
host.append(element);
389+
390+
var li = element.find(':eq(0)');
391+
var dy = (2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
392+
li.simulate('dragAndRevert', { dy: dy });
393+
expect($rootScope.items).toEqual(['One', 'Two', 'Three']);
394+
expect($rootScope.items).toEqual(listContent(element));
395+
396+
li = element.find(':eq(0)');
397+
dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
398+
li.simulate('drag', { dy: dy });
399+
expect($rootScope.items).toEqual(['Two', 'One', 'Three']);
400+
expect($rootScope.items).toEqual(listContent(element));
401+
402+
li = element.find(':eq(1)');
403+
dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
404+
li.simulate('drag', { dy: dy });
405+
expect($rootScope.items).toEqual(['Two', 'Three', 'One']);
406+
expect($rootScope.items).toEqual(listContent(element));
407+
408+
li = element.find(':eq(1)');
409+
dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
410+
li.simulate('drag', { dy: dy });
411+
expect($rootScope.items).toEqual(['Two', 'One', 'Three']);
412+
expect($rootScope.items).toEqual(listContent(element));
413+
414+
$(element).remove();
415+
});
416+
});
417+
377418
});
378419

379420
describe('Multiple sortables related', function() {

0 commit comments

Comments
 (0)