Skip to content

Commit 2282e92

Browse files
committed
Prevent from measuring when element height is 0
1 parent a6f9892 commit 2282e92

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

dev/serve.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default Vue.extend({
1212
data() {
1313
return {
1414
expandedGroup: -1,
15-
flatItems: [1, 2, 3, 4],
15+
flatItems: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
1616
items: {
1717
number: [
1818
1,
@@ -82,6 +82,7 @@ export default Vue.extend({
8282
string: [],
8383
},
8484
title: 'Take an action',
85+
isVisible: false,
8586
};
8687
},
8788
methods: {
@@ -124,6 +125,7 @@ export default Vue.extend({
124125
<template>
125126
<div id="app">
126127
<div class="horizontal-wrapper">
128+
<button @click="isVisible = !isVisible">On visibility change</button>
127129
<ExpandingList
128130
:items="items"
129131
:expanded-group="expandedGroup"
@@ -135,7 +137,7 @@ export default Vue.extend({
135137
<li v-text="item" />
136138
</template>
137139
</ExpandingList>
138-
<VirtualScroll :items="flatItems">
140+
<VirtualScroll :root-height="100" v-show="isVisible" :items="flatItems">
139141
<template #item="{ item }">
140142
<li v-text="item" />
141143
</template>

src/components/AutoHeightMeasurer.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export default {
2121
},
2222
mounted() {
2323
this.observer = new ResizeObserver(([entry]) => {
24-
this.$emit('height', {
25-
index: this.index,
26-
height: entry.contentRect.height,
27-
});
24+
if (entry.contentRect.height !== 0) {
25+
this.$emit('height', {
26+
index: this.index,
27+
height: entry.contentRect.height,
28+
});
29+
}
2830
});
2931
3032
if (!this.isObserving) {

0 commit comments

Comments
 (0)