🐛 fix Tree switcherIcon shown in leaf node (#20753) (#20755)

close #20511
This commit is contained in:
偏右 2020-01-08 14:09:06 +08:00 committed by GitHub
parent 539b4cd968
commit 2ebaa7e7a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -30,4 +30,16 @@ describe('Tree', () => {
);
expect(wrapper.render()).toMatchSnapshot();
});
it('switcherIcon in Tree should not render at leaf nodes', () => {
const wrapper = mount(
<Tree switcherIcon={<i className="switcherIcon" />} defaultExpandAll>
<TreeNode icon="icon">
<TreeNode id="node1" title="node1" icon="icon" key="0-0-2" />
<TreeNode id="node2" title="node2" key="0-0-3" />
</TreeNode>
</Tree>,
);
expect(wrapper.find('.switcherIcon').length).toBe(1);
});
});

View File

@ -19,16 +19,12 @@ export default function renderSwitcherIcon(
return <LoadingOutlined className={`${prefixCls}-switcher-loading-icon`} />;
}
if (isLeaf) {
if (showLine) {
return <FileOutlined className={`${prefixCls}-switcher-line-icon`} />;
}
return null;
return showLine ? <FileOutlined className={`${prefixCls}-switcher-line-icon`} /> : null;
}
const switcherCls = `${prefixCls}-switcher-icon`;
if (React.isValidElement(switcherIcon)) {
const switcherOriginCls = switcherIcon.props.className || '';
return React.cloneElement(switcherIcon, {
className: classNames(switcherOriginCls, switcherCls),
className: classNames(switcherIcon.props.className || '', switcherCls),
});
}