Skip to content

Commit b5e1003

Browse files
committed
fix: throw exception when has none collapse-panel in default slot
1 parent 095406e commit b5e1003

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

components/vc-collapse/src/Collapse.jsx

+36-34
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,46 @@ export default {
7070
const activeKey = this.stateActiveKey;
7171
const { prefixCls, accordion, destroyInactivePanel, expandIcon } = this.$props;
7272
const newChildren = [];
73-
this.$slots.default.forEach((child, index) => {
74-
if (isEmptyElement(child)) return;
75-
const { header, headerClass, disabled } = getPropsData(child);
76-
let isActive = false;
77-
const key = child.key || String(index);
78-
if (accordion) {
79-
isActive = activeKey[0] === key;
80-
} else {
81-
isActive = activeKey.indexOf(key) > -1;
82-
}
73+
if (this.$slots.default) {
74+
this.$slots.default.forEach((child, index) => {
75+
if (isEmptyElement(child)) return;
76+
const { header, headerClass, disabled } = getPropsData(child);
77+
let isActive = false;
78+
const key = child.key || String(index);
79+
if (accordion) {
80+
isActive = activeKey[0] === key;
81+
} else {
82+
isActive = activeKey.indexOf(key) > -1;
83+
}
8384

84-
let panelEvents = {};
85-
if (!disabled && disabled !== '') {
86-
panelEvents = {
87-
itemClick: () => {
88-
this.onClickItem(key);
85+
let panelEvents = {};
86+
if (!disabled && disabled !== '') {
87+
panelEvents = {
88+
itemClick: () => {
89+
this.onClickItem(key);
90+
},
91+
};
92+
}
93+
94+
const props = {
95+
props: {
96+
header,
97+
headerClass,
98+
isActive,
99+
prefixCls,
100+
destroyInactivePanel,
101+
openAnimation: this.currentOpenAnimations,
102+
accordion,
103+
expandIcon,
104+
},
105+
on: {
106+
...panelEvents,
89107
},
90108
};
91-
}
92-
93-
const props = {
94-
props: {
95-
header,
96-
headerClass,
97-
isActive,
98-
prefixCls,
99-
destroyInactivePanel,
100-
openAnimation: this.currentOpenAnimations,
101-
accordion,
102-
expandIcon,
103-
},
104-
on: {
105-
...panelEvents,
106-
},
107-
};
108109

109-
newChildren.push(cloneElement(child, props));
110-
});
110+
newChildren.push(cloneElement(child, props));
111+
});
112+
}
111113
return newChildren;
112114
},
113115
setActiveKey(activeKey) {

0 commit comments

Comments
 (0)