Skip to content

Commit ed23cfc

Browse files
authored
DataGrid - Scrolling position is reset to far right on an attempt to scroll left if the most right cell is focused using the keyboard (T1277214) (DevExpress#29373)
1 parent b5054a9 commit ed23cfc

File tree

5 files changed

+51
-19
lines changed

5 files changed

+51
-19
lines changed

e2e/testcafe-devextreme/tests/dataGrid/common/scrolling.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ test('DataGrid - Gray boxes appear when the push method is used to remove rows i
17651765
});
17661766
});
17671767

1768-
// T1262288
1768+
// T1262288 - Left to Right
17691769
test('DataGrid - Focused cell moves to the end of the table after horizontal scrolling', async (t) => {
17701770
const dataGrid = new DataGrid('#container');
17711771

@@ -1794,3 +1794,33 @@ test('DataGrid - Focused cell moves to the end of the table after horizontal scr
17941794
enabled: false,
17951795
},
17961796
}));
1797+
1798+
// T1277214 - Right to Left
1799+
test('DataGrid - Scrolling position is reset to far right on an attempt to scroll left if the most right cell is focused using the keyboard', async (t) => {
1800+
const dataGrid = new DataGrid('#container');
1801+
await dataGrid.scrollTo(t, { x: 1000 });
1802+
await t
1803+
.click(dataGrid.getDataCell(0, 20).element)
1804+
.pressKey('right');
1805+
1806+
await t.expect(dataGrid.getDataCell(0, 20).isFocused).ok();
1807+
1808+
await dataGrid.scrollBy({ x: -1000 });
1809+
await dataGrid.scrollBy({ x: 1000 });
1810+
1811+
await t.expect(dataGrid.getDataCell(0, 20).isFocused).ok();
1812+
}).before(async () => createWidget('dxDataGrid', {
1813+
dataSource: getData(1, 20).map((item, index) => ({ ...item, id: index })),
1814+
keyExpr: 'id',
1815+
columnWidth: 100,
1816+
showBorders: true,
1817+
focusedRowEnabled: true,
1818+
scrolling: {
1819+
columnRenderingMode: 'virtual',
1820+
mode: 'virtual',
1821+
showScrollbar: 'always',
1822+
},
1823+
paging: {
1824+
enabled: false,
1825+
},
1826+
}));

packages/devextreme/js/__internal/grids/grid_core/data_controller/m_data_controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ export class DataController extends DataHelperMixin(modules.Controller) {
499499
that._columnsController.columnsChanged.remove(updateItemsHandler);
500500
that.updateItems({
501501
repaintChangesOnly: false,
502+
event: change?.changeTypes?.event,
502503
virtualColumnsScrolling: change?.changeTypes?.virtualColumnsScrolling,
503504
});
504505
};

packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ export class KeyboardNavigationController extends modules.ViewController {
303303
? !isAppend
304304
: this._isHiddenFocus && isFullUpdate && !e?.virtualColumnsScrolling;
305305
if (needUpdateFocus) {
306-
this._updateFocus(true);
306+
const isScrollEvent = !!e?.event?.type;
307+
const skipFocusEvent = e?.virtualColumnsScrolling && isScrollEvent;
308+
this._updateFocus(true, skipFocusEvent);
307309
}
308310
}
309311
}
@@ -315,9 +317,7 @@ export class KeyboardNavigationController extends modules.ViewController {
315317

316318
if (!$focusedElement.length && e?.virtualColumnsScrolling) {
317319
const focusedColumnIndex = this._focusedCellPosition?.columnIndex ?? -1;
318-
const focusedColumnIndexWithoutOffset = focusedColumnIndex - this._getFocusedColumnIndexOffset(focusedColumnIndex);
319-
320-
return focusedColumnIndexWithoutOffset >= 0;
320+
return this._isColumnRendered(focusedColumnIndex);
321321
}
322322

323323
return true;
@@ -1567,7 +1567,7 @@ export class KeyboardNavigationController extends modules.ViewController {
15671567
}
15681568
}
15691569

1570-
public _updateFocus(isRenderView?) {
1570+
public _updateFocus(isRenderView?, skipFocusEvent = false) {
15711571
this._updateFocusTimeout = setTimeout(() => {
15721572
if (this._needFocusEditingCell()) {
15731573
this._editingController._focusEditingCell();
@@ -1606,12 +1606,12 @@ export class KeyboardNavigationController extends modules.ViewController {
16061606
);
16071607
return;
16081608
}
1609-
!isFocusedElementDefined && this._focus($cell);
1609+
!isFocusedElementDefined && this._focus($cell, false, skipFocusEvent);
16101610
} else if (
16111611
!isFocusedElementDefined
16121612
&& (this._isNeedFocus || this._isHiddenFocus)
16131613
) {
1614-
this._focus($cell, this._isHiddenFocus);
1614+
this._focus($cell, this._isHiddenFocus, skipFocusEvent);
16151615
}
16161616
if (isEditing && !column?.showEditorAlways) {
16171617
this._focusInteractiveElement.bind(this)($cell);
@@ -2007,7 +2007,6 @@ export class KeyboardNavigationController extends modules.ViewController {
20072007
const isShowWhenGrouped = column && column.showWhenGrouped;
20082008
const isDataCell = column && !$cell.hasClass(COMMAND_EXPAND_CLASS) && isDataRow($row);
20092009
const isValidGroupSpaceColumn = function () {
2010-
// eslint-disable-next-line radix
20112010
return (
20122011
(!isMasterDetailRow
20132012
&& column

packages/devextreme/js/__internal/grids/grid_core/virtual_columns/m_virtual_columns.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const rowsView = (Base: ModuleType<RowsView>) => class VirtualColumnsRowsViewExt
5050
}
5151

5252
// @ts-expect-error
53-
that._columnsController.setScrollPosition(left);
53+
that._columnsController.setScrollPosition(left, e.event);
5454
}
5555

5656
protected _renderCore(e) {
@@ -181,11 +181,13 @@ const columns = (Base: ModuleType<ColumnsController>) => class VirtualColumnsCon
181181
return this.option('scrolling.columnPageSize');
182182
}
183183

184-
private _fireColumnsChanged() {
184+
private _fireColumnsChanged(event?) {
185185
const date: any = new Date();
186186
this.columnsChanged.fire({
187187
optionNames: { all: true, length: 1 },
188-
changeTypes: { columns: true, virtualColumnsScrolling: true, length: 2 },
188+
changeTypes: {
189+
columns: true, virtualColumnsScrolling: true, length: 2, event,
190+
},
189191
});
190192
this._renderTime = (new Date()) as any - date;
191193
}
@@ -202,25 +204,25 @@ const columns = (Base: ModuleType<ColumnsController>) => class VirtualColumnsCon
202204
return scrollingTimeout;
203205
}
204206

205-
private setScrollPosition(position) {
207+
private setScrollPosition(position, event?) {
206208
const scrollingTimeout = this.getScrollingTimeout();
207209

208210
if (scrollingTimeout > 0) {
209211
clearTimeout(this._changedTimeout);
210212

211213
this._changedTimeout = setTimeout(() => {
212-
this._setScrollPositionCore(position);
214+
this._setScrollPositionCore(position, event);
213215
}, scrollingTimeout);
214216
} else {
215-
this._setScrollPositionCore(position);
217+
this._setScrollPositionCore(position, event);
216218
}
217219
}
218220

219221
private resize() {
220222
this._setScrollPositionCore(this._position);
221223
}
222224

223-
private _setScrollPositionCore(position) {
225+
private _setScrollPositionCore(position, event?) {
224226
const that = this;
225227

226228
if (that.isVirtualMode()) {
@@ -232,7 +234,7 @@ const columns = (Base: ModuleType<ColumnsController>) => class VirtualColumnsCon
232234
if (needColumnsChanged) {
233235
that._beginPageIndex = beginPageIndex;
234236
that._endPageIndex = endPageIndex;
235-
that._fireColumnsChanged();
237+
that._fireColumnsChanged(event);
236238
}
237239
}
238240
}

packages/devextreme/testing/tests/DevExpress.ui.widgets.dataGrid/virtualColumns.tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ QUnit.module('Scrolling', { beforeEach: setupModule, afterEach: teardownModule }
385385
this.columnsController.columnsChanged.add(e => {
386386
assert.deepEqual(e, {
387387
optionNames: { all: true, length: 1 },
388-
changeTypes: { columns: true, virtualColumnsScrolling: true, length: 2 }
388+
changeTypes: { columns: true, virtualColumnsScrolling: true, length: 2, event: undefined }
389389
}, 'columnsChanged args');
390390
columnsChangedPositions.push(pos);
391391
});
@@ -413,7 +413,7 @@ QUnit.module('Scrolling', { beforeEach: setupModule, afterEach: teardownModule }
413413
this.columnsController.columnsChanged.add(e => {
414414
assert.deepEqual(e, {
415415
optionNames: { all: true, length: 1 },
416-
changeTypes: { columns: true, virtualColumnsScrolling: true, length: 2 }
416+
changeTypes: { columns: true, virtualColumnsScrolling: true, length: 2, event: undefined }
417417
}, 'columnsChanged args');
418418
columnsChangedPositions.push(pos);
419419
});

0 commit comments

Comments
 (0)