Skip to content

Commit

Permalink
🐛 fix Tree switcherIcon shown in leaf node (#20753)
Browse files Browse the repository at this point in the history
close #20511
  • Loading branch information
afc163 committed Jan 8, 2020
1 parent 539b4cd commit 041b743
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 12 additions & 0 deletions components/tree/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
8 changes: 2 additions & 6 deletions components/tree/utils/iconUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
}

Expand Down

0 comments on commit 041b743

Please sign in to comment.