Skip to content

Commit

Permalink
fix: pagination sizing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Chen authored and Thomas Chen committed Jul 26, 2022
1 parent 8df85c5 commit 3e2417d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/react/src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Props extends React.HTMLAttributes<HTMLDivElement> {
onPreviousPageClick?: () => void;
onFirstPageClick?: () => void;
onLastPageClick?: () => void;
onPageSizeChange?: () => void;
tooltipPlacement?: Placement;
thin?: boolean;
className?: string;
Expand All @@ -40,6 +41,7 @@ const Pagination = React.forwardRef<HTMLDivElement, Props>(
onPreviousPageClick,
onFirstPageClick,
onLastPageClick,
onPageSizeChange,
className,
thin = false,
...other
Expand Down Expand Up @@ -174,6 +176,7 @@ Pagination.propTypes = {
onPreviousPageClick: PropTypes.func,
onFirstPageClick: PropTypes.func,
onLastPageClick: PropTypes.func,
onPageSizeChange: PropTypes.func,
// @ts-expect-error
tooltipPlacement: PropTypes.string,
className: PropTypes.string
Expand Down
8 changes: 5 additions & 3 deletions packages/react/src/components/Pagination/usePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface PaginationResults {
onPreviousPageClick: () => void;
onFirstPageClick: () => void;
onLastPageClick: () => void;
setCurrentPage: (page:number) => void;
}

// PageStatus has some built-in redundancy to prevent a user from
Expand All @@ -27,7 +28,7 @@ interface PageStatus {
export const usePagination = ({
totalItems,
initialPageSize = 10,
initialPage = 1
initialPage = 1,
}: Options): {
pagination: PaginationResults;
pageStatus: PageStatus;
Expand All @@ -36,7 +37,6 @@ export const usePagination = ({

const pageStart = currentPage * initialPageSize - initialPageSize + 1;
const pageEnd = Math.min(pageStart + initialPageSize - 1, totalItems);

const onFirstPageClick = () => setCurrentPage(1);
const onPreviousPageClick = () => setCurrentPage(currentPage - 1);
const onNextPageClick = () => setCurrentPage(currentPage + 1);
Expand All @@ -50,7 +50,8 @@ export const usePagination = ({
onFirstPageClick,
onPreviousPageClick,
onNextPageClick,
onLastPageClick
onLastPageClick,
setCurrentPage
};

const pageStatus: PageStatus = {
Expand All @@ -59,5 +60,6 @@ export const usePagination = ({
pageEnd
};


return { pagination, pageStatus };
};

0 comments on commit 3e2417d

Please sign in to comment.