Skip to content

Commit 22aa446

Browse files
committed
WIP
1 parent 3c75978 commit 22aa446

File tree

2 files changed

+55
-45
lines changed

2 files changed

+55
-45
lines changed

packages/react-virtual/e2e/app/main.tsx

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,46 @@ const App = () => {
2929
})
3030

3131
return (
32-
<div
33-
ref={parentRef}
34-
id="scroll-container"
35-
style={{ height: 400, overflow: 'auto' }}
36-
>
37-
<div
38-
style={{ height: rowVirtualizer.getTotalSize(), position: 'relative' }}
39-
>
40-
{rowVirtualizer.getVirtualItems().map((v) => (
41-
<div
42-
key={v.key}
43-
data-testid={`item-${v.index}`}
44-
ref={rowVirtualizer.measureElement}
45-
data-index={v.index}
46-
style={{
47-
position: 'absolute',
48-
top: 0,
49-
left: 0,
50-
transform: `translateY(${v.start}px)`,
51-
width: '100%',
52-
}}
53-
>
54-
<div style={{ height: randomHeight(String(v.key)) }}>
55-
Row {v.index}
56-
</div>
57-
</div>
58-
))}
59-
</div>
32+
<div>
6033
<button
6134
id="scroll-to-1000"
6235
onClick={() => rowVirtualizer.scrollToIndex(1000)}
6336
>
6437
Scroll to 1000
6538
</button>
39+
40+
<div
41+
ref={parentRef}
42+
id="scroll-container"
43+
style={{ height: 400, overflow: 'auto' }}
44+
>
45+
<div
46+
style={{
47+
height: rowVirtualizer.getTotalSize(),
48+
position: 'relative',
49+
}}
50+
>
51+
{rowVirtualizer.getVirtualItems().map((v) => (
52+
<div
53+
key={v.key}
54+
data-testid={`item-${v.index}`}
55+
ref={rowVirtualizer.measureElement}
56+
data-index={v.index}
57+
style={{
58+
position: 'absolute',
59+
top: 0,
60+
left: 0,
61+
transform: `translateY(${v.start}px)`,
62+
width: '100%',
63+
}}
64+
>
65+
<div style={{ height: randomHeight(String(v.key)) }}>
66+
Row {v.index}
67+
</div>
68+
</div>
69+
))}
70+
</div>
71+
</div>
6672
</div>
6773
)
6874
}
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
import { expect, test } from '@playwright/test'
22

3-
test('scrolls to index 1000', async ({ page }) => {
4-
await page.goto('/')
5-
await page.waitForSelector('#scroll-to-1000', { state: 'visible' })
6-
await page.click('#scroll-to-1000')
3+
const check = () => {
4+
const item = document.querySelector('[data-testid="item-1000"]')
5+
const container = document.querySelector('#scroll-container')
6+
7+
if (!item || !container) throw new Error('Elements not found')
78

8-
const delta = await page.evaluate(() => {
9-
const item = document.querySelector('[data-testid="item-1000"]')
10-
const container = document.querySelector('#scroll-container')
9+
const itemRect = item.getBoundingClientRect()
10+
const containerRect = container.getBoundingClientRect()
11+
const scrollTop = container.scrollTop
1112

12-
if (!item || !container) throw new Error('Elements not found')
13+
const top = itemRect.top + scrollTop - containerRect.top
14+
const botttom = top + itemRect.height
1315

14-
const itemRect = item.getBoundingClientRect()
15-
const containerRect = container.getBoundingClientRect()
16-
const scrollTop = container.scrollTop
16+
const containerBottom = scrollTop + container.clientHeight
1717

18-
const top = itemRect.top + scrollTop - containerRect.top
19-
const botttom = top + itemRect.height
18+
return Math.abs(botttom - containerBottom)
19+
}
2020

21-
const containerBottom = scrollTop + container.clientHeight
21+
test('scrolls to index 1000', async ({ page }) => {
22+
await page.goto('/')
23+
await page.click('#scroll-to-1000')
2224

23-
return Math.abs(botttom - containerBottom)
24-
})
25-
console.log('delta:', delta)
25+
// Wait for scroll effect (including retries)
26+
await page.waitForTimeout(1000)
2627

2728
await expect(page.locator('[data-testid="item-1000"]')).toBeVisible()
29+
30+
const delta = await page.evaluate(check)
31+
console.log('bootom element detla', delta)
2832
})

0 commit comments

Comments
 (0)