treeSelect.stories.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. import React, { useState } from 'react';
  2. import { Icon, Button, Form, Popover, Tag, Typography } from '../../index';
  3. import TreeSelect from '../index';
  4. import { flattenDeep } from 'lodash';
  5. import CustomTrigger from './CustomTrigger';
  6. import { IconCreditCard } from '@douyinfe/semi-icons';
  7. const TreeNode = TreeSelect.TreeNode;
  8. const { Title } = Typography;
  9. export default {
  10. title: 'TreeSelect',
  11. parameters: {
  12. chromatic: { disableSnapshot: true },
  13. },
  14. }
  15. const treeData1 = [
  16. {
  17. label: 'Node1',
  18. value: '0-0',
  19. key: '0-0',
  20. children: [
  21. {
  22. label: 'Child Node1',
  23. value: '0-0-1',
  24. key: '0-0-1',
  25. },
  26. {
  27. label: 'Child Node2',
  28. value: '0-0-2',
  29. key: '0-0-2',
  30. },
  31. ],
  32. },
  33. {
  34. label: 'Node2',
  35. value: '0-1',
  36. key: '0-1',
  37. },
  38. ];
  39. const treeData2 = [
  40. {
  41. label: '亚洲',
  42. value: 'yazhou',
  43. key: 'yazhou',
  44. children: [
  45. {
  46. label: '中国',
  47. value: 'zhongguo',
  48. key: 'zhongguo',
  49. children: [
  50. {
  51. label: '北京',
  52. value: 'beijing',
  53. key: 'beijing',
  54. },
  55. {
  56. label: '上海',
  57. value: 'shanghai',
  58. key: 'shanghai',
  59. },
  60. ],
  61. },
  62. // {
  63. // label: '日本',
  64. // value: 'riben',
  65. // key: 'riben',
  66. // children: [
  67. // {
  68. // label: '东京',
  69. // value: 'dongjing',
  70. // key: 'dongjing'
  71. // },
  72. // {
  73. // label: '大阪',
  74. // value: 'daban',
  75. // key: 'daban'
  76. // }
  77. // ]
  78. // },
  79. ],
  80. },
  81. {
  82. label: '北美洲',
  83. value: 'beimeizhou',
  84. key: 'beimeizhou',
  85. children: [
  86. {
  87. label: '美国',
  88. value: 'meiguo',
  89. key: 'meiguo',
  90. },
  91. {
  92. label: '加拿大',
  93. value: 'jianada',
  94. key: 'jianada',
  95. },
  96. ],
  97. },
  98. ];
  99. const treeDataWithoutValue = [
  100. {
  101. label: '亚洲',
  102. key: 'yazhou',
  103. children: [
  104. {
  105. label: '中国',
  106. key: 'zhongguo',
  107. disabled: true,
  108. children: [
  109. {
  110. label: '北京',
  111. key: 'beijing',
  112. },
  113. {
  114. label: '上海',
  115. key: 'shanghai',
  116. },
  117. ],
  118. },
  119. {
  120. label: '日本',
  121. key: 'riben',
  122. children: [
  123. {
  124. label: '东京',
  125. key: 'dongjing',
  126. },
  127. {
  128. label: '大阪',
  129. key: 'daban',
  130. },
  131. ],
  132. },
  133. ],
  134. },
  135. {
  136. label: '北美洲',
  137. key: 'beimeizhou',
  138. children: [
  139. {
  140. label: '美国',
  141. key: 'meiguo',
  142. },
  143. {
  144. label: '加拿大',
  145. key: 'jianada',
  146. },
  147. ],
  148. },
  149. ];
  150. class SimpleTree extends React.Component {
  151. render() {
  152. return (
  153. <div>
  154. <TreeSelect
  155. style={{ width: 300 }}
  156. // value={this.state.value}
  157. dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
  158. treeData={treeData1}
  159. placeholder="Please select"
  160. onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
  161. onSelect={(e, bool) => console.log('select', e, bool)}
  162. onChange={(e, node) => console.log('change', e, node)}
  163. />
  164. <br />
  165. <br />
  166. <TreeSelect
  167. style={{ width: 300 }}
  168. // value={this.state.value}
  169. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  170. treeData={treeData2}
  171. placeholder="Please select"
  172. />
  173. </div>
  174. );
  175. }
  176. }
  177. export const _TreeSelect = () => {
  178. const treeData = [
  179. {
  180. label: '亚洲',
  181. value: 'Asia',
  182. key: '0',
  183. children: [
  184. {
  185. label: '中国',
  186. value: 'China',
  187. key: '0-0',
  188. children: [
  189. {
  190. label: '北京',
  191. value: 'Beijing',
  192. key: '0-0-0',
  193. },
  194. {
  195. label: '上海',
  196. value: 'Shanghai',
  197. key: '0-0-1',
  198. },
  199. ],
  200. },
  201. ],
  202. },
  203. {
  204. label: '北美洲',
  205. value: 'North America',
  206. key: '1',
  207. },
  208. ];
  209. return (
  210. <TreeSelect
  211. style={{ width: 300 }}
  212. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  213. treeData={treeData2}
  214. placeholder="请选择"
  215. />
  216. );
  217. };
  218. _TreeSelect.story = {
  219. name: 'tree select',
  220. };
  221. export const Searchable = () => (
  222. <div>
  223. <TreeSelect
  224. style={{ width: 300 }}
  225. // value={this.state.value}
  226. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  227. treeData={treeData2}
  228. filterTreeNode
  229. treeNodeFilterProp="value"
  230. placeholder="Please select"
  231. />
  232. <br />
  233. <br />
  234. <TreeSelect
  235. style={{ width: 300 }}
  236. // value={this.state.value}
  237. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  238. treeData={treeData2}
  239. filterTreeNode
  240. placeholder="Please select"
  241. />
  242. <br />
  243. <br />
  244. <TreeSelect
  245. style={{ width: 300 }}
  246. // value={this.state.value}
  247. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  248. treeData={treeData2}
  249. filterTreeNode
  250. searchAutoFocus
  251. placeholder="searchAutoFocus"
  252. />
  253. </div>
  254. );
  255. Searchable.story = {
  256. name: 'searchable',
  257. };
  258. export const SearchPosition = () => (
  259. <>
  260. <TreeSelect
  261. searchPosition="trigger"
  262. style={{ width: 300 }}
  263. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  264. treeData={treeData2}
  265. filterTreeNode
  266. placeholder="单选"
  267. />
  268. <br />
  269. <br />
  270. <TreeSelect
  271. searchPosition="trigger"
  272. style={{ width: 300 }}
  273. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  274. treeData={treeData2}
  275. multiple
  276. filterTreeNode
  277. maxTagCount={2}
  278. placeholder="多选"
  279. />
  280. <br />
  281. <br />
  282. <TreeSelect
  283. searchPosition="trigger"
  284. style={{ width: 300 }}
  285. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  286. treeData={treeData2}
  287. multiple
  288. filterTreeNode
  289. maxTagCount={2}
  290. placeholder="searchAutoFocus"
  291. searchAutoFocus
  292. />
  293. <br />
  294. <br />
  295. <TreeSelect
  296. searchPosition="trigger"
  297. style={{ width: 300 }}
  298. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  299. treeData={treeData2}
  300. multiple
  301. filterTreeNode
  302. maxTagCount={1}
  303. placeholder="maxTagCount=1"
  304. />
  305. </>
  306. );
  307. SearchPosition.story = {
  308. name: 'searchPosition',
  309. };
  310. export const PrefixSuffixInsetLabel = () => (
  311. <div>
  312. <TreeSelect
  313. style={{ width: 300 }}
  314. // value={this.state.value}
  315. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  316. treeData={treeData2}
  317. filterTreeNode
  318. prefix={<IconCreditCard />}
  319. treeNodeFilterProp="value"
  320. placeholder="Please select"
  321. />
  322. <br />
  323. <br />
  324. <TreeSelect
  325. style={{ width: 300 }}
  326. // value={this.state.value}
  327. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  328. treeData={treeData2}
  329. filterTreeNode
  330. prefix={<span>1234</span>}
  331. treeNodeFilterProp="value"
  332. placeholder="Please select"
  333. />
  334. <br />
  335. <br />
  336. <TreeSelect
  337. style={{ width: 300 }}
  338. suffix="RMB"
  339. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  340. treeData={treeData2}
  341. placeholder="Please select"
  342. />
  343. <br />
  344. <br />
  345. <TreeSelect
  346. style={{ width: 300 }}
  347. insetLabel="blablabla"
  348. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  349. treeData={treeData2}
  350. placeholder="Please select"
  351. />
  352. <br />
  353. <br />
  354. <TreeSelect
  355. style={{ width: 300 }}
  356. insetLabel={<span>1234</span>}
  357. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  358. treeData={treeData2}
  359. placeholder="Please select"
  360. />
  361. </div>
  362. );
  363. PrefixSuffixInsetLabel.story = {
  364. name: 'prefix suffix insetLabel',
  365. };
  366. PrefixSuffixInsetLabel.parameters = {
  367. chromatic: { disableSnapshot: false },
  368. }
  369. export const ValidateStatus = () => (
  370. <div>
  371. <TreeSelect
  372. style={{ width: 300 }}
  373. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  374. treeData={treeData2}
  375. multiple
  376. validateStatus="warning"
  377. placeholder="Please select"
  378. onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
  379. onSelect={(e, bool) => console.log('select', e, bool)}
  380. onChange={e => console.log('change', e)}
  381. />
  382. <br />
  383. <br />
  384. <TreeSelect
  385. style={{ width: 300 }}
  386. validateStatus="error"
  387. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  388. treeData={treeData2}
  389. // multiple
  390. placeholder="Please select"
  391. />
  392. </div>
  393. );
  394. ValidateStatus.story = {
  395. name: 'validate status',
  396. };
  397. ValidateStatus.parameters = {
  398. chromatic: { disableSnapshot: false },
  399. }
  400. export const Multiple = () => (
  401. <div>
  402. <TreeSelect
  403. style={{ width: 300 }}
  404. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  405. treeData={treeData2}
  406. multiple
  407. placeholder="Please select"
  408. onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
  409. onSelect={(e, bool) => console.log('select', e, bool)}
  410. onChange={e => console.log('change', e)}
  411. />
  412. <br />
  413. <br />
  414. <TreeSelect
  415. style={{ width: 300 }}
  416. // value={this.state.value}
  417. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  418. treeData={treeData2}
  419. multiple
  420. placeholder="Please select"
  421. />
  422. </div>
  423. );
  424. Multiple.story = {
  425. name: 'multiple',
  426. };
  427. export const MaxTagCount = () => (
  428. <div>
  429. <TreeSelect
  430. style={{ width: 300 }}
  431. // value={this.state.value}
  432. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  433. treeData={treeData2}
  434. multiple
  435. maxTagCount={2}
  436. placeholder="Please select"
  437. />
  438. {/* <br />
  439. <br />
  440. <TreeSelect
  441. style={{ width: 300 }}
  442. // value={this.state.value}
  443. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  444. treeData={treeData2}
  445. multiple
  446. placeholder="Please select"
  447. /> */}
  448. </div>
  449. );
  450. MaxTagCount.story = {
  451. name: 'maxTagCount',
  452. };
  453. export const MultipleSearchable = () => (
  454. <div>
  455. <TreeSelect
  456. style={{ width: 300 }}
  457. // value={this.state.value}
  458. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  459. treeData={treeData2}
  460. multiple
  461. filterTreeNode
  462. treeNodeFilterProp="value"
  463. placeholder="Please select"
  464. />
  465. </div>
  466. );
  467. MultipleSearchable.story = {
  468. name: 'multiple searchable',
  469. };
  470. export const DefaultValues = () => (
  471. <div>
  472. <TreeSelect
  473. style={{ width: 300 }}
  474. defaultValue={'shanghai'}
  475. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  476. treeData={treeData2}
  477. // multiple
  478. filterTreeNode
  479. treeNodeFilterProp="value"
  480. />
  481. <br />
  482. <br />
  483. <TreeSelect
  484. style={{ width: 300 }}
  485. defaultValue={'shanghai'}
  486. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  487. treeData={treeData2}
  488. filterTreeNode
  489. multiple
  490. treeNodeFilterProp="value"
  491. />
  492. <br />
  493. <br />
  494. <TreeSelect
  495. style={{ width: 300 }}
  496. defaultValue={['shanghai', 'daban', 'dongjing']}
  497. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  498. treeData={treeData2}
  499. filterTreeNode
  500. multiple
  501. treeNodeFilterProp="value"
  502. />
  503. <br />
  504. <br />
  505. <TreeSelect
  506. style={{ width: 300 }}
  507. defaultValue={['meiguo', 'dongjing']}
  508. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  509. treeData={treeData2}
  510. filterTreeNode
  511. multiple
  512. treeNodeFilterProp="value"
  513. />
  514. </div>
  515. );
  516. DefaultValues.story = {
  517. name: 'default values',
  518. };
  519. export const Disabled = () => (
  520. <div>
  521. <TreeSelect
  522. style={{ width: 300 }}
  523. defaultValue={'shanghai'}
  524. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  525. treeData={treeData2}
  526. multiple
  527. filterTreeNode
  528. disabled
  529. treeNodeFilterProp="value"
  530. placeholder="Please select"
  531. />
  532. <br />
  533. <br />
  534. <TreeSelect
  535. style={{ width: 300 }}
  536. defaultValue={'shanghai'}
  537. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  538. treeData={treeData2}
  539. filterTreeNode
  540. disabled
  541. treeNodeFilterProp="value"
  542. placeholder="Please select"
  543. />
  544. <br />
  545. <br />
  546. <TreeSelect
  547. style={{ width: 300 }}
  548. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  549. treeData={treeData2}
  550. multiple
  551. filterTreeNode
  552. disabled
  553. treeNodeFilterProp="value"
  554. placeholder="Please select"
  555. />
  556. </div>
  557. );
  558. Disabled.story = {
  559. name: 'disabled',
  560. };
  561. Disabled.parameters = {
  562. chromatic: { disableSnapshot: false },
  563. }
  564. export const OptionLabelProp = () => (
  565. <>
  566. <TreeSelect
  567. style={{ width: 300 }}
  568. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  569. treeData={treeData2}
  570. multiple
  571. filterTreeNode
  572. treeNodeFilterProp="value"
  573. treeNodeLabelProp="value"
  574. placeholder="Please select"
  575. />
  576. </>
  577. );
  578. OptionLabelProp.story = {
  579. name: 'optionLabelProp',
  580. };
  581. export const ValueInArray = () => (
  582. <>
  583. <TreeSelect
  584. style={{ width: 300 }}
  585. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  586. treeData={treeData2}
  587. multiple
  588. filterTreeNode
  589. valueInArray
  590. onChange={(...args) => console.log(args)}
  591. treeNodeFilterProp="value"
  592. treeNodeLabelProp="value"
  593. placeholder="Please select"
  594. />
  595. </>
  596. );
  597. ValueInArray.story = {
  598. name: 'valueInArray',
  599. };
  600. export const OnBlurOnFocus = () => (
  601. <>
  602. <div>single</div>
  603. <TreeSelect
  604. style={{ width: 300 }}
  605. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  606. treeData={treeData2}
  607. onBlur={(...args) => console.log('blur', args)}
  608. onFocus={(...args) => console.log('focus', args)}
  609. placeholder="Please select"
  610. />
  611. <div>multiple</div>
  612. <TreeSelect
  613. style={{ width: 300 }}
  614. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  615. treeData={treeData2}
  616. multiple
  617. onBlur={(...args) => console.log('blur', args)}
  618. onFocus={(...args) => console.log('focus', args)}
  619. placeholder="Please select"
  620. />
  621. </>
  622. );
  623. OnBlurOnFocus.story = {
  624. name: 'onBlur/onFocus',
  625. };
  626. export const LeafOnly = () => (
  627. <div>
  628. <TreeSelect
  629. style={{ width: 300 }}
  630. // value={this.state.value}
  631. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  632. treeData={treeData2}
  633. multiple
  634. leafOnly
  635. placeholder="Please select"
  636. onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
  637. onSelect={(e, bool) => console.log('select', e, bool)}
  638. onChange={e => console.log('change', e)}
  639. />
  640. </div>
  641. );
  642. LeafOnly.story = {
  643. name: 'leafOnly',
  644. };
  645. class Demo extends React.Component {
  646. constructor() {
  647. super();
  648. this.state = {
  649. value: 'shanghai',
  650. };
  651. }
  652. onChange(value) {
  653. this.setState({ value });
  654. }
  655. render() {
  656. return (
  657. <TreeSelect
  658. style={{ width: 300 }}
  659. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  660. treeData={treeData2}
  661. value={this.state.value}
  662. placeholder="Please select"
  663. onChange={e => this.onChange(e)}
  664. />
  665. );
  666. }
  667. }
  668. export const ControlledComponentSingle = () => <Demo />;
  669. ControlledComponentSingle.story = {
  670. name: 'controlled Component single',
  671. };
  672. class Demo2 extends React.Component {
  673. constructor() {
  674. super();
  675. this.state = {
  676. value: ['Shanghai'],
  677. };
  678. }
  679. onChange(value) {
  680. this.setState({ value });
  681. }
  682. render() {
  683. console.log(this.state.value);
  684. const treeData = [
  685. {
  686. label: '亚洲',
  687. value: 'Asia',
  688. key: '0',
  689. children: [
  690. {
  691. label: '中国',
  692. value: 'China',
  693. key: '0-0',
  694. children: [
  695. {
  696. label: '北京',
  697. value: 'Beijing',
  698. key: '0-0-0',
  699. },
  700. {
  701. label: '上海',
  702. value: 'Shanghai',
  703. key: '0-0-1',
  704. },
  705. ],
  706. },
  707. ],
  708. },
  709. {
  710. label: '北美洲',
  711. value: 'North America',
  712. key: '1',
  713. },
  714. ];
  715. return (
  716. <TreeSelect
  717. style={{ width: 300 }}
  718. multiple
  719. dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
  720. treeData={treeData}
  721. value={this.state.value}
  722. placeholder="Please select"
  723. onChange={e => this.onChange(e)}
  724. />
  725. );
  726. }
  727. }
  728. export const ControlledComponentMultiple = () => <Demo2 />;
  729. ControlledComponentMultiple.story = {
  730. name: 'controlled Component multiple',
  731. };
  732. class Demo3 extends React.Component {
  733. constructor() {
  734. super();
  735. this.state = {
  736. value: ['Shanghai'],
  737. };
  738. }
  739. // 获取最底层值
  740. getDeepChildrensByNode = node => {
  741. return flattenDeep(
  742. node.map(item => {
  743. if (item.children) {
  744. return this.getDeepChildrensByNode(item.children);
  745. }
  746. return item.value;
  747. })
  748. );
  749. };
  750. onChange(value, node) {
  751. console.log('onchange', value);
  752. value = this.getDeepChildrensByNode(node);
  753. console.log('modifiled', value);
  754. this.setState({ value });
  755. }
  756. render() {
  757. const treeData = [
  758. {
  759. label: '亚洲',
  760. value: 'Asia',
  761. key: '0',
  762. children: [
  763. {
  764. label: '中国',
  765. value: 'China',
  766. key: '0-0',
  767. children: [
  768. {
  769. label: '北京',
  770. value: 'Beijing',
  771. key: '0-0-0',
  772. },
  773. {
  774. label: '上海',
  775. value: 'Shanghai',
  776. key: '0-0-1',
  777. },
  778. ],
  779. },
  780. ],
  781. },
  782. {
  783. label: '北美洲',
  784. value: 'North America',
  785. key: '1',
  786. },
  787. ];
  788. return (
  789. <TreeSelect
  790. style={{ width: 300 }}
  791. multiple
  792. dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
  793. treeData={treeData}
  794. value={this.state.value}
  795. placeholder="Please select"
  796. onChange={(e, node) => this.onChange(e, node)}
  797. />
  798. );
  799. }
  800. }
  801. export const ControlledComponentMultipleValueModified = () => <Demo3 />;
  802. ControlledComponentMultipleValueModified.story = {
  803. name: 'controlled Component multiple value modified',
  804. };
  805. class ConvertDemo extends React.Component {
  806. constructor(props) {
  807. super(props);
  808. this.formApi = null;
  809. }
  810. handleChange = val => {
  811. let finalVal = val;
  812. let firstClassOption = ['Asia', 'North America'];
  813. // 在这里去做你的value替换逻辑
  814. console.log('originVal:' + val);
  815. if (val.length === 1) {
  816. // do nothing
  817. } else {
  818. if (val.every(item => firstClassOption.includes(item))) {
  819. finalVal = val[val.length - 1];
  820. }
  821. }
  822. console.log('finalVal:' + finalVal);
  823. return finalVal;
  824. };
  825. render() {
  826. const treeData = [
  827. {
  828. label: '亚洲',
  829. value: 'Asia',
  830. key: '0',
  831. children: [
  832. {
  833. label: '中国',
  834. value: 'China',
  835. key: '0-0',
  836. children: [
  837. {
  838. label: '北京',
  839. value: 'Beijing',
  840. key: '0-0-0',
  841. },
  842. {
  843. label: '上海',
  844. value: 'Shanghai',
  845. key: '0-0-1',
  846. },
  847. ],
  848. },
  849. ],
  850. },
  851. {
  852. label: '北美洲',
  853. value: 'North America',
  854. key: '1',
  855. },
  856. ];
  857. return (
  858. <Form getFormApi={this.getFormApi}>
  859. <Form.TreeSelect
  860. field="tree"
  861. label="节点(TreeSelect)"
  862. placeholder="请选择服务节点"
  863. treeData={treeData}
  864. convert={this.handleChange}
  865. filterTreeNode
  866. multiple
  867. ></Form.TreeSelect>
  868. </Form>
  869. );
  870. }
  871. }
  872. export const _ConvertDemo = () => <ConvertDemo />;
  873. _ConvertDemo.story = {
  874. name: 'convert demo',
  875. };
  876. export const TreeselectDefaultOpenInPopover = () => (
  877. <Popover
  878. content={
  879. <TreeSelect
  880. style={{ width: 200 }}
  881. dropdownStyle={{ width: 200 }}
  882. treeData={treeData1}
  883. defaultOpen
  884. // value={this.state.value}
  885. // placeholder="Please select"
  886. // onChange={(e, node) => this.onChange(e, node)}
  887. />
  888. }
  889. >
  890. <Button style={{ marginLeft: 150 }}>悬停此处</Button>
  891. </Popover>
  892. );
  893. TreeselectDefaultOpenInPopover.story = {
  894. name: 'treeselect defaultOpen in popover',
  895. };
  896. export const CustomTriggerDemo = () => <CustomTrigger />;
  897. CustomTriggerDemo.story = { name: 'custom trigger' };
  898. const AutoParentDemo = () => {
  899. const [expandedKeys, setExpandedKeys] = useState(['beimeizhou']);
  900. const [selectedKeys, setSelectedKeys] = useState(['beimeizhou']);
  901. const [autoExpandParent, setAutoExpandParent] = useState(true);
  902. const onExpand = expandedKeys => {
  903. console.log('onExpand', expandedKeys);
  904. // if not set autoExpandParent to false, if children expanded, parent can not collapse.
  905. // or, you can remove all expanded children keys.
  906. setExpandedKeys(expandedKeys);
  907. setAutoExpandParent(false);
  908. };
  909. const onSelect = (selectedKeys, info) => {
  910. console.log('onSelect:', info);
  911. setSelectedKeys(selectedKeys);
  912. };
  913. return (
  914. <div>
  915. <Button
  916. onClick={() => {
  917. setSelectedKeys(['beijing']);
  918. setExpandedKeys(['beijing']);
  919. setAutoExpandParent(true);
  920. }}
  921. >
  922. Update
  923. </Button>
  924. <TreeSelect
  925. onExpand={onExpand}
  926. expandedKeys={expandedKeys}
  927. autoExpandParent={autoExpandParent}
  928. onChange={onSelect}
  929. value={selectedKeys}
  930. treeData={treeData2}
  931. // multiple
  932. />
  933. </div>
  934. );
  935. };
  936. export const AutoExpandParent = () => (
  937. <>
  938. <AutoParentDemo />
  939. </>
  940. );
  941. AutoExpandParent.story = {
  942. name: 'autoExpandParent',
  943. };
  944. export const TreeWithoutValueProps = () => (
  945. <TreeSelect
  946. treeData={treeDataWithoutValue}
  947. value="beijing"
  948. defaultExpandAll
  949. onChange={(...args) => console.log(args)}
  950. />
  951. );
  952. TreeWithoutValueProps.story = {
  953. name: 'tree without value props',
  954. };
  955. export const TreeSelectRenderSelectedItem = () => {
  956. const treeData = [
  957. {
  958. label: '亚洲',
  959. value: 'Asia',
  960. key: '0',
  961. children: [
  962. {
  963. label: '中国',
  964. value: 'China',
  965. key: '0-0',
  966. children: [
  967. {
  968. label: '北京',
  969. value: 'Beijing',
  970. key: '0-0-0',
  971. },
  972. {
  973. label: '上海',
  974. value: 'Shanghai',
  975. key: '0-0-1',
  976. },
  977. ],
  978. },
  979. ],
  980. },
  981. {
  982. label: '北美洲',
  983. value: 'North America',
  984. key: '1',
  985. },
  986. {
  987. label: '南美洲',
  988. value: 'South America',
  989. key: '2',
  990. },
  991. {
  992. label: '南极洲',
  993. value: 'Antarctica',
  994. key: '3',
  995. },
  996. ];
  997. return (
  998. <>
  999. <h4>单选</h4>
  1000. <TreeSelect
  1001. style={{ width: 300 }}
  1002. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1003. treeData={treeData}
  1004. placeholder="请选择"
  1005. renderSelectedItem={item => `${item.value}-${item.label}`}
  1006. />
  1007. <h4>多选</h4>
  1008. <TreeSelect
  1009. style={{ width: 300 }}
  1010. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1011. treeData={treeData}
  1012. multiple
  1013. placeholder="请选择"
  1014. renderSelectedItem={(item, { index, onClose }) => ({
  1015. content: `${item.value}-${item.label}`,
  1016. isRenderInTag: true,
  1017. })}
  1018. />
  1019. <h4>多选 + isRenderInTag=false</h4>
  1020. <TreeSelect
  1021. style={{ width: 300 }}
  1022. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1023. treeData={treeData}
  1024. multiple
  1025. maxTagCount={2}
  1026. placeholder="请选择"
  1027. renderSelectedItem={(item, { index, onClose }) => ({
  1028. content: (
  1029. <Tag key={index} color="white">
  1030. {item.value}
  1031. </Tag>
  1032. ),
  1033. isRenderInTag: false,
  1034. })}
  1035. />
  1036. </>
  1037. );
  1038. };
  1039. TreeSelectRenderSelectedItem.story = {
  1040. name: 'treeSelect renderSelectedItem',
  1041. };
  1042. const DisableStrictlyDemo = () => {
  1043. const [value, setValue] = useState(['Shanghai']);
  1044. const treeData = [
  1045. {
  1046. label: '亚洲',
  1047. value: 'Asia',
  1048. key: '0',
  1049. children: [
  1050. {
  1051. label: '中国',
  1052. value: 'China',
  1053. key: '0-0',
  1054. disabled: true,
  1055. children: [
  1056. {
  1057. label: '北京',
  1058. value: 'Beijing',
  1059. key: '0-0-0',
  1060. },
  1061. {
  1062. label: '上海',
  1063. value: 'Shanghai',
  1064. key: '0-0-1',
  1065. },
  1066. ],
  1067. },
  1068. {
  1069. label: '日本',
  1070. value: 'Japan',
  1071. key: '0-1',
  1072. },
  1073. ],
  1074. },
  1075. {
  1076. label: '北美洲',
  1077. value: 'North America',
  1078. key: '1',
  1079. },
  1080. ];
  1081. return (
  1082. <div>
  1083. <TreeSelect
  1084. style={{ width: 300 }}
  1085. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1086. treeData={treeData}
  1087. disableStrictly
  1088. multiple
  1089. searchPosition="trigger"
  1090. filterTreeNode
  1091. value={value}
  1092. onChange={value => setValue(value)}
  1093. />
  1094. </div>
  1095. );
  1096. };
  1097. export const DisabledStrictly = () => (
  1098. <>
  1099. <DisableStrictlyDemo />
  1100. </>
  1101. );
  1102. DisabledStrictly.story = {
  1103. name: 'disabledStrictly',
  1104. };
  1105. export const CheckRelationDemo = () => {
  1106. const treeData = [
  1107. {
  1108. label: 'Asia',
  1109. value: 'Asia',
  1110. key: '0',
  1111. children: [
  1112. {
  1113. label: 'China',
  1114. value: 'China',
  1115. key: '0-0',
  1116. children: [
  1117. {
  1118. label: 'Beijing',
  1119. value: 'Beijing',
  1120. key: '0-0-0',
  1121. },
  1122. {
  1123. label: 'Shanghai',
  1124. value: 'Shanghai',
  1125. key: '0-0-1',
  1126. },
  1127. {
  1128. label: 'Chengdu',
  1129. value: 'Chengdu',
  1130. key: '0-0-2',
  1131. },
  1132. ],
  1133. },
  1134. {
  1135. label: 'Japan',
  1136. value: 'Japan',
  1137. key: '0-1',
  1138. children: [
  1139. {
  1140. label: 'Osaka',
  1141. value: 'Osaka',
  1142. key: '0-1-0'
  1143. }
  1144. ]
  1145. },
  1146. ],
  1147. },
  1148. {
  1149. label: 'North America',
  1150. value: 'North America',
  1151. key: '1',
  1152. children: [
  1153. {
  1154. label: 'United States',
  1155. value: 'United States',
  1156. key: '1-0'
  1157. },
  1158. {
  1159. label: 'Canada',
  1160. value: 'Canada',
  1161. key: '1-1'
  1162. }
  1163. ]
  1164. }
  1165. ];
  1166. const [value, setValue] = useState('China');
  1167. const [value2, setValue2] = useState();
  1168. const [value3, setValue3] = useState();
  1169. const style = {
  1170. width: 300,
  1171. };
  1172. const dropdownStyle = {
  1173. maxHeight: 400,
  1174. overflow: 'auto'
  1175. };
  1176. const handleChange = value => {
  1177. console.log(value);
  1178. setValue(value);
  1179. };
  1180. const handleChange2 = value => {
  1181. console.log(value);
  1182. setValue2(value);
  1183. };
  1184. const handleChange3 = value => {
  1185. console.log(value);
  1186. setValue3(value);
  1187. };
  1188. return (
  1189. <>
  1190. <div>checkRelation='unRelated'</div>
  1191. <TreeSelect
  1192. dropdownStyle={dropdownStyle}
  1193. treeData={treeData}
  1194. multiple
  1195. checkRelation='unRelated'
  1196. defaultExpandAll
  1197. style={style}
  1198. />
  1199. <br /><br />
  1200. <div>checkRelation='unRelated' + maxTagCount=2</div>
  1201. <TreeSelect
  1202. dropdownStyle={dropdownStyle}
  1203. treeData={treeData}
  1204. multiple
  1205. maxTagCount={2}
  1206. checkRelation='unRelated'
  1207. defaultExpandAll
  1208. style={style}
  1209. />
  1210. <br /><br />
  1211. <div>checkRelation='unRelated' + maxTagCount=2 + 开启搜索</div>
  1212. <TreeSelect
  1213. dropdownStyle={dropdownStyle}
  1214. treeData={treeData}
  1215. multiple
  1216. maxTagCount={2}
  1217. filterTreeNode
  1218. checkRelation='unRelated'
  1219. defaultExpandAll
  1220. style={style}
  1221. />
  1222. <br /><br />
  1223. <div>checkRelation='unRelated' + maxTagCount=2 + 开启搜索 + searchBox in trigger</div>
  1224. <TreeSelect
  1225. dropdownStyle={dropdownStyle}
  1226. treeData={treeData}
  1227. multiple
  1228. maxTagCount={2}
  1229. filterTreeNode
  1230. checkRelation='unRelated'
  1231. searchPosition='trigger'
  1232. defaultExpandAll
  1233. style={style}
  1234. />
  1235. <br /><br />
  1236. <div>checkRelation='unRelated' + 中国节点为 disabled</div>
  1237. <TreeSelect
  1238. dropdownStyle={dropdownStyle}
  1239. treeData={treeDataWithoutValue}
  1240. multiple
  1241. checkRelation='unRelated'
  1242. defaultExpandAll
  1243. style={style}
  1244. />
  1245. <br /><br />
  1246. <div>checkRelation='unRelated' + 中国节点为 disabled + 严格禁用</div>
  1247. <TreeSelect
  1248. dropdownStyle={dropdownStyle}
  1249. treeData={treeDataWithoutValue}
  1250. multiple
  1251. checkRelation='unRelated'
  1252. defaultExpandAll
  1253. disableStrictly
  1254. style={style}
  1255. />
  1256. <br /><br />
  1257. <div>checkRelation='unRelated' + defaultValue 为 China</div>
  1258. <TreeSelect
  1259. dropdownStyle={dropdownStyle}
  1260. treeData={treeData}
  1261. multiple
  1262. checkRelation='unRelated'
  1263. defaultExpandAll
  1264. style={style}
  1265. defaultValue='China'
  1266. />
  1267. <br /><br />
  1268. <div>checkRelation='unRelated' + defaultValue 为 China + 开启搜索</div>
  1269. <TreeSelect
  1270. dropdownStyle={dropdownStyle}
  1271. treeData={treeData}
  1272. multiple
  1273. filterTreeNode
  1274. checkRelation='unRelated'
  1275. defaultExpandAll
  1276. style={style}
  1277. defaultValue='China'
  1278. />
  1279. <br /><br />
  1280. <div>多选 + checkRelation='unRelated' + defaultValue 为 China + 开启搜索 + searchBox in trigger + showClear</div>
  1281. <TreeSelect
  1282. dropdownStyle={dropdownStyle}
  1283. treeData={treeData}
  1284. multiple
  1285. filterTreeNode
  1286. showClear
  1287. checkRelation='unRelated'
  1288. defaultExpandAll
  1289. style={style}
  1290. searchPosition='trigger'
  1291. defaultValue={['China', 'Japan']}
  1292. />
  1293. <br /><br />
  1294. <div>单选 + checkRelation='unRelated' + defaultValue 为 China + 开启搜索 + searchBox in trigger + showClear</div>
  1295. <TreeSelect
  1296. dropdownStyle={dropdownStyle}
  1297. treeData={treeData}
  1298. filterTreeNode
  1299. showClear
  1300. checkRelation='unRelated'
  1301. defaultExpandAll
  1302. style={style}
  1303. searchPosition='trigger'
  1304. defaultValue='China'
  1305. />
  1306. <br /><br />
  1307. <div>checkRelation='unRelated' + 受控 + value 初始为 China</div>
  1308. <TreeSelect
  1309. dropdownStyle={dropdownStyle}
  1310. treeData={treeData}
  1311. multiple
  1312. checkRelation='unRelated'
  1313. defaultExpandAll
  1314. style={style}
  1315. value={value}
  1316. onChange={handleChange}
  1317. />
  1318. <br /><br />
  1319. <div>checkRelation='unRelated' + 受控 + onChangeWithObject</div>
  1320. <TreeSelect
  1321. dropdownStyle={dropdownStyle}
  1322. treeData={treeData}
  1323. multiple
  1324. checkRelation='unRelated'
  1325. defaultExpandAll
  1326. style={style}
  1327. value={value2}
  1328. onChangeWithObject
  1329. onChange={handleChange2}
  1330. />
  1331. <br /><br />
  1332. <div>checkRelation='unRelated' + 受控 + leafOnly,此时 leafOnly 失效</div>
  1333. <TreeSelect
  1334. dropdownStyle={dropdownStyle}
  1335. leafOnly
  1336. treeData={treeData}
  1337. multiple
  1338. checkRelation='unRelated'
  1339. defaultExpandAll
  1340. style={style}
  1341. value={value3}
  1342. onChange={handleChange3}
  1343. />
  1344. <br /><br />
  1345. <div>checkRelation='unRelated' + onSelect </div>
  1346. <TreeSelect
  1347. dropdownStyle={dropdownStyle}
  1348. treeData={treeData}
  1349. multiple
  1350. checkRelation='unRelated'
  1351. defaultExpandAll
  1352. style={style}
  1353. onSelect={(value,status,node)=>console.log('select', value, status, node)}
  1354. />
  1355. </>
  1356. );
  1357. };
  1358. export const SearchableAndExpandedKeys = () => {
  1359. const [expandedKeys1, setExpandedKeys1] = useState([]);
  1360. const [expandedKeys2, setExpandedKeys2] = useState([]);
  1361. const [expandedKeys3, setExpandedKeys3] = useState([]);
  1362. return (
  1363. <>
  1364. <Title heading={6}>expandedKeys 受控</Title>
  1365. <TreeSelect
  1366. style={{ width: 300, marginBottom: 30 }}
  1367. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1368. treeData={treeData2}
  1369. expandedKeys={expandedKeys1}
  1370. defaultValue='beijing'
  1371. onExpand={v => {
  1372. console.log('onExpand value: ', v);
  1373. setExpandedKeys1(v);
  1374. }}
  1375. />
  1376. <Title heading={6}>expandedKeys 受控 + 开启搜索</Title>
  1377. <TreeSelect
  1378. style={{ width: 300, marginBottom: 30 }}
  1379. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1380. treeData={treeData2}
  1381. filterTreeNode
  1382. defaultValue='beijing'
  1383. expandedKeys={expandedKeys2}
  1384. onExpand={v => {
  1385. console.log('onExpand value: ', v);
  1386. setExpandedKeys2(v);
  1387. }}
  1388. />
  1389. <Title heading={6}>expandedKeys 受控 + 开启搜索 + 搜索时更新 expandedKeys</Title>
  1390. <TreeSelect
  1391. style={{ width: 300, marginBottom: 30 }}
  1392. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1393. treeData={treeData2}
  1394. filterTreeNode
  1395. expandedKeys={expandedKeys3}
  1396. defaultValue='beijing'
  1397. onExpand={v => {
  1398. console.log('onExpand value: ', v);
  1399. setExpandedKeys3(v)
  1400. }}
  1401. onSearch={(input, filterExpandedKeys) => {
  1402. console.log('onExpand filterExpandedKeys: ', filterExpandedKeys);
  1403. setExpandedKeys3(filterExpandedKeys);
  1404. }}
  1405. />
  1406. </>
  1407. )
  1408. }
  1409. export const loadData = () => {
  1410. const initialData = [
  1411. {
  1412. label: 'Expand to load',
  1413. value: '0',
  1414. key: '0',
  1415. },
  1416. {
  1417. label: 'Expand to load',
  1418. value: '1',
  1419. key: '1',
  1420. },
  1421. {
  1422. label: 'Leaf Node',
  1423. value: '2',
  1424. key: '2',
  1425. isLeaf: true,
  1426. },
  1427. ];
  1428. const [treeData, setTreeData] = useState(initialData);
  1429. const [loadedKeys, setLoadedKeys] = useState(['2']);
  1430. function updateTreeData(list, key, children) {
  1431. return list.map(node => {
  1432. if (node.key === key) {
  1433. return { ...node, children };
  1434. }
  1435. if (node.children) {
  1436. return { ...node, children: updateTreeData(node.children, key, children) };
  1437. }
  1438. return node;
  1439. });
  1440. }
  1441. function onLoadData({ key, children }) {
  1442. return new Promise(resolve => {
  1443. if (children) {
  1444. resolve();
  1445. return;
  1446. }
  1447. setTimeout(() => {
  1448. setTreeData(origin =>
  1449. updateTreeData(origin, key, [
  1450. {
  1451. label: 'Child Node',
  1452. key: `${key}-0`,
  1453. },
  1454. {
  1455. label: 'Child Node',
  1456. key: `${key}-1`,
  1457. },
  1458. ]),
  1459. );
  1460. resolve();
  1461. }, 1000);
  1462. });
  1463. }
  1464. return (
  1465. <TreeSelect
  1466. loadData={onLoadData}
  1467. filterTreeNode
  1468. treeData={treeData}
  1469. style={{ width: 300 }}
  1470. placeholder="请选择"
  1471. />
  1472. );
  1473. }
  1474. export const loadDataAndLoadedkeys = () => {
  1475. const initialData = [
  1476. {
  1477. label: 'Expand to load',
  1478. value: '0',
  1479. key: '0',
  1480. },
  1481. {
  1482. label: 'Expand to load',
  1483. value: '1',
  1484. key: '1',
  1485. },
  1486. {
  1487. label: 'Leaf Node',
  1488. value: '2',
  1489. key: '2',
  1490. isLeaf: true,
  1491. },
  1492. ];
  1493. const [treeData, setTreeData] = useState(initialData);
  1494. const [loadedKeys, setLoadedKeys] = useState(['2']);
  1495. function updateTreeData(list, key, children) {
  1496. return list.map(node => {
  1497. if (node.key === key) {
  1498. return { ...node, children };
  1499. }
  1500. if (node.children) {
  1501. return { ...node, children: updateTreeData(node.children, key, children) };
  1502. }
  1503. return node;
  1504. });
  1505. }
  1506. function updateLoadedKeys(key) {
  1507. if(!loadedKeys.includes(key)){
  1508. setLoadedKeys([...loadedKeys, key]);
  1509. console.log('[...loadedKeys, key]', [...loadedKeys, key]);
  1510. }
  1511. }
  1512. function onLoadData({ key, children }) {
  1513. return new Promise(resolve => {
  1514. if (children) {
  1515. resolve();
  1516. return;
  1517. }
  1518. setTimeout(() => {
  1519. setTreeData(origin =>
  1520. updateTreeData(origin, key, [
  1521. {
  1522. label: 'Child Node',
  1523. key: `${key}-0`,
  1524. },
  1525. {
  1526. label: 'Child Node',
  1527. key: `${key}-1`,
  1528. },
  1529. ]),
  1530. );
  1531. // updateLoadedKeys(key);
  1532. resolve();
  1533. }, 1000);
  1534. });
  1535. }
  1536. return (
  1537. <TreeSelect
  1538. loadData={onLoadData}
  1539. filterTreeNode
  1540. // loadedKeys={loadedKeys}
  1541. treeData={treeData}
  1542. style={{ width: 300 }}
  1543. placeholder="请选择"
  1544. />
  1545. );
  1546. }