-
-
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(): tall items collapse correctly close to bottom
- Loading branch information
Showing
16 changed files
with
306 additions
and
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe('list with scroll seek placeholders', () => { | ||
beforeEach(async () => { | ||
await page.goto('http://localhost:1234/collapsible-long-item') | ||
await page.waitForSelector('#test-root div') | ||
await page.waitForTimeout(100) | ||
}) | ||
|
||
it('compensates correctly when collapsing an item', async () => { | ||
await page.evaluate(() => { | ||
const scroller = document.querySelector('#test-root > div')! | ||
scroller.scrollBy({ top: -400 }) | ||
}) | ||
|
||
await page.waitForTimeout(200) | ||
|
||
await page.evaluate(() => { | ||
const button = document.querySelector('[data-index="90"] button') as HTMLButtonElement | ||
button.click() | ||
}) | ||
|
||
await page.waitForTimeout(200) | ||
|
||
const scrollTop = await page.evaluate(() => { | ||
const scroller = document.querySelector('#test-root > div')! | ||
return scroller.scrollTop | ||
}) | ||
|
||
expect(scrollTop).toBe(9200) | ||
}) | ||
}) |
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,45 @@ | ||
import * as React from 'react' | ||
import { Virtuoso } from '../src' | ||
|
||
const Expanded = React.createContext([ | ||
false, | ||
(_val: boolean) => { | ||
void _val | ||
}, | ||
] as const) | ||
|
||
const Item = ({ index }: { index: number }) => { | ||
const [expanded, setExpanded] = React.useContext(Expanded) | ||
|
||
return ( | ||
<div style={{ border: '1px solid black', height: index === 90 && !expanded ? 600 : 100, display: 'flex', flexDirection: 'row' }}> | ||
<div style={{ flex: 1 }}>Item {index}</div> | ||
<button | ||
onClick={() => { | ||
setExpanded(!expanded) | ||
}} | ||
> | ||
Toggle | ||
</button> | ||
</div> | ||
) | ||
} | ||
|
||
const ExpandedProvider: React.FC = ({ children }) => { | ||
const [expanded, setExpanded] = React.useState(false) | ||
return <Expanded.Provider value={[expanded as any, setExpanded]}>{children}</Expanded.Provider> | ||
} | ||
|
||
export default function App() { | ||
return ( | ||
<ExpandedProvider> | ||
<Virtuoso | ||
initialTopMostItemIndex={99} | ||
followOutput={true} | ||
totalCount={100} | ||
itemContent={(index) => <Item index={index} />} | ||
style={{ height: 600 }} | ||
/> | ||
</ExpandedProvider> | ||
) | ||
} |
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
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
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
Oops, something went wrong.
9665bf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @petyosi ,
You forgot a few console.log in this PR. :)
Thx for the continuous hard work. Happy Christmas to you
9665bf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ethorsen thanks for spotting that, pushed a fix. Happy holidays to you too.