Skip to content

Commit 3bea297

Browse files
committed
fix(VPagination): predictable length behavior in flex container
fixes #22907
1 parent 8d5d16a commit 3bea297

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/vuetify/src/components/VPagination/VPagination.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ export const VPagination = genericComponent<VPaginationSlots>()({
190190
const range = computed(() => {
191191
if (length.value <= 0 || isNaN(length.value) || length.value > Number.MAX_SAFE_INTEGER) return []
192192

193+
if (props.totalVisible == null && length.value < 3) {
194+
return createRange(length.value, start.value)
195+
}
196+
193197
if (totalVisible.value <= 0) return []
194198
else if (totalVisible.value === 1) return [page.value]
195199

packages/vuetify/src/components/VPagination/__tests__/VPagination.spec.browser.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { VPagination } from '../VPagination'
33
import { VLocaleProvider } from '@/components/VLocaleProvider'
44

55
// Utilities
6-
import { page, render, screen, showcase, userEvent } from '@test'
6+
import { page, render, screen, showcase, userEvent, waitIdle } from '@test'
77
import { ref } from 'vue'
88

99
const stories = {
@@ -23,6 +23,30 @@ describe('VPagination', () => {
2323
expect(screen.getAllByCSS('.v-pagination__item')).toHaveLength(3)
2424
})
2525

26+
it('should render all pages when length is less than 3 in a flexbox container', async () => {
27+
render(() => (
28+
<div class="d-flex">
29+
<VPagination length="2" />
30+
</div>
31+
))
32+
33+
await waitIdle() // resize-observer loop has to settle
34+
35+
expect(screen.getAllByCSS('.v-pagination__item')).toHaveLength(2)
36+
expect(screen.getAllByCSS('.v-pagination__item .v-btn').at(0)).toHaveTextContent('1')
37+
expect(screen.getAllByCSS('.v-pagination__item .v-btn').at(1)).toHaveTextContent('2')
38+
})
39+
40+
it('should still honor an explicit total-visible when length is less than 3', () => {
41+
render(() => (
42+
<div class="d-flex">
43+
<VPagination length="2" totalVisible="1" />
44+
</div>
45+
))
46+
47+
expect(screen.getAllByCSS('.v-pagination__item')).toHaveLength(1)
48+
})
49+
2650
it('should react to mouse navigation', async () => {
2751
render(() => (
2852
<VPagination length="3" />

0 commit comments

Comments
 (0)