Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Commit 99ad726

Browse files
author
Ken Berkeley
committed
[feature] support accordion for nested components by setting support-nested="accordion"
1 parent 1927da3 commit 99ad726

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/index.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ export default {
151151
return this.columns$.length + (+!!this.selection)
152152
},
153153
data$ () {
154-
const { data } = this
155-
if (this.supportNested) {
154+
const { data, supportNested } = this
155+
if (supportNested) {
156156
// support nested components with extra magic
157157
data.forEach(item => {
158158
if (!item.__nested__) {
@@ -182,6 +182,22 @@ export default {
182182
}
183183
}
184184
})
185+
if (supportNested === 'accordion') {
186+
this.$watch(
187+
() => item.__nested__,
188+
nested => {
189+
// only one nested component can be expanded at the same time
190+
if (data.filter(({ __nested__ }) => __nested__.visible).length < 2) return
191+
192+
data.forEach(({ __nested__ }) => {
193+
if (__nested__.visible && __nested__ !== nested) {
194+
__nested__.visible = false
195+
}
196+
})
197+
},
198+
{ deep: true }
199+
)
200+
}
185201
Object.defineProperty(item, '__nested__', { enumerable: false })
186202
}
187203
})

0 commit comments

Comments
 (0)