Skip to content

feat(data-grid): auto-scroll grid during drag selection#1115

Open
sadmann7 wants to merge 15 commits intomainfrom
sadman/drag-select-auto-scroll
Open

feat(data-grid): auto-scroll grid during drag selection#1115
sadmann7 wants to merge 15 commits intomainfrom
sadman/drag-select-auto-scroll

Conversation

@sadmann7
Copy link
Copy Markdown
Owner

When drag-selecting cells and moving the mouse beyond the grid's visible edges, the grid now auto-scrolls in that direction and extends the selection to include newly visible cells. Scroll speed scales with distance from the edge for fine-grained control.

When drag-selecting cells and moving the mouse beyond the grid's visible
edges, the grid now auto-scrolls in that direction and extends the
selection to include newly visible cells. Scroll speed scales with
distance from the edge for fine-grained control.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI review requested due to automatic review settings February 24, 2026 09:59
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tablecn Ready Ready Preview, Comment Feb 25, 2026 8:41am

Request Review

Guard against missing container ref in tick() by stopping auto-scroll
immediately when container or table refs are unavailable. This prevents
infinite recursion in test environments where RAF executes synchronously.

Also prevent startAutoScroll from starting when container doesn't exist.

Co-authored-by: Cursor <cursoragent@cursor.com>
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

This PR adds auto-scroll functionality to the data grid during drag selection. When users drag-select cells and move the mouse beyond the grid's visible edges, the grid now automatically scrolls in that direction while extending the selection to include newly visible cells. The scroll speed scales with the distance from the edge, providing fine-grained control.

Changes:

  • Added four new constants to configure auto-scroll behavior (edge zone, minimum/maximum speed, and selection throttle)
  • Created a dragDepsRef using useAsRef to maintain stable references to selection functions and grid properties
  • Implemented a comprehensive auto-scroll effect using requestAnimationFrame that tracks mouse position, calculates scroll deltas, updates scroll position, and extends cell selection

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Swap pinned column widths for viewport scroll area calculation in RTL
- Map visual zones to correct logical column arrays (left visual = right logical in RTL)
- Handle negative scrollLeft in RTL browsers correctly

Co-authored-by: Cursor <cursoragent@cursor.com>
Replace complex width-based column calculations with document.elementFromPoint
to directly find the cell under the mouse cursor. This works correctly in both
LTR and RTL without manual coordinate translation or zone mapping.

Co-authored-by: Cursor <cursoragent@cursor.com>
In RTL, logical column 0 is on the visual right. The previous code
measured absX from the visual left, mapping to the wrong column.
Now measures from the visual right in RTL mode, correctly matching
logical column order. Also handles Firefox RTL scrollLeft (non-negative)
vs Chrome (negative) for the scroll offset calculation.

Co-authored-by: Cursor <cursoragent@cursor.com>
When only scrolling vertically (no horizontal auto-scroll), keep the
current selection column instead of recalculating it from pixel math.
The scrollLeft-based column resolution is unreliable in RTL because
scrollLeft=0 is ambiguous between Chrome's initial state and Firefox's
fully-scrolled state. Column changes during horizontal auto-scroll
still use the full calculation; vertical-only scrolling preserves
the column from onCellMouseEnter.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	public/r/data-grid.json
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.

2 participants