Skip to content

Commit

Permalink
fix(b-pagination): properly calculate number of links with `hide-elli…
Browse files Browse the repository at this point in the history
…psis` option (closes #5514) (#5678)

* fix(b-pagination): properly calculate number of links with `hide-ellipsis` option

* Update pagination.spec.js
  • Loading branch information
jacobmllr95 authored Aug 22, 2020
1 parent 31c06b5 commit 98e17ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
19 changes: 19 additions & 0 deletions src/components/pagination/pagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,25 @@ describe('pagination', () => {
wrapper.destroy()
})

it('has correct number of links when `hide-ellipsis` is enabled', async () => {
const wrapper = mount(BPagination, {
propsData: {
hideEllipsis: true,
totalRows: 100,
perPage: 10,
value: 1
}
})
expect(wrapper.element.tagName).toBe('UL')
expect(wrapper.findAll('li').length).toBe(9)

await wrapper.setProps({ value: 5 })
await waitNT(wrapper.vm)
expect(wrapper.findAll('li').length).toBe(9)

wrapper.destroy()
})

it('has attribute aria-controls on page links when prop aria-controls is set', async () => {
const wrapper = mount(BPagination, {
propsData: {
Expand Down
16 changes: 9 additions & 7 deletions src/mixins/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,14 @@ export default {
},
paginationParams() {
// Determine if we should show the the ellipsis
const limit = this.localLimit
const numberOfPages = this.localNumberOfPages
const currentPage = this.computedCurrentPage
const hideEllipsis = this.hideEllipsis
const firstNumber = this.firstNumber
const lastNumber = this.lastNumber
const {
localLimit: limit,
localNumberOfPages: numberOfPages,
computedCurrentPage: currentPage,
hideEllipsis,
firstNumber,
lastNumber
} = this
let showFirstDots = false
let showLastDots = false
let numberOfLinks = limit
Expand All @@ -252,7 +254,7 @@ export default {
} else {
// We are somewhere in the middle of the page list
if (limit > ELLIPSIS_THRESHOLD) {
numberOfLinks = limit - 2
numberOfLinks = limit - (hideEllipsis ? 0 : 2)
showFirstDots = !!(!hideEllipsis || firstNumber)
showLastDots = !!(!hideEllipsis || lastNumber)
}
Expand Down

0 comments on commit 98e17ca

Please sign in to comment.