Skip to content

Commit f2a2282

Browse files
committed
- improve height calculations; no need to pass rootHeight as a prop.
- improve performance - allow for multiple nesting for NestedList.vue - clean code - update dependencies
1 parent c5aa338 commit f2a2282

File tree

10 files changed

+359
-268
lines changed

10 files changed

+359
-268
lines changed

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Example:
4646
```vue
4747
<template>
4848
<VirtualScroll
49+
style="height: 200px"
4950
:items="items"
50-
:root-height="rootHeight"
5151
:render-ahead="renderAhead"
5252
:estimated-height="estimatedHeight">
5353
<template #item="{ item, index}">
@@ -61,7 +61,6 @@ export default {
6161
data() {
6262
return {
6363
items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
64-
rootHeight: 100,
6564
renderAhead: 2, // Buffer, +2 at top / bottom in queue
6665
estimatedHeight: 20, // We need to assume that there is some default height for each row which will be recalculated later
6766
};
@@ -79,8 +78,8 @@ Example:
7978
```vue
8079
<template>
8180
<NestedList
81+
style="height: 200px"
8282
:items="items"
83-
:root-height="rootHeight"
8483
:render-ahead="renderAhead"
8584
:estimated-height="estimatedHeight">
8685
<template #group="{ item, index }">
@@ -100,7 +99,6 @@ export default {
10099
numberGroup: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
101100
stringGroup: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'],
102101
},
103-
rootHeight: 100,
104102
renderAhead: 2, // Buffer, +2 at top / bottom in queue
105103
estimatedHeight: 20, // We need to assume that there is some default height for each row which will be recalculated later
106104
};
@@ -118,8 +116,8 @@ Example:
118116
```vue
119117
<template>
120118
<ExpandingList
119+
style="height: 200px"
121120
:items="items"
122-
:root-height="rootHeight"
123121
:render-ahead="renderAhead"
124122
:estimated-height="estimatedHeight"
125123
:expanded-group="expandedGroup"
@@ -141,14 +139,13 @@ export default {
141139
numberGroup: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
142140
stringGroup: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'],
143141
},
144-
rootHeight: 100,
145142
renderAhead: 2, // Buffer, +2 at top / bottom in queue
146143
estimatedHeight: 20, // We need to assume that there is some default height for each row which will be recalculated later
147144
expandedGroup: '',
148145
};
149146
},
150147
methods: {
151-
expandedGroup(group) {
148+
onExpandGroup(group) {
152149
// You may fetch data here and mutate items object
153150
// this.items[group] = ['a', 'b', 'c', 'd'];
154151
@@ -164,7 +161,6 @@ Props:
164161
| Prop name | Description | Default value |
165162
| ------------- |:-------------:| -----:|
166163
| items | list of items | [] or {} for Nested/Expanding List |
167-
| rootHeight | max height of scroll component | 400 |
168164
| renderAhead | number of buffered items at the top/bottom | 2 |
169165
| estimatedHeight | approximated value of each row height | 30 |
170166
| expandedGroup | key of expanded group - only for ExpandingList | '' |
@@ -173,7 +169,28 @@ Events:
173169

174170
- expand: click event for group element which toggles between visible state of group items - only for ExpandingList
175171

172+
### Tips
173+
174+
Do not use margin directly for styling node items! Height won't be measured well.
175+
{: .alert .alert-danger}
176+
177+
Each virtualized component by default will expand height by 100%, to override it and make things happening you either have to set height / max-height of component or by implementing dynamic height content with flexbox / grid.
178+
{: .alert .alert-info}
176179

177180
## License
178181

179182
[MIT](http://opensource.org/licenses/MIT)
183+
184+
<style>
185+
.alert-info {
186+
color: rgb(49,112,143) !important;
187+
}
188+
189+
.alert-green {
190+
color: rgb(60,118,61) !important;
191+
}
192+
193+
.alert-danger {
194+
color: rgb(169,68,66) !important;
195+
}
196+
</style>

dev/serve.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export default Vue.extend({
127127
<div class="horizontal-wrapper">
128128
<button @click="isVisible = !isVisible">On visibility change</button>
129129
<ExpandingList
130+
style="height: 100px"
130131
:items="items"
131132
:expanded-group="expandedGroup"
132133
@expand="onExpandGroup">
@@ -137,7 +138,7 @@ export default Vue.extend({
137138
<li v-text="item" />
138139
</template>
139140
</ExpandingList>
140-
<VirtualScroll :root-height="100" v-show="isVisible" :items="flatItems">
141+
<VirtualScroll style="height: 100px" v-show="isVisible" :items="flatItems">
141142
<template #item="{ item }">
142143
<li v-text="item" />
143144
</template>

0 commit comments

Comments
 (0)