From 40f231b1f5cb19f45de4e49427bb7dbd62ce3103 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 22 Dec 2023 11:17:54 +0000 Subject: [PATCH] Reverted #4646 - For TabView and Accordion --- components/lib/accordion/Accordion.vue | 30 ++++++++++++-------- components/lib/accordiontab/AccordionTab.vue | 9 +----- components/lib/tabpanel/TabPanel.vue | 9 +----- components/lib/tabview/TabView.vue | 27 ++++++++++++------ components/lib/treetable/TreeTable.vue | 1 + 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/components/lib/accordion/Accordion.vue b/components/lib/accordion/Accordion.vue index d25a9e809..dfd54e2b5 100755 --- a/components/lib/accordion/Accordion.vue +++ b/components/lib/accordion/Accordion.vue @@ -57,7 +57,7 @@ import ChevronDownIcon from 'primevue/icons/chevrondown'; import ChevronRightIcon from 'primevue/icons/chevronright'; import Ripple from 'primevue/ripple'; -import { DomHandler, HelperSet, UniqueComponentId } from 'primevue/utils'; +import { DomHandler, UniqueComponentId } from 'primevue/utils'; import { mergeProps } from 'vue'; import BaseAccordion from './BaseAccordion.vue'; @@ -65,16 +65,10 @@ export default { name: 'Accordion', extends: BaseAccordion, emits: ['update:activeIndex', 'tab-open', 'tab-close', 'tab-click'], - provide() { - return { - $accordionTabs: this.d_accordionTabs - }; - }, data() { return { id: this.$attrs.id, - d_activeIndex: this.activeIndex, - d_accordionTabs: new HelperSet({ type: 'AccordionTab' }) + d_activeIndex: this.activeIndex }; }, watch: { @@ -88,10 +82,10 @@ export default { mounted() { this.id = this.id || UniqueComponentId(); }, - beforeUnmount() { - this.d_accordionTabs.clear(); - }, methods: { + isAccordionTab(child) { + return child.type.name === 'AccordionTab'; + }, isTabActive(index) { return this.multiple ? this.d_activeIndex && this.d_activeIndex.includes(index) : this.d_activeIndex === index; }, @@ -241,7 +235,19 @@ export default { }, computed: { tabs() { - return this.d_accordionTabs.get(this); + return this.$slots.default().reduce((tabs, child) => { + if (this.isAccordionTab(child)) { + tabs.push(child); + } else if (child.children && child.children instanceof Array) { + child.children.forEach((nestedChild) => { + if (this.isAccordionTab(nestedChild)) { + tabs.push(nestedChild); + } + }); + } + + return tabs; + }, []); } }, components: { diff --git a/components/lib/accordiontab/AccordionTab.vue b/components/lib/accordiontab/AccordionTab.vue index 7f6a97935..c5f577a91 100755 --- a/components/lib/accordiontab/AccordionTab.vue +++ b/components/lib/accordiontab/AccordionTab.vue @@ -7,13 +7,6 @@ import BaseAccordionTab from './BaseAccordionTab.vue'; export default { name: 'AccordionTab', - extends: BaseAccordionTab, - inject: ['$accordionTabs'], - mounted() { - this.$accordionTabs?.add(this.$); - }, - unmounted() { - this.$accordionTabs?.delete(this.$); - } + extends: BaseAccordionTab }; diff --git a/components/lib/tabpanel/TabPanel.vue b/components/lib/tabpanel/TabPanel.vue index 2483c99f8..90790ba53 100755 --- a/components/lib/tabpanel/TabPanel.vue +++ b/components/lib/tabpanel/TabPanel.vue @@ -7,13 +7,6 @@ import BaseTabPanel from './BaseTabPanel.vue'; export default { name: 'TabPanel', - extends: BaseTabPanel, - inject: ['$tabPanels'], - mounted() { - this.$tabPanels?.add(this.$); - }, - unmounted() { - this.$tabPanels?.delete(this.$); - } + extends: BaseTabPanel }; diff --git a/components/lib/tabview/TabView.vue b/components/lib/tabview/TabView.vue index b4a588563..2ceb0fc1f 100755 --- a/components/lib/tabview/TabView.vue +++ b/components/lib/tabview/TabView.vue @@ -95,7 +95,7 @@ import ChevronLeftIcon from 'primevue/icons/chevronleft'; import ChevronRightIcon from 'primevue/icons/chevronright'; import Ripple from 'primevue/ripple'; -import { DomHandler, HelperSet, UniqueComponentId } from 'primevue/utils'; +import { DomHandler, UniqueComponentId } from 'primevue/utils'; import { mergeProps } from 'vue'; import BaseTabView from './BaseTabView.vue'; @@ -103,18 +103,12 @@ export default { name: 'TabView', extends: BaseTabView, emits: ['update:activeIndex', 'tab-change', 'tab-click'], - provide() { - return { - $tabPanels: this.d_tabPanels - }; - }, data() { return { id: this.$attrs.id, d_activeIndex: this.activeIndex, isPrevButtonDisabled: true, - isNextButtonDisabled: false, - d_tabPanels: new HelperSet({ type: 'TabPanel' }) + isNextButtonDisabled: false }; }, watch: { @@ -140,6 +134,9 @@ export default { this.d_tabPanels.clear(); }, methods: { + isTabPanel(child) { + return child.type.name === 'TabPanel'; + }, isTabActive(index) { return this.d_activeIndex === index; }, @@ -348,7 +345,19 @@ export default { }, computed: { tabs() { - return this.d_tabPanels.get(this); + return this.$slots.default().reduce((tabs, child) => { + if (this.isTabPanel(child)) { + tabs.push(child); + } else if (child.children && child.children instanceof Array) { + child.children.forEach((nestedChild) => { + if (this.isTabPanel(nestedChild)) { + tabs.push(nestedChild); + } + }); + } + + return tabs; + }, []); }, prevButtonAriaLabel() { return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.previous : undefined; diff --git a/components/lib/treetable/TreeTable.vue b/components/lib/treetable/TreeTable.vue index eee6577c3..49594bbaa 100755 --- a/components/lib/treetable/TreeTable.vue +++ b/components/lib/treetable/TreeTable.vue @@ -1,5 +1,6 @@