fix: keep className given to expandIcon in Collapse component (#19160)

This commit is contained in:
Gabriele Petrioli 2019-10-11 05:23:41 +03:00 committed by 骗你是小猫咪
parent 78b1f90e51
commit 3ac716d808
2 changed files with 20 additions and 3 deletions

View File

@ -45,14 +45,15 @@ export default class Collapse extends React.Component<CollapseProps, any> {
renderExpandIcon = (panelProps: PanelProps = {}, prefixCls: string) => {
const { expandIcon } = this.props;
const icon = expandIcon ? (
const icon = (expandIcon ? (
expandIcon(panelProps)
) : (
<Icon type="right" rotate={panelProps.isActive ? 90 : undefined} />
);
)) as React.ReactNode;
return React.isValidElement(icon)
? React.cloneElement(icon as any, {
className: `${prefixCls}-arrow`,
className: classNames(icon.props.className, `${prefixCls}-arrow`),
})
: icon;
};

View File

@ -27,6 +27,22 @@ describe('Collapse', () => {
expect(wrapper.render()).toMatchSnapshot();
});
it('should keep the className of the expandIcon', () => {
const wrapper = mount(
<Collapse
expandIcon={() => (
<button type="button" className="custom-expandicon-classname">
action
</button>
)}
>
<Collapse.Panel header="header" />
</Collapse>,
);
expect(wrapper.find('.custom-expandicon-classname').exists()).toBe(true);
});
it('should render extra node of panel', () => {
const wrapper = mount(
<Collapse>