Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions src/Collapse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,44 @@ class Collapse extends Component {
this.setActiveKey(activeKey);
}

getItems() {
getNewChild(child, index) {
if (!child) return null;

const activeKey = this.state.activeKey;
const { prefixCls, accordion, destroyInactivePanel, expandIcon, children } = this.props;
const newChildren = [];
const { prefixCls, accordion, destroyInactivePanel, expandIcon } = this.props;
// If there is no key provide, use the panel order as default key
const key = child.key || String(index);
const { header, headerClass, disabled } = child.props;
let isActive = false;
if (accordion) {
isActive = activeKey[0] === key;
} else {
isActive = activeKey.indexOf(key) > -1;
}

const props = {
key,
header,
headerClass,
isActive,
prefixCls,
destroyInactivePanel,
openAnimation: this.state.openAnimation,
accordion,
children: child.props.children,
onItemClick: disabled ? null : this.onClickItem.bind(this, key),
expandIcon,
};

return React.cloneElement(child, props);
}

getItems() {
const { children } = this.props;
const childList = isFragment(children) ? children.props.children : children;

Children.forEach(childList, (child, index) => {
if (!child) return;
// If there is no key provide, use the panel order as default key
const key = child.key || String(index);
const { header, headerClass, disabled } = child.props;
let isActive = false;
if (accordion) {
isActive = activeKey[0] === key;
} else {
isActive = activeKey.indexOf(key) > -1;
}
const newChildren = Children.map(childList, this.getNewChild.bind(this));

const props = {
key,
header,
headerClass,
isActive,
prefixCls,
destroyInactivePanel,
openAnimation: this.state.openAnimation,
accordion,
children: child.props.children,
onItemClick: disabled ? null : () => this.onClickItem(key),
expandIcon,
};

newChildren.push(React.cloneElement(child, props));
});
// ref: https://github.com/ant-design/ant-design/issues/13884
if (isFragment(children)) {
return (
Expand Down