From 2a39a97633b8827cbb3903cd2fc47d28c960af72 Mon Sep 17 00:00:00 2001 From: naortedgi Date: Sun, 15 Nov 2020 21:58:39 +0200 Subject: [PATCH] add accordion dynamic tabs support with v-for directive --- src/components/accordion/Accordion.vue | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/accordion/Accordion.vue b/src/components/accordion/Accordion.vue index 8cf69dee6..43d4e2241 100755 --- a/src/components/accordion/Accordion.vue +++ b/src/components/accordion/Accordion.vue @@ -98,11 +98,24 @@ export default { getHeaderIcon(i) { const active = this.isTabActive(i); return ['p-accordion-toggle-icon pi', {'pi-chevron-right': !active, 'pi-chevron-down': active}]; + }, + childIsAccordionTab(child) { + return child.type.name === 'accordiontab' } + }, computed: { tabs() { - return this.$slots.default().filter(child => child.type.name === 'accordiontab'); + const tabs = [] + this.$slots.default().forEach(child => { + if (this.childIsAccordionTab(child)) tabs.push(child) + else if (child.children.length > 0) + child.children.forEach(nestedChild => { + if (this.childIsAccordionTab(nestedChild)) tabs.push(nestedChild) + }) + } + ) + return tabs }, ariaId() { return UniqueComponentId(); @@ -128,4 +141,4 @@ export default { .p-accordion-header-text { line-height: 1; } - \ No newline at end of file +