TanStack / TanStack/virtual

`scrollIntoView` does not fully reveal item if scroll element's client size and offset size are different

Open
#634 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.1k
Forks
466
Avg merge
2d 31m
Merged PRs (30d)
13

Description

Describe the bug

The virtualizer's scrollIntoView method does not fully scroll an item into view at the end of the block if the scroll element's client size and offset size are different. For example if the scroll element has a border or scrollbar.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/tender-tom-z8876k

Steps to reproduce

This grid is forked from the official "Fixed" react example. Keyboard arrow navigation has been added, plus a 10px thick border on the scroll element.

Click onto a grid item to focus it, and then use the right or down arrow keys to navigate past the edge of the scroll container, you will find that the focused item does not get fully scrolled into view, but is partly obscured by the scroll element's border.

Expected behavior

As a user I expected the focused cell to be fully, but just barely, scrolled into view at the edge of the scroll element. Instead, it's partly cropped.

How often does this bug happen?

Every time

Screenshots or Videos

https://github.com/TanStack/virtual/assets/34119/bc7e97d8-166d-4c63-a776-6208d6708c1c

Platform

macOS, chrome

tanstack-virtual version

3.0.1

TypeScript version

No response

Additional context

In another application I'm working on, the virtualizer does not account for the size of a scrollbar and exhibits the same defect.

This example can be repaired by overriding the virtualizers' scrollRect with the scroll element's clientWidth and clientHeight measurements. You can see this by uncommenting the code at the top of the onFocus handler on the items.

Terms & Code of Conduct
  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the virtualizer's scrollIntoView method and the scrollRect override shown in the reproducible React example. Reproduce the issue with a bordered scroll element and inspect the onFocus handler and clientWidth/clientHeight measurements. Done means keyboard navigation fully reveals the focused cell at the container edge, including when borders or scrollbars make client and offset sizes differ.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.