Skip to content

Is there anyway to avoid the absolute positioning of virtualized items? #476

Answered by piecyk
lexahall asked this question in Q&A
Discussion options

You must be logged in to vote

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) => (

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@lexahall
Comment options

@MTG2000
Comment options

@bennobuilder
Comment options

@piecyk
Comment options

Answer selected by lexahall
Comment options

You must be logged in to vote
1 reply
@piecyk
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants