-
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.
Answered by
piecyk
Jan 19, 2023
Replies: 1 comment 1 reply
-
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.
1 reply
Answer selected by
lexahall
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.