mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 00:42:36 +00:00
Fixed #4646 - Add custom wrapper support for helper components
This commit is contained in:
parent
7618f8ba7a
commit
f16bd6ab2e
14 changed files with 196 additions and 157 deletions
|
@ -57,7 +57,7 @@
|
|||
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
||||
import ChevronRightIcon from 'primevue/icons/chevronright';
|
||||
import Ripple from 'primevue/ripple';
|
||||
import { DomHandler, UniqueComponentId } from 'primevue/utils';
|
||||
import { DomHandler, HelperSet, UniqueComponentId } from 'primevue/utils';
|
||||
import { mergeProps } from 'vue';
|
||||
import BaseAccordion from './BaseAccordion.vue';
|
||||
|
||||
|
@ -65,10 +65,16 @@ 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_activeIndex: this.activeIndex,
|
||||
d_accordionTabs: new HelperSet({ type: 'AccordionTab' })
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
|
@ -82,10 +88,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;
|
||||
},
|
||||
|
@ -235,19 +241,7 @@ export default {
|
|||
},
|
||||
computed: {
|
||||
tabs() {
|
||||
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;
|
||||
}, []);
|
||||
return this.d_accordionTabs.get(this);
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue