Skip to content

DataGrid - Fix the browser scrolling back to the grid when data is updated (T1310557)#33168

Open
markallenramirez wants to merge 1 commit intoDevExpress:26_1from
markallenramirez:bug_T1310557/26_1
Open

DataGrid - Fix the browser scrolling back to the grid when data is updated (T1310557)#33168
markallenramirez wants to merge 1 commit intoDevExpress:26_1from
markallenramirez:bug_T1310557/26_1

Conversation

@markallenramirez
Copy link
Copy Markdown
Contributor

No description provided.

@markallenramirez markallenramirez self-assigned this Apr 6, 2026
Copilot AI review requested due to automatic review settings April 6, 2026 12:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes DataGrid keyboard-navigation focus restoration so that updating data doesn’t cause the browser to scroll the page back to the grid (by using native focus({ preventScroll }) during render completion).

Changes:

  • Add a preventScroll flag to _updateFocus and _focus and propagate it from renderCompleted.
  • Replace synthetic eventsEngine.trigger(..., 'focus') with native DOM focus({ preventScroll }) for the focused cell/row.

Comment on lines 1736 to +1745
$focusedElementInsideCell,
);
return;
}
!isFocusedElementDefined && this._focus($cell, false, skipFocusEvent);
} else if (
!isFocusedElementDefined
&& (this._isNeedFocus || this._isHiddenFocus)
) {
this._focus($cell, this._isHiddenFocus, skipFocusEvent);
this._focus($cell, this._isHiddenFocus, skipFocusEvent, preventScroll);
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_updateFocus(..., preventScroll) only forwards preventScroll to _focus(...) in the fallback branch. In the (isRenderView || !isCommandCell) && this._editorFactory.focus() branch, _focus($cell, false, skipFocusEvent) will still call focus({ preventScroll: false }), which can reintroduce the page jump this change is trying to prevent. Consider passing preventScroll through in this branch as well (or routing both branches through a single _focus call that receives the flag).

Copilot uses AI. Check for mistakes.
Comment on lines +1636 to 1638
public _focus($cell, disableFocus?, skipFocusEvent?, preventScroll = false) {
const $row = $cell && !$cell.hasClass(ROW_CLASS)
? $cell.closest(`.${ROW_CLASS}`)
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_focus now accepts preventScroll, but there are derived controllers overriding _focus (e.g. keyboard_navigation/scrollable_a11y.ts) that currently only accept 3 params and call super._focus($cell, disableFocus, skipFocusEvent). When preventScroll is passed from this controller, those overrides will ignore it and the scroll-prevention behavior will not apply in those modes. Please update the overrides to accept/forward the new parameter.

Copilot uses AI. Check for mistakes.
Comment on lines 312 to +316
if (needUpdateFocus) {
const isScrollEvent = !!e?.event?.type;
const skipFocusEvent = e?.virtualColumnsScrolling && isScrollEvent;
this._updateFocus(true, skipFocusEvent);
const preventScroll = !isFullUpdate;
this._updateFocus(true, skipFocusEvent, preventScroll);
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces new behavior (calling element.focus({ preventScroll }) during renderCompleted when updating focus). There are existing DataGrid keyboard navigation QUnit tests (e.g. testing/tests/DevExpress.ui.widgets.dataGrid/keyboardNavigation.rowsView.tests.js) that cover renderCompleted focus restoration; consider adding a regression test that verifies preventScroll is propagated (e.g. by stubbing HTMLElement.prototype.focus and asserting the preventScroll option for non-refresh change types).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants