mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-12 04:13:13 +08:00

* feat: TreeSelect support maxCount * Update components/tree-select/index.zh-CN.md Co-authored-by: thinkasany <480968828@qq.com> Signed-off-by: lijianan <574980606@qq.com> * chore: bump tree & tree-select version for supporting maxCount * test: update snapshot * chore: bump rc-cascader version to 3.31.0 * :wqhe commit message for your changes. Lines starting * rerun ci * rerun ci * docs: update doc * docs: improve demo * fix: add demo * docs: add demo * chore: trigger CI build --------- Signed-off-by: lijianan <574980606@qq.com> Signed-off-by: Jony J <1844749591@qq.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: thinkasany <480968828@qq.com>
72 lines
1.3 KiB
TypeScript
72 lines
1.3 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { TreeSelect } from 'antd';
|
|
import { DownOutlined } from '@ant-design/icons';
|
|
|
|
const treeData = [
|
|
{
|
|
title: 'Node1',
|
|
value: '0-0',
|
|
key: '0-0',
|
|
children: [
|
|
{
|
|
title: 'Child Node1',
|
|
value: '0-0-1',
|
|
key: '0-0-1',
|
|
},
|
|
{
|
|
title: 'Child Node2',
|
|
value: '0-0-2',
|
|
key: '0-0-2',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: 'Node2',
|
|
value: '0-1',
|
|
key: '0-1',
|
|
children: [
|
|
{
|
|
title: 'Child Node3',
|
|
value: '0-1-1',
|
|
key: '0-1-1',
|
|
},
|
|
{
|
|
title: 'Child Node4',
|
|
value: '0-1-2',
|
|
key: '0-1-2',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
const MAX_COUNT = 2;
|
|
|
|
function MaxCountNoEffectDemo() {
|
|
const [value, setValue] = useState<string[]>([]);
|
|
|
|
const suffix = (
|
|
<>
|
|
<span>
|
|
{value.length} / {MAX_COUNT}
|
|
</span>
|
|
<DownOutlined />
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<TreeSelect
|
|
treeCheckable
|
|
showCheckedStrategy={TreeSelect.SHOW_PARENT}
|
|
maxCount={MAX_COUNT}
|
|
suffixIcon={suffix}
|
|
placeholder="please select"
|
|
value={value}
|
|
onChange={(val) => setValue(val as string[])}
|
|
style={{ width: '100%' }}
|
|
treeData={treeData}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default MaxCountNoEffectDemo;
|