fix: throw exception when has none collapse-panel in default slot (#1116)

pull/1143/head
ly303550688 2019-08-22 13:51:47 +08:00 committed by tangjinzhou
parent 095406eea6
commit 62e3c4b73a
1 changed files with 36 additions and 34 deletions

View File

@ -70,44 +70,46 @@ export default {
const activeKey = this.stateActiveKey; const activeKey = this.stateActiveKey;
const { prefixCls, accordion, destroyInactivePanel, expandIcon } = this.$props; const { prefixCls, accordion, destroyInactivePanel, expandIcon } = this.$props;
const newChildren = []; const newChildren = [];
this.$slots.default.forEach((child, index) => { if (this.$slots.default) {
if (isEmptyElement(child)) return; this.$slots.default.forEach((child, index) => {
const { header, headerClass, disabled } = getPropsData(child); if (isEmptyElement(child)) return;
let isActive = false; const { header, headerClass, disabled } = getPropsData(child);
const key = child.key || String(index); let isActive = false;
if (accordion) { const key = child.key || String(index);
isActive = activeKey[0] === key; if (accordion) {
} else { isActive = activeKey[0] === key;
isActive = activeKey.indexOf(key) > -1; } else {
} isActive = activeKey.indexOf(key) > -1;
}
let panelEvents = {}; let panelEvents = {};
if (!disabled && disabled !== '') { if (!disabled && disabled !== '') {
panelEvents = { panelEvents = {
itemClick: () => { itemClick: () => {
this.onClickItem(key); this.onClickItem(key);
},
};
}
const props = {
props: {
header,
headerClass,
isActive,
prefixCls,
destroyInactivePanel,
openAnimation: this.currentOpenAnimations,
accordion,
expandIcon,
},
on: {
...panelEvents,
}, },
}; };
}
const props = { newChildren.push(cloneElement(child, props));
props: { });
header, }
headerClass,
isActive,
prefixCls,
destroyInactivePanel,
openAnimation: this.currentOpenAnimations,
accordion,
expandIcon,
},
on: {
...panelEvents,
},
};
newChildren.push(cloneElement(child, props));
});
return newChildren; return newChildren;
}, },
setActiveKey(activeKey) { setActiveKey(activeKey) {