Skip to content

fix: disable pagination nav buttons correctly #10561

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

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: rename prop for clarity
  • Loading branch information
Parkreiner committed Nov 7, 2023
commit efd5cf1d81b9af8aa78750f7a454c9236f7ab383
22 changes: 13 additions & 9 deletions site/src/components/PaginationWidget/PaginationWidgetBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export type PaginationWidgetBaseProps = {

export const PaginationWidgetBase = ({
count,
page,
limit,
onChange,
page: currentPage,
}: PaginationWidgetBaseProps): JSX.Element | null => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
Expand All @@ -27,8 +27,8 @@ export const PaginationWidgetBase = ({
return null;
}

const isFirstPage = page <= 1;
const isLastPage = page >= numPages;
const isFirstPage = currentPage <= 1;
const isLastPage = currentPage >= numPages;

return (
<div
Expand All @@ -48,21 +48,25 @@ export const PaginationWidgetBase = ({
disabled={isFirstPage}
onClick={() => {
if (!isFirstPage) {
onChange(page - 1);
onChange(currentPage - 1);
}
}}
>
<KeyboardArrowLeft />
</Button>
{isMobile ? (
<PageButton activePage={page} page={page} numPages={numPages} />
<PageButton
activePage={currentPage}
page={currentPage}
numPages={numPages}
/>
) : (
buildPagedList(numPages, page).map((pageItem) => {
buildPagedList(numPages, currentPage).map((pageItem) => {
if (pageItem === "left" || pageItem === "right") {
return (
<PageButton
key={pageItem}
activePage={page}
activePage={currentPage}
placeholder="..."
disabled
/>
Expand All @@ -73,7 +77,7 @@ export const PaginationWidgetBase = ({
<PageButton
key={pageItem}
page={pageItem}
activePage={page}
activePage={currentPage}
numPages={numPages}
onPageClick={() => onChange(pageItem)}
/>
Expand All @@ -85,7 +89,7 @@ export const PaginationWidgetBase = ({
disabled={isLastPage}
onClick={() => {
if (!isLastPage) {
onChange(page + 1);
onChange(currentPage + 1);
}
}}
>
Expand Down