question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resizing rows in dynamic list

See original GitHub issue

I’ve given the dynamic list of this great lib a spin and encountered two issues:

  1. My rows can expand/collapse on click (i.e. change height), but the virtualized list doesn’t adapt the item positions. Could this benefit from a ResizeObserver hook such as useMeasure?
  2. It would be very nice to have a mechanism where the dynamic list’s overall initial height is set such that it doesn’t cut off partial rows. See e.g. the first example shown in react-collapse where the height limit is set by the number of visible paragraphs.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:20
  • Comments:10

github_iconTop GitHub Comments

25reactions
piecykcommented, Apr 10, 2021

Yes, using ResizeObserver is the way to go. Current it’s possible to implement this with small row wrapper, checkout demo at https://codesandbox.io/s/resizeobserver-react-virtual-6131c?file=/src/index.js

IMHO as ResizeObserver is supported in every modern browser https://caniuse.com/resizeobserver maybe we can officially supporting it.

4reactions
kidrocacommented, Nov 23, 2021

I’ve found that for any dynamic size to be able to work we shouldn’t set a fixed height on the row elements I also have content that allows to expand an item and it doesn’t work unless I substitute height for min-height

           {rowVirtualizer.virtualItems.map(virtualRow => (
             <div
               key={virtualRow.index}
               ref={virtualRow.measureRef}
               className={virtualRow.index % 2 ? 'ListItemOdd' : 'ListItemEven'}
               style={{
                 position: 'absolute',
                 top: 0,
                 left: 0,
                 width: '100%',
                 // This change
                 minHeight: `${virtualRow.size}px`,
                 transform: `translateY(${virtualRow.start}px)`,
               }}
             >
               Row {virtualRow.index}
             </div>
           ))}

For example my inner content would expand an item from 100px to 350px, but it won’t work when the row has a fixed height of 100px When I use min-height the row is allowed to expand, which in turn gets captured by measureRef and the change propagates to virtualRow.size and virtualRow.start

I imagine to be able to both expand and shrink we should not be setting any height at all, but only measureRef

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resizing rows in dynamic list · Issue #28 · TanStack/virtual
My rows can expand/collapse on click (i.e. change height), but the virtualized list doesn't adapt the item positions. Could this benefit from a...
Read more >
Resizing ListView Rows Dynamically - android - Stack Overflow
Overview: I have a ListView of different types of rows including images and text of varying heights. At runtime, I am trying to...
Read more >
How to change and AutoFit row height in Excel - Ablebits
Here's how: To change the height of one row, drag the lower boundary of the row heading until the row is set to...
Read more >
Resize a table by adding or removing rows and columns
You can use the Resize command in Excel to add rows and columns to a table: Click anywhere in the table, and the...
Read more >
Dynamic resize - Templater
Dynamic resize. Templater's low level API has the Resize(int) method which is used to (usually vertically) resize on object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found