Skip to content

Commit e4f8144

Browse files
committed
fix(VPagination): predictable length behavior in flex container
fixes #22907
1 parent 78e21ef commit e4f8144

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,14 @@ export const VPagination = genericComponent<VPaginationSlots>()({
193193
const range = computed(() => {
194194
if (length.value <= 0 || isNaN(length.value) || length.value > Number.MAX_SAFE_INTEGER) return []
195195

196+
196197
if (totalVisible.value <= 0) return []
197198
else if (totalVisible.value === 1) return [page.value]
198199

199-
if (length.value <= totalVisible.value) {
200+
if (
201+
length.value <= totalVisible.value
202+
|| props.totalVisible == null && length.value < 3
203+
) {
200204
return createRange(length.value, start.value)
201205
}
202206

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ 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+
expect(screen.getAllByCSS('.v-pagination__item')).toHaveLength(2)
34+
expect(screen.getAllByCSS('.v-pagination__item .v-btn').at(0)).toHaveTextContent('1')
35+
expect(screen.getAllByCSS('.v-pagination__item .v-btn').at(1)).toHaveTextContent('2')
36+
})
37+
38+
it('should still honor an explicit total-visible when length is less than 3', () => {
39+
render(() => (
40+
<div class="d-flex">
41+
<VPagination length="2" totalVisible="1" />
42+
</div>
43+
))
44+
45+
expect(screen.getAllByCSS('.v-pagination__item')).toHaveLength(1)
46+
})
47+
2648
it('should render without first and last page buttons', () => {
2749
render(() => (
2850
<VPagination showFirstLastPage={ false } length="3" />

0 commit comments

Comments
 (0)