Skip to content

Commit

Permalink
fix(Pagination): ellipsis should separate at least 2 pages (#647)
Browse files Browse the repository at this point in the history
* feat(Pagination): ellipsis should separate at least 2 pages

* test: update after ellipsis behaviour changes

* chore: rename test

---------

Co-authored-by: zernonia <zernonia@gmail.com>
  • Loading branch information
andreww2012 and zernonia committed Feb 1, 2024
1 parent f35a3ae commit db923ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions packages/radix-vue/src/Pagination/Pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ describe('given show-edges Pagination', () => {
await wrapper.find('[aria-label="Page 5"]').trigger('click')
})

it('should have default 2 siblings on each side', () => {
expect(wrapper.find('[aria-label="Page 2"]').exists()).toBe(false)
it('should have page 2', () => {
expect(wrapper.find('[aria-label="Page 2"]').exists()).toBe(true)
expect(wrapper.find('[aria-label="Page 3"]').exists()).toBe(true)
expect(wrapper.find('[aria-label="Page 4"]').exists()).toBe(true)
})

it('should not have page 8', () => {
expect(wrapper.find('[aria-label="Page 6"]').exists()).toBe(true)
expect(wrapper.find('[aria-label="Page 7"]').exists()).toBe(true)
expect(wrapper.find('[aria-label="Page 8"]').exists()).toBe(false)
})

it('should have left right ellipsis', () => {
expect(wrapper.findAll('[data-type="ellipsis"]').length).toBe(2)
it('should have right ellipsis', () => {
expect(wrapper.findAll('[data-type="ellipsis"]').length).toBe(1)
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/radix-vue/src/Pagination/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function getRange(currentPage: number, pageCount: number, siblingCount: n
const leftSiblingIndex = Math.max(currentPage - siblingCount, firstPageIndex)
const rightSiblingIndex = Math.min(currentPage + siblingCount, lastPageIndex)

const showLeftEllipsis = leftSiblingIndex > firstPageIndex + 1
const showRightEllipsis = rightSiblingIndex < lastPageIndex - 1
const showLeftEllipsis = leftSiblingIndex > firstPageIndex + 2
const showRightEllipsis = rightSiblingIndex < lastPageIndex - 2

if (showEdges) {
/**
Expand Down

0 comments on commit db923ef

Please sign in to comment.