Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: keep className given to expandIcon in Collapse component #19160

Merged
merged 1 commit into from Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions components/collapse/Collapse.tsx
Expand Up @@ -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`),
gpetrioli marked this conversation as resolved.
Show resolved Hide resolved
})
: icon;
};
Expand Down
16 changes: 16 additions & 0 deletions components/collapse/__tests__/index.test.js
Expand Up @@ -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>
Expand Down