-
In the offical docs I consistently see a wrapper div around the virtualized items that looks like so:
Unfortunately, this causes issues for the contextual menu that I have on each of my items. Is there anyway to avoid this form of placement? Has anyone done something different? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Yes, rather to position each element we can move it as whole group. We use this approach for table, where we can't position absolute rows. const List = () => {
const virtualizer = useWindowVirtualizer({
count: 1000,
estimateSize: () => 24,
})
const items = virtualizer.getVirtualItems()
const [paddingTop, paddingBottom] =
items.length > 0
? [
Math.max(0, items[0].start - virtualizer.options.scrollMargin),
Math.max(0, virtualizer.getTotalSize() - items[items.length - 1].end),
]
: [0, 0]
return (
<div>
<div
style={{
paddingTop,
paddingBottom,
}}
>
{items.map((item) => (
<div
key={item.key}
data-index={item.index}
ref={virtualizer.measureElement}
>
<div>{item.index}</div>
</div>
))}
</div>
</div>
)
} |
Beta Was this translation helpful? Give feedback.
-
Above answer is not working with native html table elements like where display: table is used instead of display: block like divs. |
Beta Was this translation helpful? Give feedback.
-
A more hackish solution that works without position absolute and without padding logic. Make a wrapper over your virtual item and give it <div
style={{
height: `${virtualizer.getTotalSize()}px`,
}}
>
{virtualizer.getVirtualItems().map((virtualItem) => {
return (
<div
key={virtualItem.key}
style={{
// position: "absolute", Without position absolute
height: `0px`,
}}
>
<div
style={{
height: `${virtualItem.size}px`,
transform: `translateY(${virtualItem.start}px)`,
}}
>
{virtualItem.index}
</div>
</div>
);
})}
</div> |
Beta Was this translation helpful? Give feedback.
Yes, rather to position each element we can move it as whole group. We use this approach for table, where we can't position absolute rows.