Skip to content

Commit 8d1724a

Browse files
clive107johnleider
authored andcommitted
fix(VPagination): fix v-pagination misbehavior (#3636) (#4651)
1 parent ccedbd3 commit 8d1724a

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed

src/components/VPagination/VPagination.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default {
6363
const left = Math.floor(maxLength / 2)
6464
const right = this.length - left + 1 + even
6565

66-
if (this.value >= left && this.value <= right) {
66+
if (this.value > left && this.value < right) {
6767
const start = this.value - left + 2
6868
const end = this.value + left - 2 - even
6969

test/unit/components/VPagination/VPagination.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,46 @@ test('VPagination.vue', ({ mount }) => {
127127
expect(wrapper.find('.v-pagination__more').length).toEqual(2)
128128
})
129129

130+
it('should only render start and end of range if value is equals "left"', async () => {
131+
jest.useFakeTimers()
132+
const wrapper = mount(VPagination, {
133+
propsData: {
134+
length: 100,
135+
totalVisible: 5
136+
}
137+
})
138+
const maxLength = wrapper.vm.totalVisible
139+
const left = Math.floor(maxLength / 2)
140+
wrapper.setProps({ value: left })
141+
jest.runAllTimers()
142+
143+
await wrapper.vm.$nextTick()
144+
145+
expect(wrapper.html()).toMatchSnapshot()
146+
expect(wrapper.find('.v-pagination__more').length).toEqual(1)
147+
})
148+
149+
it('should only render start and end of range if value is equals "right"', async () => {
150+
jest.useFakeTimers()
151+
const wrapper = mount(VPagination, {
152+
propsData: {
153+
length: 100,
154+
totalVisible: 5
155+
}
156+
})
157+
const maxLength = wrapper.vm.totalVisible
158+
const even = maxLength % 2 === 0 ? 1 : 0
159+
const left = Math.floor(maxLength / 2)
160+
const right = wrapper.vm.length - left + 1 + even
161+
wrapper.setProps({ value: right })
162+
jest.runAllTimers()
163+
164+
await wrapper.vm.$nextTick()
165+
166+
expect(wrapper.html()).toMatchSnapshot()
167+
expect(wrapper.find('.v-pagination__more').length).toEqual(1)
168+
})
169+
130170
it('should use totalVisible prop if defined', async () => {
131171
jest.useFakeTimers()
132172
const wrapper = mount(VPagination, {

test/unit/components/VPagination/__snapshots__/VPagination.spec.js.snap

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,106 @@ exports[`VPagination.vue should only render start and end of range if length is
320320
321321
`;
322322

323+
exports[`VPagination.vue should only render start and end of range if value is equals "left" 1`] = `
324+
325+
<ul class="v-pagination">
326+
<li>
327+
<button class="v-pagination__navigation">
328+
<i aria-hidden="true"
329+
class="v-icon material-icons"
330+
>
331+
chevron_left
332+
</i>
333+
</button>
334+
</li>
335+
<li>
336+
<button class="v-pagination__item">
337+
1
338+
</button>
339+
</li>
340+
<li>
341+
<button class="v-pagination__item v-pagination__item--active primary">
342+
2
343+
</button>
344+
</li>
345+
<li>
346+
<span class="v-pagination__more">
347+
...
348+
</span>
349+
</li>
350+
<li>
351+
<button class="v-pagination__item">
352+
99
353+
</button>
354+
</li>
355+
<li>
356+
<button class="v-pagination__item">
357+
100
358+
</button>
359+
</li>
360+
<li>
361+
<button class="v-pagination__navigation">
362+
<i aria-hidden="true"
363+
class="v-icon material-icons"
364+
>
365+
chevron_right
366+
</i>
367+
</button>
368+
</li>
369+
</ul>
370+
371+
`;
372+
373+
exports[`VPagination.vue should only render start and end of range if value is equals "right" 1`] = `
374+
375+
<ul class="v-pagination">
376+
<li>
377+
<button class="v-pagination__navigation">
378+
<i aria-hidden="true"
379+
class="v-icon material-icons"
380+
>
381+
chevron_left
382+
</i>
383+
</button>
384+
</li>
385+
<li>
386+
<button class="v-pagination__item">
387+
1
388+
</button>
389+
</li>
390+
<li>
391+
<button class="v-pagination__item">
392+
2
393+
</button>
394+
</li>
395+
<li>
396+
<span class="v-pagination__more">
397+
...
398+
</span>
399+
</li>
400+
<li>
401+
<button class="v-pagination__item v-pagination__item--active primary">
402+
99
403+
</button>
404+
</li>
405+
<li>
406+
<button class="v-pagination__item">
407+
100
408+
</button>
409+
</li>
410+
<li>
411+
<button class="v-pagination__navigation">
412+
<i aria-hidden="true"
413+
class="v-icon material-icons"
414+
>
415+
chevron_right
416+
</i>
417+
</button>
418+
</li>
419+
</ul>
420+
421+
`;
422+
323423
exports[`VPagination.vue should render component in RTL mode and match snapshot 1`] = `
324424
325425
<ul class="v-pagination">

0 commit comments

Comments
 (0)