mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 19:42:54 +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>
71 lines
1.2 KiB
TypeScript
71 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
import { DownOutlined } from '@ant-design/icons';
|
|
import { TreeSelect } from 'antd';
|
|
|
|
const MAX_COUNT = 3;
|
|
|
|
const treeData = [
|
|
{
|
|
title: 'Parent 1',
|
|
value: 'parent1',
|
|
children: [
|
|
{
|
|
title: 'Child 1-1',
|
|
value: 'child1-1',
|
|
},
|
|
{
|
|
title: 'Child 1-2',
|
|
value: 'child1-2',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: 'Parent 2',
|
|
value: 'parent2',
|
|
children: [
|
|
{
|
|
title: 'Child 2-1',
|
|
value: 'child2-1',
|
|
},
|
|
{
|
|
title: 'Child 2-2',
|
|
value: 'child2-2',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
const App: React.FC = () => {
|
|
const [value, setValue] = React.useState<string[]>(['child1-1']);
|
|
|
|
const onChange = (newValue: string[]) => {
|
|
setValue(newValue);
|
|
};
|
|
|
|
const suffix = (
|
|
<>
|
|
<span>
|
|
{value.length} / {MAX_COUNT}
|
|
</span>
|
|
<DownOutlined />
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<TreeSelect
|
|
treeData={treeData}
|
|
value={value}
|
|
onChange={onChange}
|
|
multiple
|
|
maxCount={MAX_COUNT}
|
|
style={{ width: '100%' }}
|
|
suffixIcon={suffix}
|
|
treeCheckable
|
|
placeholder="Please select"
|
|
showCheckedStrategy={TreeSelect.SHOW_CHILD}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|