Skip to content

Commit

Permalink
fix: initialScrollTop not working w/o initialItemCount
Browse files Browse the repository at this point in the history
Fixes #883
  • Loading branch information
petyosi committed Apr 18, 2023
1 parent b40f11c commit 42c8a03
Show file tree
Hide file tree
Showing 8 changed files with 1,383 additions and 1,324 deletions.
1 change: 1 addition & 0 deletions e2e/initial-scroll-top.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test.describe('initial scroll top', () => {
})

test('starts from 50px', async ({ page }) => {
await page.waitForTimeout(100)
const scrollTop = await page.evaluate(() => {
const scroller = document.querySelectorAll('[data-test-id=virtuoso-scroller]')[0]
return scroller.scrollTop
Expand Down
1 change: 0 additions & 1 deletion examples/initial-scroll-top.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export function Example() {
return (
<Virtuoso
computeItemKey={(key) => `item-${key}`}
initialItemCount={30}
totalCount={100}
initialScrollTop={50}
itemContent={(index) => <div style={{ height: 30 }}>Item {index}</div>}
Expand Down
1 change: 0 additions & 1 deletion examples/initial-topmost-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useState } from 'react'
import { IndexLocationWithAlign, Virtuoso } from '../src'
import { IndexLocation } from '../src/scrollToIndexSystem'

// @ts-expect-error I know
globalThis['VIRTUOSO_LOG_LEVEL'] = 0

const itemContent = (index: number) => <div style={{ height: index % 2 ? 30 : 20, background: 'white' }}>Item {index}</div>
Expand Down
51 changes: 51 additions & 0 deletions examples/iti-multiple.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as React from 'react'
import { Virtuoso } from '../src'

const itemContent = (index: number) => <div style={{ height: index % 2 ? 30 : 20, background: 'white' }}>Item {index}</div>

export function App() {
const data = Array(50)
.fill(undefined)
.map((_, i) => i);

return (
<div className="App">
<div style={{ display: "flex", flexDirection: "row", gap: 10 }}>
{Array(20)
.fill(undefined)
.map((_, i) => (
<Virtuoso
key={i}
style={{
flex: 1,
height: 400,
border: "2px black solid",
}}
data={data}
itemContent={(_, i) => (
<div
style={{ backgroundColor: i == 0 ? "red" : "transparent" }}
>
{i}
</div>
)}
//initialScrollTop={200}
initialTopMostItemIndex={5}
/>
))}
</div>
</div>
);
}
export function Example() {

return (
<>
<div style={{ display: 'flex', flexDirection: 'row', height: 400}}>
{Array.from({length: 30}).map((_, key) => {
return <Virtuoso key={key} totalCount={100} itemContent={itemContent} initialTopMostItemIndex={20} style={{ height: 300, minWidth: '3rem', fontSize: '7px', flex: 1 }} />
})}
</div>
</>
)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"vite": "^4.0.0",
"vitest": "^0.26.2"
},
"packageManager": "pnpm@7.21.0",
"packageManager": "pnpm@8.3.0",
"resolutions": {
"@types/react": "^16.14.2"
},
Expand Down
Loading

0 comments on commit 42c8a03

Please sign in to comment.