mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-14 08:51:26 +08:00
47 lines
825 B
TypeScript
47 lines
825 B
TypeScript
|
import React, { useState } from 'react';
|
||
|
import { TreeSelect } from 'antd';
|
||
|
|
||
|
const treeData = [
|
||
|
{
|
||
|
title: 'Node1',
|
||
|
value: '0-0',
|
||
|
children: [
|
||
|
{
|
||
|
title: 'Child Node1',
|
||
|
value: '0-0-1',
|
||
|
},
|
||
|
{
|
||
|
title: 'Child Node2',
|
||
|
value: '0-0-2',
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
{
|
||
|
title: 'Node2',
|
||
|
value: '0-1',
|
||
|
},
|
||
|
];
|
||
|
|
||
|
const App: React.FC = () => {
|
||
|
const [value, setValue] = useState<string>();
|
||
|
|
||
|
const onChange = (newValue: string) => {
|
||
|
console.log(newValue);
|
||
|
setValue(newValue);
|
||
|
};
|
||
|
|
||
|
return (
|
||
|
<TreeSelect
|
||
|
style={{ width: '100%' }}
|
||
|
value={value}
|
||
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||
|
treeData={treeData}
|
||
|
placeholder="Please select"
|
||
|
treeDefaultExpandAll
|
||
|
onChange={onChange}
|
||
|
/>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default App;
|