diff --git a/src/gridSystem.ts b/src/gridSystem.ts index b41e1697a..c3e47a6e5 100644 --- a/src/gridSystem.ts +++ b/src/gridSystem.ts @@ -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)) } diff --git a/test/Grid.test.tsx b/test/Grid.test.tsx index 696375094..9ed1f6dcd 100644 --- a/test/Grid.test.tsx +++ b/test/Grid.test.tsx @@ -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() + }) + + 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