Skip to content

Commit 809581c

Browse files
authored
List: fix kbn reordering via shift+arrow when grouped (T1281674, T1281673) (#29525)
1 parent c7e0bd2 commit 809581c

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

packages/devextreme/js/__internal/ui/list/m_list.edit.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ class ListEdit extends ListBase {
4444
const nextItemIndex = focusedItemIndex + (moveUp ? -1 : 1);
4545
const $nextItem = editStrategy.getItemElement(nextItemIndex);
4646

47-
this.reorderItem(focusedElement, $nextItem);
48-
this.scrollToItem(focusedElement);
47+
const isMoveFromGroup = this.option('grouped')
48+
&& $(focusedElement).parent().get(0) !== $nextItem.parent().get(0);
49+
if (!isMoveFromGroup) {
50+
this.reorderItem(focusedElement, $nextItem);
51+
this.scrollToItem(focusedElement);
52+
}
4953
e.preventDefault();
5054
} else {
5155
const editProvider = this._editProvider;

packages/devextreme/testing/tests/DevExpress.ui.widgets/listParts/editingTests.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import ArrayStore from 'common/data/array_store';
88
import 'ui/list';
99

1010
const LIST_ITEM_CLASS = 'dx-list-item';
11+
const LIST_ITEMS_CLASS = 'dx-list-items';
1112
const LIST_ITEM_SELECTED_CLASS = 'dx-list-item-selected';
1213
const LIST_GROUP_CLASS = 'dx-list-group';
14+
const LIST_GROUP_HEADER_CLASS = 'dx-list-group-header';
1315
const LIST_SELECT_ALL_CHECKBOX_CLASS = 'dx-list-select-all-checkbox';
1416
const LIST_SELECT_ALL_CLASS = 'dx-list-select-all';
1517
const SELECT_CHECKBOX_CLASS = 'dx-list-select-checkbox';
@@ -316,6 +318,102 @@ QUnit.module('keyboard navigation', {
316318

317319
assert.deepEqual(list.option('items'), items, 'items were reordered');
318320
});
321+
322+
QUnit.module('grouped', {
323+
beforeEach: function() {
324+
this.getInitialItems = () => {
325+
return [{
326+
items: ['1-1', '1-2'],
327+
}, {
328+
items: ['2-1', '2-2'],
329+
}];
330+
};
331+
this.items = this.getInitialItems();
332+
this.$list = $('#list').dxList({
333+
items: this.getInitialItems(),
334+
grouped: true,
335+
collapsibleGroups: true,
336+
itemDragging: {
337+
allowReordering: true
338+
},
339+
focusStateEnabled: true
340+
});
341+
this.list = this.$list.dxList('instance');
342+
this.keyboard = keyboardMock(this.$list.find('[tabindex=0]'));
343+
}
344+
}, () => {
345+
QUnit.test('shift+arrowDown on first group last item should not move item out of group (T1281674)', function(assert) {
346+
const $firstGroupLastItem = this.$list
347+
.find(`.${LIST_GROUP_CLASS}`).eq(0)
348+
.find(`.${LIST_ITEM_CLASS}`).last();
349+
350+
$firstGroupLastItem.trigger('dxpointerdown');
351+
this.clock.tick(10);
352+
this.keyboard.keyDown('arrowDown', { shiftKey: true });
353+
354+
assert.deepEqual(this.list.option('items'), this.items, 'items are not reordered');
355+
});
356+
357+
QUnit.test('shift+arrowDown on a last group last item should not move item out of group (T1281674)', function(assert) {
358+
const $lastGroupLastItem = this.$list
359+
.find(`.${LIST_GROUP_CLASS}`).last()
360+
.find(`.${LIST_ITEM_CLASS}`).last();
361+
362+
$lastGroupLastItem.trigger('dxpointerdown');
363+
this.clock.tick(10);
364+
this.keyboard.keyDown('arrowDown', { shiftKey: true });
365+
366+
assert.deepEqual(this.list.option('items'), this.items, 'items are not reordered');
367+
});
368+
369+
QUnit.test('shift+arrowUp on first group first item should not move item out of group (T1281674)', function(assert) {
370+
const $firstGroupFirstItem = this.$list
371+
.find(`.${LIST_GROUP_CLASS}`).eq(0)
372+
.find(`.${LIST_ITEM_CLASS}`).eq(0);
373+
374+
$firstGroupFirstItem.trigger('dxpointerdown');
375+
this.clock.tick(10);
376+
this.keyboard.keyDown('arrowUp', { shiftKey: true });
377+
378+
assert.deepEqual(this.list.option('items'), this.items, 'items are not reordered');
379+
});
380+
381+
QUnit.test('shift+arrowUp on last group first item should not move item out of group (T1281674)', function(assert) {
382+
const $lastGroupFirstItem = this.$list
383+
.find(`.${LIST_GROUP_CLASS}`).last()
384+
.find(`.${LIST_ITEM_CLASS}`).eq(0);
385+
386+
$lastGroupFirstItem.trigger('dxpointerdown');
387+
this.clock.tick(10);
388+
this.keyboard.keyDown('arrowUp', { shiftKey: true });
389+
390+
assert.deepEqual(this.list.option('items'), this.items, 'items are not reordered');
391+
});
392+
393+
QUnit.test('shift+arrowDown should not move group header (T1281673)', function(assert) {
394+
const $lastGroupHeader = this.$list.find(`.${LIST_GROUP_HEADER_CLASS}`).last();
395+
396+
$lastGroupHeader.trigger('dxclick');
397+
const $initialItemsSnapshot = this.$list.find(`.${LIST_ITEMS_CLASS}`).html();
398+
this.keyboard.keyDown('arrowDown', { shiftKey: true });
399+
400+
const $itemsSnapshot = this.$list.find(`.${LIST_ITEMS_CLASS}`).html();
401+
assert.deepEqual(this.list.option('items'), this.items, 'items option is not changed');
402+
assert.deepEqual($itemsSnapshot, $initialItemsSnapshot, 'DOM is not changed');
403+
});
404+
405+
QUnit.test('shift+arrowUp should not move group header (T1281673)', function(assert) {
406+
const $lastGroupHeader = this.$list.find(`.${LIST_GROUP_HEADER_CLASS}`).last();
407+
408+
$lastGroupHeader.trigger('dxclick');
409+
const $initialItemsSnapshot = this.$list.find(`.${LIST_ITEMS_CLASS}`).html();
410+
this.keyboard.keyDown('arrowUp', { shiftKey: true });
411+
412+
const $itemsSnapshot = this.$list.find(`.${LIST_ITEMS_CLASS}`).html();
413+
assert.deepEqual(this.list.option('items'), this.items, 'items option is not changed');
414+
assert.deepEqual($itemsSnapshot, $initialItemsSnapshot, 'DOM is not changed');
415+
});
416+
});
319417
});
320418

321419
QUnit.module('deleting in grouped list with dataSource', {

0 commit comments

Comments
 (0)