Skip to content

Commit

Permalink
fix: grid does not render items when initialTopMostItemIndex is set t…
Browse files Browse the repository at this point in the history
…o 1 or more (#1162)
  • Loading branch information
suke authored Nov 21, 2024
1 parent 3405b64 commit 483654f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gridSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export const gridSystem = /*#__PURE__*/ u.system(

if (itemWidth === 0) {
const startIndex = getInitialTopMostItemIndexNumber(initialTopMostItemIndex, totalCount)
const endIndex = Math.max(startIndex + initialItemCount - 1, 0)
const endIndex = startIndex + Math.max(initialItemCount - 1, 0)
return buildProbeGridState(buildItems(startIndex, endIndex, data))
}

Expand Down
18 changes: 18 additions & 0 deletions test/Grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ describe('Grid', () => {
expect(listParent.textContent).toBe('Item 0')
})

it('renders a probe item initially with the initialTopMostItemIndex', () => {
act(() => {
ReactDOM.createRoot(container).render(<VirtuosoGrid totalCount={20000} initialTopMostItemIndex={10} />)
})

const scroller = container.firstElementChild as any
const viewport = scroller.firstElementChild
const listParent = viewport.firstElementChild

act(() => {
scroller.triggerScroll({ scrollTop: 0, scrollHeight: 700, viewportHeight: 200 })
viewport.triggerResize({ getBoundingClientRect: () => ({ height: 700 }) })
})

expect(listParent.children).toHaveLength(1)
expect(listParent.textContent).toBe('Item 10')
})

describe('data list', () => {
let scroller: any
let viewport: any
Expand Down

0 comments on commit 483654f

Please sign in to comment.