Skip to content

Commit 1394b6c

Browse files
dmitriytatdsseng
authored andcommitted
fix(VPagination): max length (#9423)
* fix(VPagination): max length * test(VPagination): add more length cases
1 parent 2283635 commit 1394b6c

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

packages/vuetify/src/components/VPagination/VPagination.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ export default mixins(Colorable, Themeable).extend({
6161

6262
items (): (string | number)[] {
6363
const totalVisible = parseInt(this.totalVisible, 10)
64-
const maxLength = totalVisible > this.maxButtons
65-
? this.maxButtons
66-
: totalVisible || this.maxButtons
6764

68-
if (this.length <= maxLength || maxLength < 1) {
65+
const maxLength = Math.min(
66+
Math.max(0, totalVisible) || this.length,
67+
Math.max(0, this.maxButtons) || this.length,
68+
this.length
69+
)
70+
71+
if (this.length <= maxLength) {
6972
return this.range(1, this.length)
7073
}
7174

packages/vuetify/src/components/VPagination/__tests__/VPagination.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,35 @@ describe('VPagination.ts', () => {
244244
expect(wrapper.vm.items).toHaveLength(10)
245245
})
246246

247+
it('should never show more than the number of total visible buttons', () => {
248+
const wrapper = mountFunction({
249+
data: () => ({
250+
maxButtons: 0,
251+
}),
252+
253+
propsData: {
254+
length: 5,
255+
totalVisible: undefined,
256+
},
257+
})
258+
259+
expect(wrapper.vm.items).toHaveLength(5)
260+
261+
wrapper.setProps({ length: 40 })
262+
263+
wrapper.setData({ maxButtons: 0 })
264+
wrapper.setProps({ totalVisible: 10 })
265+
expect(wrapper.vm.items).toHaveLength(10)
266+
267+
wrapper.setData({ maxButtons: 11 })
268+
wrapper.setProps({ totalVisible: undefined })
269+
expect(wrapper.vm.items).toHaveLength(11)
270+
271+
wrapper.setData({ maxButtons: 12 })
272+
wrapper.setProps({ totalVisible: 13 })
273+
expect(wrapper.vm.items).toHaveLength(12)
274+
})
275+
247276
it('should return length when maxButtons is less than 1', () => {
248277
const wrapper = mountFunction({
249278
data: () => ({ maxButtons: -3 }),

0 commit comments

Comments
 (0)