Skip to content

Commit 5e45493

Browse files
authored
List: fix border cases on dragging first or last items using KBN (T1320189) (#32350)
1 parent 97fdcd3 commit 5e45493

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,19 @@ class ListEdit extends ListBase {
6161

6262
if (e.shiftKey && itemDragging?.allowReordering) {
6363
const nextItemIndex = focusedItemIndex + (moveUp ? -1 : 1);
64+
65+
if (nextItemIndex < 0
66+
|| nextItemIndex === NOT_EXISTING_INDEX
67+
|| nextItemIndex > this._getLastItemIndex()) {
68+
return;
69+
}
70+
6471
const $nextItem = editStrategy.getItemElement(nextItemIndex);
6572

73+
if (!$nextItem) {
74+
return;
75+
}
76+
6677
const isMoveFromGroup = grouped
6778
&& $(focusedElement).parent().get(0) !== $nextItem.parent().get(0);
6879
if (!isMoveFromGroup) {

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,62 @@ QUnit.module('keyboard navigation', {
319319
assert.deepEqual(list.option('items'), items, 'items were reordered');
320320
});
321321

322+
QUnit.test('shift+arrowUp on first item should not throw error (T1320189)', function(assert) {
323+
const items = ['1', '2', '3'];
324+
325+
const $list = $('#list').dxList({
326+
items: items,
327+
editEnabled: true,
328+
itemDragging: {
329+
allowReordering: true
330+
},
331+
focusStateEnabled: true
332+
});
333+
334+
const list = $list.dxList('instance');
335+
const keyboard = keyboardMock($list.find('[tabindex=0]'));
336+
337+
const $firstItem = $list.find('.' + LIST_ITEM_CLASS).eq(0);
338+
list.option('focusedElement', $firstItem.get(0));
339+
340+
let errorMessage = '';
341+
try {
342+
keyboard.keyDown('arrowUp', { shiftKey: true });
343+
} catch(e) {
344+
errorMessage = `error message: ${e.message}`;
345+
}
346+
347+
assert.strictEqual(errorMessage, '', 'no error thrown when trying to move first item up');
348+
});
349+
350+
QUnit.test('shift+arrowDown on last item should not throw error (T1320189)', function(assert) {
351+
const items = ['1', '2', '3'];
352+
353+
const $list = $('#list').dxList({
354+
items: items,
355+
editEnabled: true,
356+
itemDragging: {
357+
allowReordering: true
358+
},
359+
focusStateEnabled: true
360+
});
361+
const list = $list.dxList('instance');
362+
const keyboard = keyboardMock($list.find('[tabindex=0]'));
363+
364+
const $lastItem = $list.find('.' + LIST_ITEM_CLASS).eq(2);
365+
list.option('focusedElement', $lastItem.get(0));
366+
367+
let errorMessage = '';
368+
try {
369+
keyboard.keyDown('arrowDown', { shiftKey: true });
370+
} catch(e) {
371+
errorMessage = `error message: ${e.message}`;
372+
}
373+
374+
assert.strictEqual(errorMessage, '', 'no error thrown when trying to move last item down');
375+
});
376+
377+
322378
QUnit.module('grouped', {
323379
beforeEach: function() {
324380
this.getInitialItems = () => {

0 commit comments

Comments
 (0)