Skip to content

Commit

Permalink
feat: add scroll to top on pagination click
Browse files Browse the repository at this point in the history
  • Loading branch information
stardustmeg committed Jun 7, 2024
1 parent 3771c7a commit 461a012
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/features/Pagination/view/PaginationView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PaginationView {
} else {
this.callback(String(DEFAULT_PAGE + DEFAULT_PAGE));
}
this.scrollToTop();
});

return this.nextPageButton;
Expand All @@ -67,7 +68,10 @@ class PaginationView {
text: page.toString(),
});

btn.getHTML().addEventListener('click', () => this.callback(page.toString()));
btn.getHTML().addEventListener('click', () => {
this.callback(page.toString());
this.scrollToTop();
});

this.pageButtons.push(btn);

Expand All @@ -85,6 +89,7 @@ class PaginationView {
if (currentPage) {
this.callback(String(Number(currentPage) - DEFAULT_PAGE));
}
this.scrollToTop();
});
return this.prevPageButton;
}
Expand All @@ -100,6 +105,12 @@ class PaginationView {
}
}

private scrollToTop(): void {
if (window.scrollY !== 0) {
window.scrollTo({ top: 0 });
}
}

private switchStateNavigationButtons(page: number): void {
this.prevPageButton.getHTML().disabled = page === DEFAULT_PAGE;
this.nextPageButton.getHTML().disabled = page === this.pageButtons.length;
Expand Down

1 comment on commit 461a012

@stardustmeg
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.