Skip to content
This repository was archived by the owner on Aug 2, 2024. It is now read-only.

Commit 516faaf

Browse files
fix: fd-virtualized-list now uses vue-observe-visibility to track the visibility of the footer
1 parent 7d33012 commit 516faaf

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/components/VirtualizedList/VirtualizedList.vue

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
@scroll.native="handleOnScroll"
99
>
1010
<template v-slot:after>
11-
<div ref="after">
11+
<div
12+
style="height: 10px;"
13+
ref="after"
14+
v-observe-visibility="afterVisibilityChanged"
15+
>
1216
<template v-if="isLoading">
1317
<slot name="loading">
1418
<fd-spinner v-if="isLoading" />
@@ -98,23 +102,25 @@ export default {
98102
});
99103
},
100104
methods: {
105+
afterVisibilityChanged(isVisible) {
106+
this.afterSlotVisible = isVisible;
107+
if (isVisible) {
108+
this.loadMoreItemsIfNeeded();
109+
}
110+
},
101111
loadMoreItemsIfNeeded() {
102112
const { totalItemCount, isLoading } = this;
103113
const loadingIsPossible = totalItemCount != null && !isLoading;
104114
if (!loadingIsPossible) {
105115
return;
106116
}
107117
const isNeeded =
108-
this.afterSlotIsVisible() && totalItemCount > this.items.length;
118+
this.afterSlotVisible && totalItemCount > this.items.length;
109119
if (!isNeeded) {
110120
return;
111121
}
112122
this.startToLoadMoreItems();
113123
},
114-
afterSlotIsVisible() {
115-
const { $el, $refs } = this;
116-
return $refs.after.getBoundingClientRect().top <= $el.scrollHeight;
117-
},
118124
startToLoadMoreItems(event) {
119125
if (this.loadMoreItems != null) {
120126
this.state = "loading";
@@ -157,6 +163,7 @@ export default {
157163
},
158164
data() {
159165
return {
166+
afterSlotVisible: false,
160167
state: "default",
161168
selectedId: null,
162169
items_: this.items

src/docs/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import App from "./App.vue";
44
import Router from "vue-router";
55
import DocumentationLoader from "./DocumentationLoader";
66
import VueVirtualScroller from "vue-virtual-scroller";
7+
import VueObserveVisibility from "vue-observe-visibility";
78
import { DocsRouter } from "./DocsRouter";
89
import { registerComponents } from "./components";
910
import "./main.scss";
1011

1112
Vue.config.productionTip = false;
1213
Vue.use(FundamentalVue);
1314
Vue.use(VueVirtualScroller);
15+
Vue.use(VueObserveVisibility);
1416

1517
// Register Layouts globally so that they are available by name
1618
import DefaultLayout from "./layouts/DefaultLayout.vue";

src/docs/pages/Virtualized List/0-VirtualizedList.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
<docs>
44
You can use `fd-virtualized-list` when you need to display a lot of data in a scrollable list. `fd-virtualized-list` only renders what is currently on your screen. Offscreen data is not rendered. Thus scrolling through your list should be very efficient. `fd-virtualized-list` depends on a 3rd-party (open source) library called [vue-virtual-scroller](https://github.com/Akryum/vue-virtual-scroller). *Fundamental Vue* does not include a copy of [vue-virtual-scroller](https://github.com/Akryum/vue-virtual-scroller). It is up to you to properly setup [vue-virtual-scroller](https://github.com/Akryum/vue-virtual-scroller).
5+
6+
<div class="tip" style="border-left: 0.5rem solid #ffa94a;">
7+
<div class="tip-title">IMPORTANT</div>
8+
<div class="tip-body">
9+
<p>You also have to install <a href="https://github.com/Akryum/vue-observe-visibility">vue-observe-visibility</a>. <code>fd-virtualized-list</code> makes use of the <code>v-observe-visibility</code>-directive.</p>
10+
</div>
11+
</div>
12+
513
</docs>
614

715
<condensed />

0 commit comments

Comments
 (0)