From cd6b2a1858bc32ea2a0ff3f4b0124ae2b055d738 Mon Sep 17 00:00:00 2001 From: MariaAga Date: Fri, 26 May 2023 17:43:38 +0200 Subject: [PATCH] fix(Pagination): default page should be 1 --- .../src/components/Pagination/Pagination.tsx | 11 ++--- .../__snapshots__/Pagination.test.tsx.snap | 44 +++++++++---------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/packages/react-core/src/components/Pagination/Pagination.tsx b/packages/react-core/src/components/Pagination/Pagination.tsx index c531367358e..13171adb983 100644 --- a/packages/react-core/src/components/Pagination/Pagination.tsx +++ b/packages/react-core/src/components/Pagination/Pagination.tsx @@ -210,8 +210,8 @@ export const Pagination: React.FunctionComponent = ({ ofWord: 'of' }, firstPage = 1, - page: pageProp = 0, - offset = 0, + page: pageProp = 1, + offset = null, isLastFullPageShown = false, itemsStart = null, itemsEnd = null, @@ -245,11 +245,8 @@ export const Pagination: React.FunctionComponent = ({ const dropDirection = dropDirectionProp || (variant === 'bottom' && !isStatic ? 'up' : 'down'); let page = pageProp; - if (!page && offset) { - page = Math.ceil(offset / perPage); - } - if (page === 0 && !itemCount) { - page = 1; + if (offset !== null) { + page = Math.max(Math.ceil(offset / perPage), 1); } const lastPage = getLastPage(); diff --git a/packages/react-core/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap b/packages/react-core/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap index b9ba9e31904..857e57778df 100644 --- a/packages/react-core/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +++ b/packages/react-core/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap @@ -1159,7 +1159,7 @@ exports[`Pagination component render custom pagination toggle 1`] = `
- -9 - 10 - 40 - + 1 - 10 - 40 -