From ff9c745a81b17bf94fe2d9a333215a7fb851c96c Mon Sep 17 00:00:00 2001 From: Jessie Date: Tue, 6 Aug 2019 09:07:57 -0400 Subject: [PATCH] fix(Pagination): Fix pagination to update page count (#2639) * Fix pagination to update page count * Remove comment * Fix issues with input and page selection * Update snapshots --- .../src/components/Pagination/Navigation.tsx | 10 ++++++++-- .../src/components/Pagination/Pagination.tsx | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx b/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx index 2322c5e647c..f768eac2099 100644 --- a/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx +++ b/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx @@ -29,7 +29,7 @@ export interface NavigationProps extends React.HTMLProps { paginationTitle?: string; /** The number of the current page */ page: React.ReactText; - /** Function called when user sets page */ + /** Function called when page is changed */ onSetPage: (event: React.SyntheticEvent, page: number) => void; /** Function called when user clicks to navigate to next page */ onNextClick?: (event: React.SyntheticEvent, page: number) => void; @@ -93,6 +93,12 @@ export class Navigation extends React.Component this.onKeyDown(event, page, lastPage, onPageInput, onSetPage)} diff --git a/packages/patternfly-4/react-core/src/components/Pagination/Pagination.tsx b/packages/patternfly-4/react-core/src/components/Pagination/Pagination.tsx index 6d324517681..8c8e83cc5f7 100644 --- a/packages/patternfly-4/react-core/src/components/Pagination/Pagination.tsx +++ b/packages/patternfly-4/react-core/src/components/Pagination/Pagination.tsx @@ -64,6 +64,8 @@ export interface PaginationProps extends React.HTMLProps { perPage?: number; /** Select from options to number of items per page. */ perPageOptions?: PerPageOptions[]; + /** Page we start at. */ + firstPage?: number; /** Current page number. */ page?: number; /** First index of items on current page. */ @@ -112,6 +114,7 @@ export const Pagination: React.FunctionComponent = ({ currPage: 'Current page', paginationTitle: 'Pagination' }, + firstPage = 1, page = 1, itemCount, itemsStart = null, @@ -130,6 +133,12 @@ export const Pagination: React.FunctionComponent = ({ ...props }: PaginationProps) => { const lastPage = Math.ceil(itemCount / perPage); + if (page < firstPage) { + page = firstPage; + } else if (page > lastPage) { + page = lastPage; + } + const firstIndex = itemCount <= 0 ? 0 : (page - 1) * perPage + 1; let lastIndex; if (itemCount <= 0) {