Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List (Sortable) - Fix item dragging to the top position when allowReordering is false (T856292) #11729

Merged
merged 2 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion js/ui/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ const Sortable = Draggable.inherit({
},

_isValidPoint: function(visibleIndex, draggableVisibleIndex, dropInsideItem) {
const allowDropInsideItem = this.option('allowDropInsideItem');
const allowReordering = dropInsideItem || this._allowReordering();

if(!allowReordering && visibleIndex !== 0) {
if(!allowReordering && (visibleIndex !== 0 || !allowDropInsideItem)) {
return false;
}

Expand Down
23 changes: 23 additions & 0 deletions testing/tests/DevExpress.ui.widgets/listParts/editingUITests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2926,3 +2926,26 @@ QUnit.test('items should reset positions after dragend', function(assert) {
});
});

// T856292
QUnit.test('Drag and drop item to the top of the list should not work when allowReordering is false', function(assert) {
const $list = $('#list').dxList({
items: ['0', '1', '2'],
itemDragging: {
allowReordering: false,
group: 'shared'
}
});

let $items = $list.find(toSelector(LIST_ITEM_CLASS));
const $item3 = $items.eq(2);
const pointer = reorderingPointerMock($item3, this.clock);

pointer.dragStart(0.5).drag(-1).drag(-1.5).dragEnd();

$items = $list.find(toSelector(LIST_ITEM_CLASS));
$.each($items, (index, item) => {
const $item = $(item);

assert.equal($item.text(), index, 'item text');
});
});
18 changes: 18 additions & 0 deletions testing/tests/DevExpress.ui.widgets/sortable.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,24 @@ QUnit.test('option changing', function(assert) {
assert.strictEqual(this.$element.children().first().text(), 'item1', 'first item is not changed');
});

QUnit.test('Move to top if allowReordering is false', function(assert) {
// arrange
const onDragChangeSpy = sinon.spy();

this.createSortable({
allowReordering: false,
dropFeedbackMode: 'indicate',
onDragChange: onDragChangeSpy
});

// act
pointerMock(this.$element.children().eq(1)).start().down(15, 45).move(0, -45);

// assert
assert.strictEqual(onDragChangeSpy.callCount, 0, 'onDragChange event is not called');
assert.strictEqual($('.dx-sortable-placeholder').length, 0, 'placeholder does not exist');
});


QUnit.module('placeholder and source', moduleConfig);

Expand Down