diff --git a/src/Pagination.tsx b/src/Pagination.tsx index 452203d4..3ab4124b 100644 --- a/src/Pagination.tsx +++ b/src/Pagination.tsx @@ -486,13 +486,27 @@ const Pagination: React.FC = (props) => { left = allPages - pageBufferSize * 2; } + const hasJumpPrev = + !!jumpPrev && current - 1 >= pageBufferSize * 2 && current !== 1 + 2; + const hasJumpNext = + !!jumpNext && + allPages - current >= pageBufferSize * 2 && + current !== allPages - 2; + + if (!showLessItems && hasJumpPrev && right !== allPages) { + left += 1; + } + if (!showLessItems && hasJumpNext && left !== 1) { + right -= 1; + } + for (let i = left; i <= right; i += 1) { pagerList.push( , ); } - if (current - 1 >= pageBufferSize * 2 && current !== 1 + 2) { + if (hasJumpPrev) { pagerList[0] = React.cloneElement(pagerList[0], { className: clsx( `${prefixCls}-item-after-jump-prev`, @@ -503,7 +517,7 @@ const Pagination: React.FC = (props) => { pagerList.unshift(jumpPrev); } - if (allPages - current >= pageBufferSize * 2 && current !== allPages - 2) { + if (hasJumpNext) { const lastOne = pagerList[pagerList.length - 1]; pagerList[pagerList.length - 1] = React.cloneElement(lastOne, { className: clsx( diff --git a/tests/__snapshots__/demo.test.tsx.snap b/tests/__snapshots__/demo.test.tsx.snap index 19d64736..216c4b98 100644 --- a/tests/__snapshots__/demo.test.tsx.snap +++ b/tests/__snapshots__/demo.test.tsx.snap @@ -1550,18 +1550,7 @@ exports[`Example jumper 1`] = ` />
  • - - 3 - -
  • -
  • @@ -1583,7 +1572,7 @@ exports[`Example jumper 1`] = `
  • @@ -1593,17 +1582,6 @@ exports[`Example jumper 1`] = ` 6
  • -
  • - - 7 - -
  • - - 3 - -
  • -
  • @@ -1768,7 +1735,7 @@ exports[`Example jumper 1`] = `
  • @@ -1778,17 +1745,6 @@ exports[`Example jumper 1`] = ` 6
  • -
  • - - 7 - -
  • - - 3 - -
  • -
  • @@ -2130,7 +2075,7 @@ exports[`Example jumperWithGoButton 1`] = `
  • @@ -2140,17 +2085,6 @@ exports[`Example jumperWithGoButton 1`] = ` 6
  • -
  • - - 7 - -
  • - - 3 - -
  • -
  • @@ -2672,7 +2595,7 @@ exports[`Example locale 1`] = `
  • @@ -2682,17 +2605,6 @@ exports[`Example locale 1`] = ` 6
  • -
  • - - 7 - -
  • { }); }); + describe('pager item count', () => { + const getPagerItems = (container: HTMLElement) => + container.querySelectorAll( + 'li:not(.rc-pagination-prev):not(.rc-pagination-next):not(.rc-pagination-options)', + ); + const currentList = [1, 2, 3, 4, 5, 6, 50, 95, 96, 97, 98, 99, 100]; + + it('should keep pager item count when jumpers appear', () => { + currentList.forEach((current) => { + const { container, unmount } = render( + , + ); + + expect(getPagerItems(container)).toHaveLength(7); + unmount(); + }); + }); + }); + describe('hideOnSinglePage props', () => { const itemRender = (current) => {current};