-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(): no jump with float item height and itmi
Fixes #446 itmi = initialTopMostItemIndex prop
- Loading branch information
Showing
7 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
describe('list with a long last item', () => { | ||
beforeEach(async () => { | ||
await page.goto('http://localhost:1234/test-case-446') | ||
await page.waitForSelector('#test-root') | ||
await page.waitForTimeout(300) | ||
}) | ||
|
||
// the float height was causing a load of item 9 | ||
it('starts from item with index 10', async () => { | ||
const firstItemIndex = await page.evaluate(() => { | ||
const listContainer = document.querySelector('[data-test-id=virtuoso-item-list]')! | ||
return (listContainer as HTMLElement).firstElementChild!.getAttribute('data-item-index') | ||
}) | ||
expect(firstItemIndex).toBe('10') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as React from 'react' | ||
import { useState } from 'react' | ||
import { Virtuoso } from '../src' | ||
|
||
const itemContent = (index: number, note: { content: string }) => ( | ||
<div style={{ height: index % 2 ? 70.3 : 30.6, background: 'white' }}>{note.content}</div> | ||
) | ||
// globalThis['VIRTUOSO_LOG_LEVEL'] = 0 | ||
|
||
const notes: Array<ReturnType<typeof note>> = [] | ||
function note(index: number) { | ||
return { | ||
index: index + 1, | ||
content: `Note ${index}`, | ||
} | ||
} | ||
|
||
export const getNote = (index: number) => { | ||
if (!notes[index]) { | ||
notes[index] = note(index) | ||
} | ||
|
||
return notes[index] | ||
} | ||
|
||
const generateNotes = (length: number, startIndex = 0) => { | ||
return Array.from({ length }).map((_, i) => getNote(i + startIndex)) | ||
} | ||
|
||
const START_INDEX = 10000 | ||
const INITIAL_ITEM_COUNT = 20 | ||
|
||
export default function App() { | ||
const [topMostItemIndex, setTopMostItemIndex] = useState(10) | ||
const [notes] = useState(() => generateNotes(INITIAL_ITEM_COUNT, START_INDEX)) | ||
|
||
return ( | ||
<div> | ||
<button onClick={() => setTopMostItemIndex(() => 3)}>Topmost index = 3</button> | ||
<button onClick={() => setTopMostItemIndex(() => 7)}>Topmost index = 7</button> | ||
<Virtuoso data={notes} itemContent={itemContent} initialTopMostItemIndex={topMostItemIndex} style={{ height: 300 }} /> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export function correctItemSize(el: HTMLElement, dimension: 'height' | 'width') { | ||
return el.getBoundingClientRect()[dimension] | ||
return Math.round(el.getBoundingClientRect()[dimension]) | ||
} |