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

Unable to scrollToIndex() in List with dynamic height items #6251

Closed
redoz opened this issue Sep 6, 2018 · 4 comments
Closed

Unable to scrollToIndex() in List with dynamic height items #6251

redoz opened this issue Sep 6, 2018 · 4 comments

Comments

@redoz
Copy link
Contributor

redoz commented Sep 6, 2018

Please provide a reproduction of the bug in a codepen:

Bug Report

The scrollToIndex method on the List component does not seem usable with dynamic height list items. I somehow have to be able to measure each item and provide the height for it to work, but as the layout of each item depends on the current width of the row, and the contents inside it, the height is only known after the browser has completed layout out the elements.

So I'm wondering if it would not be possible to measure the height/position of the item in question using the componentDidUpdate method as a fall-back?

I tried disabling the virtualization (onShouldVirtualize={() => false}) but it seems then that the scrollToIndex is completely broken unless you provide a measureItem function.

  • Package version(s): office-ui-fabric-react: 6.62.0
  • Browser and OS versions: (fill this out if relevant)

Priorities and help requested:

Are you willing to submit a PR to fix?: Yes, but this might be beyond my abilities to fix.

Requested priority: High

Products/sites affected: (if applicable)

Describe the issue:

scrollToIndex on List is next to useless unless the consumer is able to provide a function to calculate the height of each item. But if the layout is dynamic and handled by the browser there is no way of measuring items without rendering them so the only functionality available is "scroll to the page containing the item" which is not a useful functionality from an end-user point of view.

If virtualization is disabled however, scrollToIndex appears to do not function at all without a measureItem function passed through.

Actual behavior:

scrollToIndex is not useful when the item height is unknown.

Expected behavior:

scrollToIndex should work even in situations where the item height is unknown until after the browser has layed out the components.

@redoz redoz changed the title List scrollToIndex() with dynamic height items. Unable to scrollToIndex() in List with dynamic height items Sep 6, 2018
@redoz
Copy link
Contributor Author

redoz commented Sep 6, 2018

I experimented some more, and it seems that if I add getPageSpecification={() => ({itemCount: 1})} and enable the virtualization, it will work. Not sure what kind of perf hit I take from rendering a page for every row though.

@micahgodbolt
Copy link
Member

I've got a feeling this might be a limitation of virtualization. I'm curious if other virtualized list components are able to support this, and how they do it.

@micahgodbolt
Copy link
Member

Checking out the popular react-virtualized. Not sure if they do scrollToIndex.

https://github.com/bvaughn/react-virtualized/blob/master/docs/README.md

@micahgodbolt
Copy link
Member

Seems they've hit similar issues bvaughn/react-virtualized#610

@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants