Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : Scroll to Top on Page Change #86

Merged
merged 3 commits into from
Oct 30, 2024
Merged
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
17 changes: 17 additions & 0 deletions src/components/Pagination/PaginationButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { Icon } from '@iconify-icon/react';
import { useMemo, FC, MouseEvent } from 'react';


// scroll to top while navigating through web-pages
function scroll() {
if (window.innerWidth <= 430 && window.innerWidth >= 330) {
window.scrollTo({ top: 730, behavior: 'smooth' });
} else if (window.innerWidth <= 330) {
window.scrollTo({ top: 830, behavior: 'smooth' });
} else {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
}

interface Props {
item?: { label: number; isClickable?: boolean };
type?: 'prev' | 'next';
Expand Down Expand Up @@ -29,12 +41,17 @@ const PaginationButton: FC<Props> = ({
if (disable) return;
if (!type) {
onChange(+e.currentTarget.id);
scroll();

return;
}
if (type === 'prev') {
onChange(currentPage - 1);
scroll();

} else if (type === 'next') {
onChange(currentPage + 1);
scroll();
}
};

Expand Down
Loading