Skip to content

Commit e502c31

Browse files
committed
- fixed expanding items conflicts when ids are duplicated
1 parent eaa173f commit e502c31

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ Example:
156156
<template #body>
157157
<!-- Might be added custom body which will overwrite DOM virtualization - useful for presenting placeholders in case that there is no data -->
158158
</template>
159-
<template #item="{ item, index, onExpand }">
160-
<div v-text="item" @click="onExpand" />
159+
<template #item="{ item, onExpand }">
160+
<div v-text="item" @click="onExpand(item)" />
161161
</template>
162162
<template #footer>
163163
<!-- Might be added sticky / floating footer -->

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-windowing",
3-
"version": "0.12.0",
3+
"version": "0.12.1",
44
"description": "Set of components used for virtualizing DOM",
55
"author": {
66
"name": "Maciej Kaczorowski",

src/components/ExpandingList.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export default {
6060
const expandedParents = {};
6161
6262
this.flattenedItems.forEach((item) => {
63+
if (typeof expandedParents[item.id] !== 'undefined') {
64+
delete expandedParents[item.id];
65+
}
66+
6367
if (item.expanded) {
6468
expandedParents[item.id] = true;
6569
}
@@ -84,7 +88,10 @@ export default {
8488
},
8589
methods: {
8690
onExpandItem(item) {
87-
const itemIndex = this.flattenedItems.findIndex(({ id }) => id === item.id);
91+
const itemIndex = this.flattenedItems.findIndex(({
92+
id,
93+
rootId,
94+
}) => id === item.id && rootId === item.rootId);
8895
8996
if (itemIndex !== -1) {
9097
this.flattenedItems[itemIndex].expanded = !this.flattenedItems[itemIndex].expanded;
@@ -93,7 +100,7 @@ export default {
93100
let i = itemIndex + 1;
94101
95102
while (i < this.flattenedItems.length - 1
96-
&& this.flattenedItems[i].rootIndex > this.flattenedItems[itemIndex].rootIndex) {
103+
&& this.flattenedItems[i].level > this.flattenedItems[itemIndex].level) {
97104
this.flattenedItems[i].expanded = false;
98105
99106
i += 1;

src/utils/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export const getExpandingFlattenedItems = ({
3232
items.forEach((item) => {
3333
const { children = [], ...rest } = item;
3434

35-
const isExpanded = typeof expanded === 'object'
35+
const isExpanded = Boolean(typeof expanded === 'object'
3636
? expanded[rest.id]
37-
: expanded;
37+
: expanded);
3838

3939
flattenedItems.push({
4040
...rest,

0 commit comments

Comments
 (0)