Skip to content

Commit 55f8b52

Browse files
authored
fix(VInfiniteScroll): hide side element when empty (#21749)
resolves #21705
1 parent 77b77cb commit 55f8b52

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

packages/docs/src/examples/v-infinite-scroll/status-reset.vue renamed to packages/docs/src/examples/v-infinite-scroll/misc-reset.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
<div class="d-flex ga-3 mb-2">
44
<v-chip>Server items: {{ serverItems.length }}</v-chip>
55
<v-chip>Loaded items: {{ items.length }}</v-chip>
6+
<v-spacer></v-spacer>
7+
<v-checkbox v-model="showEmptyText" hide-details="" label="show empty text"></v-checkbox>
68
</div>
7-
<v-infinite-scroll ref="scroll" height="300" side="both" @load="load">
9+
<v-infinite-scroll
10+
ref="scroll"
11+
:empty-text="showEmptyText ? 'No more records' : ''"
12+
height="300"
13+
side="both"
14+
@load="load"
15+
>
816
<template v-for="(item, index) in items" :key="index">
917
<div :class="['px-2', index % 2 === 0 ? 'bg-grey-lighten-2' : '']">
1018
Item number {{ item }}
@@ -26,6 +34,7 @@
2634
const infiniteScrollRef = useTemplateRef('scroll')
2735
2836
const items = ref([])
37+
const showEmptyText = ref(false)
2938
3039
let firstId = 0
3140
let lastId = 0
@@ -80,6 +89,7 @@
8089
data: () => {
8190
return {
8291
items: [],
92+
showEmptyText: false,
8393
serverItems: Array.from({ length: 30 }, () => ++lastId),
8494
}
8595
},

packages/docs/src/pages/en/components/infinite-scroller.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ The **error** slot is shown if the status `'error'` is returned from the `done`
144144
The `v-infinite-scroll` component exposes the `reset()` method, allowing to programatically reset the status to the default after reaching the `empty` state. This makes it possible for load to be called again.
145145
An optional 'side' parameter can also be provided to the method for cases where only one of the two sides needs to be reset.
146146

147-
<ExamplesExample file="v-infinite-scroll/status-reset" />
147+
<ExamplesExample file="v-infinite-scroll/misc-reset" />
148148

149149
### Examples
150150

packages/vuetify/src/components/VInfiniteScroll/VInfiniteScroll.sass

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use '../../styles/settings'
12
@use '../../styles/tools'
23
@use './variables' as *
34

@@ -21,9 +22,11 @@
2122
width: 100%
2223

2324
.v-infinite-scroll-intersect
25+
overflow: hidden
2426
pointer-events: none
2527
margin-top: var(--v-infinite-margin)
2628
margin-bottom: calc(var(--v-infinite-margin) * -1)
29+
2730
&:nth-child(2) // TODO: "1 of &" would be more stable if structure changes
2831
--v-infinite-margin: var(--v-infinite-margin-size, 1px)
2932
&:nth-last-child(2)
@@ -34,3 +37,10 @@
3437
display: flex
3538
justify-content: center
3639
padding: $infinite-scroll-side-padding
40+
transition-property: padding
41+
transition-duration: settings.$transition-duration-root
42+
transition-timing-function: settings.$standard-easing
43+
44+
&:empty,
45+
&:has(> div:only-child:empty)
46+
padding: 0

packages/vuetify/src/components/VInfiniteScroll/VInfiniteScroll.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ export const VInfiniteScroll = genericComponent<VInfiniteScrollSlots>()({
304304
setStatus(effectiveSide, 'ok')
305305

306306
nextTick(() => {
307-
setScrollAmount(
308-
getScrollSize() - previousScrollSize + getScrollAmount(),
309-
)
307+
if (effectiveSide !== 'end') {
308+
setScrollAmount(
309+
getScrollSize() - previousScrollSize + getScrollAmount(),
310+
)
311+
}
310312
if (props.mode !== 'manual') {
311313
nextTick(() => {
312314
// See #17475

0 commit comments

Comments
 (0)