Skip to content

Commit

Permalink
fix(Pagination): set pageCount minimal value is 1 (#857)
Browse files Browse the repository at this point in the history
* fix(pagination): set pageCount minimal value is 1

* fix(pagination): add test cases for scenario that total value is 0
  • Loading branch information
preflower authored Apr 19, 2024
1 parent 0037f03 commit 862a2ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/radix-vue/src/Pagination/Pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,27 @@ describe('given small total value', () => {
})
})
})

describe('given 0 total value', () => {
let wrapper: VueWrapper<InstanceType<typeof Pagination>>

beforeEach(() => {
document.body.innerHTML = ''
wrapper = mount(Pagination, { attachTo: document.body, props: { total: 0 } })
})

it('should pass axe accessibility tests', async () => {
expect(await axe(wrapper.element)).toHaveNoViolations()
})

it('should have first page selected by default', () => {
expect(wrapper.find('[aria-label="Page 1"]').attributes('data-selected')).toBe('true')
})

it('all button should disabled', () => {
expect(wrapper.find('[aria-label="First Page"]').attributes('disabled')).toBeDefined()
expect(wrapper.find('[aria-label="Previous Page"]').attributes('disabled')).toBeDefined()
expect(wrapper.find('[aria-label="Next Page"]').attributes('disabled')).toBeDefined()
expect(wrapper.find('[aria-label="Last Page"]').attributes('disabled')).toBeDefined()
})
})
2 changes: 1 addition & 1 deletion packages/radix-vue/src/Pagination/PaginationRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const page = useVModel(props, 'page', emits, {
passive: (props.page === undefined) as false,
}) as Ref<number>
const pageCount = computed(() => Math.ceil(props.total / props.itemsPerPage))
const pageCount = computed(() => Math.max(1, Math.ceil(props.total / props.itemsPerPage)))
providePaginationRootContext({
page,
Expand Down

0 comments on commit 862a2ac

Please sign in to comment.