Skip to content

Fix clicking a frozen cell scrolling the grid back - #4247

Merged
amanmahajan7 merged 6 commits into
mainfrom
fix-frozen-cell-scroll
Oct 26, 2026
Merged

amanmahajan7 merged 6 commits into
mainfrom
fix-frozen-cell-scroll

Conversation

@amanmahajan7

@amanmahajan7 amanmahajan7 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes a regression from #3963 in Chromium and WebKit: with frozen columns and the grid scrolled horizontally, clicking an already active frozen cell scrolls the grid back by the frozen columns' width. Each further click scrolls back again, until the horizontal scroll is gone. Double-clicking a frozen cell, and moving within a frozen column with the keyboard, do the same. Firefox isn't affected.

Cause

Frozen cells are position: sticky. The grid sets scroll-padding to the size of the frozen columns, so that ordinary cells scrolled into view don't end up hidden under them.

  • Before Make rows focusable, remove focus sink #3963, that padding was conditional. The inline padding applied only when the active cell was past the frozen columns, and the block padding only when the active row was a regular row:
    scrollPaddingInlineStart:
      selectedPosition.idx > lastFrozenColumnIndex || scrollToPosition?.idx !== undefined
        ? `${totalFrozenColumnWidth}px`
        : undefined,
  • Make rows focusable, remove focus sink #3963 ("Make rows focusable, remove focus sink") made the padding unconditional.
  • The result: a sticky frozen cell always sits inside the padded strip. Chromium and WebKit treat that strip as outside the area an element must be in to count as visible, so scrollIntoView on a frozen cell scrolls the grid. The cell is sticky, so it never leaves the strip, and every call scrolls again. Firefox doesn't scroll in this case.

Why the second click, not the first

  • First click on a new cell: the cell is activated without asking for focus or scrolling, and the mouse press focuses it. Focusing on a click doesn't scroll.
  • Clicking the active cell again: this takes the samePosition branch of setPosition, which calls scrollIntoView on the cell. A double-click hits it twice.
  • Keyboard navigation onto or within the frozen column hits it through the focus effect's scrollIntoView.

Measured with real mouse input in Chromium on main: the first click leaves scrollLeft at 1000, and each later click scrolls back exactly 100px, the frozen column's width.

When it was introduced

