diff --git a/packages/mui-material/src/usePagination/usePagination.js b/packages/mui-material/src/usePagination/usePagination.js index 60f00c5ca9b022..e58a46583c2656 100644 --- a/packages/mui-material/src/usePagination/usePagination.js +++ b/packages/mui-material/src/usePagination/usePagination.js @@ -71,28 +71,36 @@ export default function usePagination(props = {}) { const itemList = [ ...(showFirstButton ? ['first'] : []), ...(hidePrevButton ? [] : ['previous']), - ...startPages, + ...(boundaryCount === 0 && + siblingCount === 0 && + page >= 1 && + page <= count && + (siblingsStart > boundaryCount + 2 || siblingsEnd < count - boundaryCount - 1) + ? [page] + : [ + ...startPages, - // Start ellipsis - // eslint-disable-next-line no-nested-ternary - ...(siblingsStart > boundaryCount + 2 - ? ['start-ellipsis'] - : boundaryCount + 1 < count - boundaryCount - ? [boundaryCount + 1] - : []), + // Start ellipsis + // eslint-disable-next-line no-nested-ternary + ...(siblingsStart > boundaryCount + 2 + ? ['start-ellipsis'] + : boundaryCount + 1 < count - boundaryCount + ? [boundaryCount + 1] + : []), - // Sibling pages - ...range(siblingsStart, siblingsEnd), + // Sibling pages + ...range(siblingsStart, siblingsEnd), - // End ellipsis - // eslint-disable-next-line no-nested-ternary - ...(siblingsEnd < count - boundaryCount - 1 - ? ['end-ellipsis'] - : count - boundaryCount > boundaryCount - ? [count - boundaryCount] - : []), + // End ellipsis + // eslint-disable-next-line no-nested-ternary + ...(siblingsEnd < count - boundaryCount - 1 + ? ['end-ellipsis'] + : count - boundaryCount > boundaryCount + ? [count - boundaryCount] + : []), - ...endPages, + ...endPages, + ]), ...(hideNextButton ? [] : ['next']), ...(showLastButton ? ['last'] : []), ]; diff --git a/packages/mui-material/src/usePagination/usePagination.test.js b/packages/mui-material/src/usePagination/usePagination.test.js index b72081f6587f16..c42310dc11c648 100644 --- a/packages/mui-material/src/usePagination/usePagination.test.js +++ b/packages/mui-material/src/usePagination/usePagination.test.js @@ -157,13 +157,7 @@ describe('usePagination', () => { items = renderHook(() => usePagination({ count: 11, page: 6, boundaryCount: 0, siblingCount: 0 }), ).result.current.items; - expect(serialize(items)).to.deep.equal([ - 'previous', - 'start-ellipsis', - 6, - 'end-ellipsis', - 'next', - ]); + expect(serialize(items)).to.deep.equal(['previous', 6, 'next']); items = renderHook(() => usePagination({ count: 11, page: 6, boundaryCount: 0, siblingCount: 1 }), @@ -210,7 +204,7 @@ describe('usePagination', () => { items = renderHook(() => usePagination({ count: 4, page: 1, boundaryCount: 0, siblingCount: 0 }), ).result.current.items; - expect(serialize(items)).to.deep.equal(['previous', 1, 2, 'end-ellipsis', 'next']); + expect(serialize(items)).to.deep.equal(['previous', 1, 'next']); }); it('should stay navigable without previous & next buttons', () => {