Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions packages/mui-material/src/usePagination/usePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,32 @@ export default function usePagination(props = {}) {
const itemList = [
...(showFirstButton ? ['first'] : []),
...(hidePrevButton ? [] : ['previous']),
...startPages,
...(boundaryCount === 0 && siblingCount === 0
? [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'] : []),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
Loading