The test was run against older versions of src/ (only src/ swapped, with today's tests and tooling):

Version Result
v7.0.0-beta.59 passes
173e7f7d, the commit before #3963 passes
90a8fe8f (#3963) fails
every later src/ commit tested, v7.0.0-beta.60, and main fails

None of the recent PRs are involved: the bug was already there in every commit since #4034.

Fix

Restore the conditional scroll padding, adapted to start- and end-frozen columns:

const hasInlineScrollPadding = isScrollingToPosition || queryActiveColumn()?.frozen === false;
const hasBlockScrollPadding = isScrollingToPosition || activePositionIsInViewport;
  • Inline padding applies only when the active position is a cell in a non-frozen column.
  • Block padding applies only when the active position is a regular row or a cell in one, not a header or summary row.
  • Both apply while scrolling to a position (scrollToCell), as before.
  • queryActiveColumn() is new in useActivePosition. It returns the active column, or undefined when the active position isn't a cell, for example on the first render. getActiveColumn() is now built on it, and still throws in that case.

Ordinary cells still scroll out from under the frozen columns, header and summary rows, because the padding is present whenever an ordinary cell is active.

The same root cause also affected:

  • double-clicking a cell in an end-frozen column;
  • double-clicking a header cell while scrolled down, which scrolled up through the always-on block padding.

Both were checked with temporary tests and are fixed too.

Alternative considered

Keep the always-on padding, and when the element to scroll into view is a frozen cell, scroll its row instead. The row spans every column, so the browser only scrolls vertically. This fixed the frozen-column case in all three browsers. But it doesn't cover the vertical version of the bug, header and summary cells, because no element spans every row of a column. Conditional padding fixes both axes in one place, and matches the behavior before #3963.

Testing

  • New test in test/browser/column/startFrozen.test.ts:

    1. activate a frozen cell while the grid is unscrolled;
    2. scroll the grid right;
    3. press ArrowDown, and expect scrollLeft to be unchanged.

    This goes through the app's own scrollIntoView call, the same one a second click makes. It avoids clicking after scrolling, because Playwright scrolls a clicked element into view before clicking, which users don't experience.

    • On main, it fails in Chromium and WebKit (scrollLeft 900 instead of 1000), and passes in Firefox, which isn't affected.
    • With the fix, it passes in all three browsers.
  • Temporary checks (not committed), all passing with the fix:

    • repeated real clicks on the active frozen cell (Chromium, native mouse input);
    • PageDown past the bottom still scrolls vertically;
    • ArrowLeft onto a cell hidden under the frozen column still scrolls it into view;
    • double-clicking an end-frozen cell keeps scrollLeft;
    • double-clicking a header cell keeps scrollTop.
  • Full Chromium browser suite: passes, except 3 sorting tests that also fail on main on the same machine.

  • vp check, vp run typecheck and vp pack pass.

🤖 Generated with Claude Code

@amanmahajan7 amanmahajan7 self-assigned this Oct 26, 2026
Since #3963, the grid always set its scroll padding to the size of the
frozen columns, header rows, and summary rows. Frozen cells, header cells,
and summary cells are sticky and sit inside that padding, so focusing or
scrolling them into view, e.g. when clicking an active frozen cell again,
scrolled the grid until they were out of it, scrolling back to the start.

Restore the conditional padding from before #3963: apply it only on the
axes where the active cell isn't sticky, or when scrolling to a position.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov-commenter

codecov-commenter commented Oct 26, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.13%. Comparing base (fd0cc21) to head (a7670cc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4247   +/-   ##
=======================================
  Coverage   99.13%   99.13%           
=======================================
  Files          46       46           
  Lines        2195     2207   +12     
  Branches      968      977    +9     
=======================================
+ Hits         2176     2188   +12     
  Misses         19       19           
Files with missing lines Coverage Δ
src/DataGrid.tsx 99.08% <100.00%> (+0.01%) ⬆️
src/hooks/useActivePosition.ts 96.96% <100.00%> (+0.24%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amanmahajan7 amanmahajan7 changed the title Add a failing test: double-clicking a frozen cell scrolls the grid back Fix clicking a frozen cell scrolling the grid back Oct 26, 2026
@amanmahajan7
amanmahajan7 marked this pull request as ready for review October 26, 2026 16:37

@nstepien nstepien left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity:

  • Why does this happen on the second click but not the first click?
  • Can this be fixed without conditional scroll padding? I would expect browsers to not scroll the container when the element is already visible.

Comment thread src/DataGrid.tsx Resolved
amanmahajan7 and others added 3 commits October 26, 2026 17:34
Co-authored-by: Nicolas Stepien <[email protected]>
…adding

`isRowInViewport` and `isCellInViewport` aren't in scope in `DataGrid`,
and `getActiveColumn()` throws when the active position isn't a cell,
such as on the first render, so add `queryActiveColumn()` to
`useActivePosition` and use the existing `activePositionIsInViewport`.

Test focusing a frozen cell with the keyboard instead of double-clicking
it, as Playwright scrolls the clicked element into view before clicking,
which doesn't happen for users.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@amanmahajan7

amanmahajan7 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

@nstepien thanks, answers to your questions:

Why does this happen on the second click but not the first click?

On the first click on a new cell, setPosition activates it without asking for focus or scrolling, and the mouse press focuses it. Focusing on a click doesn't scroll.

Clicking the cell again when it's already active takes the samePosition branch of setPosition, which calls scrollIntoView(getCellToScroll(...)). A double-click hits that twice, and keyboard navigation within the frozen column hits it through the focus effect.

With real mouse input in Chromium on main:

  • the first click leaves scrollLeft at 1000;
  • each further click scrolls back exactly 100px, the frozen column's width.

Can this be fixed without conditional scroll padding? I would expect browsers to not scroll the container when the element is already visible.

Firefox behaves as you'd expect and doesn't scroll. Chromium and WebKit treat the scroll-padding strip as outside the area an element must be in to count as visible, and a sticky frozen cell always sits in that strip. So scrollIntoView scrolls, the cell stays stuck in the strip, and the next call scrolls again.

It can be fixed without conditional padding: when the element to scroll into view is a frozen cell, scroll its row instead. The row spans every column, so only the vertical scroll can change. In my tests, that fixed the frozen-column case in all three browsers, with the padding always on. But it doesn't cover the vertical version of the bug: double-clicking a header cell while scrolled down scrolls up through the always-on block padding. That would need "scroll horizontally only", and no element spans every row of a column. Conditional padding fixes both axes in one place, and matches the behavior before #3963, so I kept it. Happy to switch if you prefer the targeted approach.

On your suggestion: as you mentioned, getActiveColumn() throws when the active position isn't a cell, including on the first render. And isRowInViewport/isCellInViewport aren't in scope in DataGrid. So e0499e4 adds queryActiveColumn() to useActivePosition (with getActiveColumn() built on it), and uses the existing activePositionIsInViewport, which is isRowInViewport || isCellInViewport. I kept the padding logic in DataGrid, since it also depends on the scroll-to-position state from useScrollToPosition.

I also changed the test. It now focuses a frozen cell with ArrowDown after scrolling, instead of double-clicking. Playwright scrolls a clicked element into view before clicking, so on main the double-click test mostly failed because of Playwright's own scroll, not the grid's. The keyboard version goes through the grid's own scrollIntoView call: it fails on main in Chromium and WebKit, and passes with the fix.

Generated with Claude Code

@amanmahajan7
amanmahajan7 requested a review from nstepien October 26, 2026 23:40
@amanmahajan7
amanmahajan7 merged commit 81f2df3 into main Oct 26, 2026
5 checks passed
@amanmahajan7
amanmahajan7 deleted the fix-frozen-cell-scroll branch October 26, 2026 23:41
@amanmahajan7

Copy link
Copy Markdown
Collaborator Author

Let me know if you have any other comments. I can create a follow up PR

@nstepien

Copy link
Copy Markdown
Collaborator

LGTM 👍

nstepien added a commit that referenced this pull request Oct 31, 2026
With `content-visibility: auto` on the nested grid, WebKit sizes the
columns of its row wrongly until the next layout. Since #4247, activating
a cell changes the scroll padding of the grid, so pressing the mouse
triggers that layout. It moves the checkbox before the mouse is released,
which loses the click.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants