Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScrollToIndex not scrolling as expected #1226

Closed
matthew-matvei opened this issue Oct 1, 2018 · 14 comments
Closed

ScrollToIndex not scrolling as expected #1226

matthew-matvei opened this issue Oct 1, 2018 · 14 comments
Labels

Comments

@matthew-matvei
Copy link

I've created a small repro based on what we're experiencing trying to make use of <List />'s scrollToIndex prop. I believe it's a bug, given how simple the repro is and how closely we've attempted to follow documentation / examples, but it's always possible we've just mixed something up.

What is the current behavior?

  1. Clone the repro here
  2. Build and start the app (I've been using recent version of Chrome)
  3. Enter a number between 0 and 999 in the number input at the top of the screen

Despite the scrollToIndex state in <App /> being updated, which feeds down to the <List />'s scrollToIndex prop, the list is not navigated to the desired list element as expected.

What is the expected behavior?

The element at the index given in the number input box is navigated to.

Which versions of React and react-virtualized, and which browser / OS are affected by this issue? Did this work in previous versions of react-virtualized?

Browser Chrome v69.0.3497.100
OS Windows 10
React 16.5.2
React DOM 16.5.2
react-virtualized 9.20.1
@matthew-matvei
Copy link
Author

I have found this issue isn't apparent after downgrading react and react-dom to versions 16.3.2. I hope that helps, but I will leave this open since I don't think downgrading is an acceptable solution.

@michaeldzjap
Copy link

#1179 is related

@alexandrzavalii
Copy link

Anyone has a workaround for this ?

@matthew-matvei
Copy link
Author

A workaround would be downgrading React. Version 16.3.2 worked for us.

@KaySackey
Copy link

KaySackey commented Oct 8, 2018

I'm using this currently as a workaround.
It's pseudo-code that I extracted from a much larger file, but it's a start on a workable solution.

    componentDidMount(){
        if (this.props.start_index < 0) {
            return;
        }

        const initial_top = this._list_ref.getOffsetForRow({
            alignment: "start",
            index: this.props.start_index,
        });
        
        window.scrollTo(0, initial_top);
    }
    
    render(){
        return (
            <List ref={ref => this._list_ref = ref} {...other_props} scrollToIndex={this.props.start_index}/>
        )
    }

Basically it manually calls getOffsetForRow after mounting, then scrolls the window the correct location. The scrollToIndex prop is still required, or else the List component will not render the correct rows initially.

I have been using this with WindowScroller, so I have no idea if it works solo as WindowScroller does things like patch the scrollTop.

@cquiroz
Copy link

cquiroz commented Oct 31, 2018

I'm badly affected by this bug, the workaround suggested didn't work for me on a regular Table. Any other ideas?

@john-veresk
Copy link
Contributor

I've made a PR which should fix this issue.

@TilWs
Copy link

TilWs commented Dec 21, 2018

Having the same issue on react and react-dom 16.3.2. Any updates?

@bhearsum
Copy link

There's a number of Issues open about this, but I think it was fixed in #1288, and then that was backed out in #1446. See also: #1179.

@stevenmasci
Copy link

Hi, I'm also having the same issue, react react-dom 16.12.0, react-virtualized 9.21.2.

As a work around I'm manually calculating the window scroll offset by multiplying scrollToIndex by rowHeight and then using window.scrollTo().

@Dean177
Copy link

Dean177 commented Mar 14, 2020

I too am encountering this issue with react/[email protected] and [email protected].

I was able to get it kinda (still seems to be a positioning bug?) by downgrading react-virtualized to 9.21.1 and using a a ref on the List component:

let listScroll = React.useRef();
let onEvent = () => {
  listScroll.current.scrollToRow(200)
}

return (
  <List
    ref={listScroll}
    {...otherProps}
  />

@Uneedcode
Copy link

I have the same bug. so bad

@dzyubadmytro
Copy link

Any updates on this?

1 similar comment
@pm-Egor-Genning
Copy link

Any updates on this?

@github-actions github-actions bot added the Stale label Oct 2, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests