2019-09-16 21:03:29 +08:00
|
|
|
---
|
|
|
|
order: 8
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义展开/折叠图标
|
|
|
|
en-US: Customize collapse/expand icon
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
自定义展开/折叠图标。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
customize collapse/expand icon of tree node
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2019-11-28 12:34:33 +08:00
|
|
|
import { DownOutlined } from '@ant-design/icons';
|
2022-05-21 22:14:15 +08:00
|
|
|
import { Tree } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { DataNode, TreeProps } from 'antd/lib/tree';
|
2022-05-21 22:14:15 +08:00
|
|
|
import React from 'react';
|
2019-09-16 21:03:29 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const treeData: DataNode[] = [
|
|
|
|
{
|
|
|
|
title: 'parent 1',
|
|
|
|
key: '0-0',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'parent 1-0',
|
|
|
|
key: '0-0-0',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-0-0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-0-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-0-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'parent 1-1',
|
|
|
|
key: '0-0-1',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-1-0',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'parent 1-2',
|
|
|
|
key: '0-0-2',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-2-0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'leaf',
|
|
|
|
key: '0-0-2-1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const App: React.FC = () => {
|
|
|
|
const onSelect: TreeProps['onSelect'] = (selectedKeys, info) => {
|
2019-09-16 21:03:29 +08:00
|
|
|
console.log('selected', selectedKeys, info);
|
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
return (
|
|
|
|
<Tree
|
|
|
|
showLine
|
|
|
|
switcherIcon={<DownOutlined />}
|
|
|
|
defaultExpandedKeys={['0-0-0']}
|
|
|
|
onSelect={onSelect}
|
|
|
|
treeData={treeData}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2019-09-16 21:03:29 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2019-09-16 21:03:29 +08:00
|
|
|
```
|