Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/collection-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ export class CollectionBrowser
*/
private isScrollingToCell = false;

/**
* When we attempt to scroll to a page before the infinite scroller has
* been populated, this flag will be set, allowing us to complete the scroll
* once it is possible.
*/
private needsScrollToPage = false;

/**
* When page width resizes from desktop to mobile, set true to
* disable expand/collapse transition when loading.
Expand Down Expand Up @@ -1475,6 +1482,15 @@ export class CollectionBrowser
}

this.ensureAvailableTilesDisplayed();

if (
this.needsScrollToPage &&
this.currentPage &&
this.infiniteScroller?.itemCount
) {
this.needsScrollToPage = false;
this.scrollToPage(this.currentPage);
}
}

connectedCallback(): void {
Expand Down Expand Up @@ -1915,6 +1931,16 @@ export class CollectionBrowser
private scrollToPage(pageNumber: number): Promise<void> {
return new Promise(resolve => {
const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
// If the desired cell is not yet present in the infinite scroller, flag it to be
// scrolled later one ready.
if (
!this.infiniteScroller ||
this.infiniteScroller.itemCount < cellIndexToScrollTo
) {
this.needsScrollToPage = true;
return;
}

// without this setTimeout, Safari just pauses until the `fetchPage` is complete
// then scrolls to the cell
setTimeout(() => {
Expand Down
Loading