treeSelect.stories.jsx 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348
  1. import React, { useState, useMemo, useRef, useCallback } from 'react';
  2. import { Icon, Input, Button, Form, Popover, Tag, Typography, CheckboxGroup, TagInput } from '../../index';
  3. import TreeSelect from '../index';
  4. import { flattenDeep } from 'lodash';
  5. import CustomTrigger from './CustomTrigger';
  6. import { IconCreditCard, IconChevronDown, IconClose } from '@douyinfe/semi-icons';
  7. import { setFocusToPreviousMenuItem } from '@douyinfe/semi-foundation/utils/a11y';
  8. const TreeNode = TreeSelect.TreeNode;
  9. const { Title } = Typography;
  10. export default {
  11. title: 'TreeSelect',
  12. parameters: {
  13. chromatic: { disableSnapshot: true },
  14. },
  15. }
  16. const treeData1 = [
  17. {
  18. label: 'Node1',
  19. value: '0-0',
  20. key: '0-0',
  21. children: [
  22. {
  23. label: 'Child Node1',
  24. value: '0-0-1',
  25. key: '0-0-1',
  26. },
  27. {
  28. label: 'Child Node2',
  29. value: '0-0-2',
  30. key: '0-0-2',
  31. },
  32. ],
  33. },
  34. {
  35. label: 'Node2',
  36. value: '0-1',
  37. key: '0-1',
  38. },
  39. ];
  40. const treeData2 = [
  41. {
  42. label: '亚洲',
  43. value: 'yazhou',
  44. key: 'yazhou',
  45. children: [
  46. {
  47. label: '中国',
  48. value: 'zhongguo',
  49. key: 'zhongguo',
  50. children: [
  51. {
  52. label: '北京',
  53. value: 'beijing',
  54. key: 'beijing',
  55. },
  56. {
  57. label: '上海',
  58. value: 'shanghai',
  59. key: 'shanghai',
  60. },
  61. ],
  62. },
  63. // {
  64. // label: '日本',
  65. // value: 'riben',
  66. // key: 'riben',
  67. // children: [
  68. // {
  69. // label: '东京',
  70. // value: 'dongjing',
  71. // key: 'dongjing'
  72. // },
  73. // {
  74. // label: '大阪',
  75. // value: 'daban',
  76. // key: 'daban'
  77. // }
  78. // ]
  79. // },
  80. ],
  81. },
  82. {
  83. label: '北美洲',
  84. value: 'beimeizhou',
  85. key: 'beimeizhou',
  86. children: [
  87. {
  88. label: '美国',
  89. value: 'meiguo',
  90. key: 'meiguo',
  91. },
  92. {
  93. label: '加拿大',
  94. value: 'jianada',
  95. key: 'jianada',
  96. },
  97. ],
  98. },
  99. ];
  100. const treeData3 = [
  101. {
  102. label: 'Node1',
  103. value: '0-0',
  104. key: '0-0',
  105. children: [
  106. {
  107. label: 'Child Node1',
  108. value: '0-0-1',
  109. key: '0-0-1',
  110. },
  111. {
  112. label: 'Child Node2',
  113. value: '0-0-2',
  114. key: '0-0-2',
  115. },
  116. {
  117. label: 'Child Node3',
  118. value: '0-0-3',
  119. key: '0-0-3',
  120. },
  121. {
  122. label: 'Child Node4',
  123. value: '0-0-4',
  124. key: '0-0-4',
  125. },
  126. {
  127. label: 'Child Node5',
  128. value: '0-0-5',
  129. key: '0-0-5',
  130. },
  131. {
  132. label: 'Child Node6',
  133. value: '0-0-6',
  134. key: '0-0-6',
  135. },
  136. {
  137. label: 'Child Node7',
  138. value: '0-0-7',
  139. key: '0-0-7',
  140. },
  141. {
  142. label: 'Child Node8',
  143. value: '0-0-8',
  144. key: '0-0-8',
  145. },
  146. {
  147. label: 'Child Node9',
  148. value: '0-0-9',
  149. key: '0-0-9',
  150. },
  151. {
  152. label: 'Child Node10',
  153. value: '0-0-10',
  154. key: '0-0-10',
  155. },
  156. ],
  157. },
  158. {
  159. label: 'Node2',
  160. value: '0-1',
  161. key: '0-1',
  162. },
  163. ];
  164. const treeDataWithoutValue = [
  165. {
  166. label: '亚洲',
  167. key: 'yazhou',
  168. children: [
  169. {
  170. label: '中国',
  171. key: 'zhongguo',
  172. disabled: true,
  173. children: [
  174. {
  175. label: '北京',
  176. key: 'beijing',
  177. },
  178. {
  179. label: '上海',
  180. key: 'shanghai',
  181. },
  182. ],
  183. },
  184. {
  185. label: '日本',
  186. key: 'riben',
  187. children: [
  188. {
  189. label: '东京',
  190. key: 'dongjing',
  191. },
  192. {
  193. label: '大阪',
  194. key: 'daban',
  195. },
  196. ],
  197. },
  198. ],
  199. },
  200. {
  201. label: '北美洲',
  202. key: 'beimeizhou',
  203. children: [
  204. {
  205. label: '美国',
  206. key: 'meiguo',
  207. },
  208. {
  209. label: '加拿大',
  210. key: 'jianada',
  211. },
  212. ],
  213. },
  214. ];
  215. export const TreeSelectWrapper = () => (
  216. <div>
  217. <div>github issue 750 修改测试用例</div>
  218. <CheckboxGroup>
  219. <TreeSelect
  220. showClear={true}
  221. expandAll
  222. style={{width: 400}}
  223. treeData={[
  224. {
  225. key: '1',
  226. label: '所有节点',
  227. value: '1',
  228. children: [
  229. { key: '20006251', label: 'Semi', value: '[email protected]' },
  230. { key: '20006248', label: 'Design', value: '[email protected]' },
  231. {
  232. key: '20006205',
  233. label: 'React',
  234. value: '[email protected]',
  235. },
  236. ],
  237. },
  238. ]}
  239. multiple
  240. filterTreeNode
  241. showFilteredOnly={true}
  242. leafOnly
  243. />
  244. </CheckboxGroup>
  245. </div>
  246. );
  247. TreeSelectWrapper.story = {
  248. name: 'treeSelect wrapper',
  249. };
  250. class SimpleTree extends React.Component {
  251. render() {
  252. return (
  253. <div>
  254. <TreeSelect
  255. style={{ width: 300 }}
  256. // value={this.state.value}
  257. dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
  258. treeData={treeData1}
  259. placeholder="Please select"
  260. onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
  261. onSelect={(e, bool) => console.log('select', e, bool)}
  262. onChange={(e, node) => console.log('change', e, node)}
  263. />
  264. <br />
  265. <br />
  266. <TreeSelect
  267. style={{ width: 300 }}
  268. // value={this.state.value}
  269. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  270. treeData={treeData2}
  271. placeholder="Please select"
  272. />
  273. </div>
  274. );
  275. }
  276. }
  277. export const _TreeSelect = () => {
  278. const treeData = [
  279. {
  280. label: '亚洲',
  281. value: 'Asia',
  282. key: '0',
  283. children: [
  284. {
  285. label: '中国',
  286. value: 'China',
  287. key: '0-0',
  288. children: [
  289. {
  290. label: '北京',
  291. value: 'Beijing',
  292. key: '0-0-0',
  293. },
  294. {
  295. label: '上海',
  296. value: 'Shanghai',
  297. key: '0-0-1',
  298. },
  299. ],
  300. },
  301. ],
  302. },
  303. {
  304. label: '北美洲',
  305. value: 'North America',
  306. key: '1',
  307. },
  308. ];
  309. return (
  310. <TreeSelect
  311. style={{ width: 300 }}
  312. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  313. treeData={treeData2}
  314. placeholder="请选择"
  315. />
  316. );
  317. };
  318. _TreeSelect.story = {
  319. name: 'tree select',
  320. };
  321. export const Searchable = () => (
  322. <div>
  323. <TreeSelect
  324. style={{ width: 300 }}
  325. // value={this.state.value}
  326. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  327. treeData={treeData2}
  328. filterTreeNode
  329. treeNodeFilterProp="value"
  330. placeholder="Please select"
  331. />
  332. <br />
  333. <br />
  334. <TreeSelect
  335. style={{ width: 300 }}
  336. // value={this.state.value}
  337. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  338. treeData={treeData2}
  339. filterTreeNode
  340. placeholder="Please select"
  341. />
  342. <br />
  343. <br />
  344. <TreeSelect
  345. style={{ width: 300 }}
  346. // value={this.state.value}
  347. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  348. treeData={treeData2}
  349. filterTreeNode
  350. searchAutoFocus
  351. placeholder="searchAutoFocus"
  352. />
  353. </div>
  354. );
  355. Searchable.story = {
  356. name: 'searchable',
  357. };
  358. export const SearchPosition = () => (
  359. <>
  360. <TreeSelect
  361. searchPosition="trigger"
  362. style={{ width: 300 }}
  363. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  364. treeData={treeData2}
  365. filterTreeNode
  366. placeholder="单选"
  367. />
  368. <br />
  369. <br />
  370. <TreeSelect
  371. searchPosition="trigger"
  372. style={{ width: 300 }}
  373. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  374. treeData={treeData2}
  375. multiple
  376. filterTreeNode
  377. maxTagCount={2}
  378. placeholder="多选"
  379. />
  380. <br />
  381. <br />
  382. <TreeSelect
  383. searchPosition="trigger"
  384. style={{ width: 300 }}
  385. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  386. treeData={treeData2}
  387. multiple
  388. filterTreeNode
  389. maxTagCount={2}
  390. placeholder="searchAutoFocus"
  391. searchAutoFocus
  392. />
  393. <br />
  394. <br />
  395. <TreeSelect
  396. searchPosition="trigger"
  397. style={{ width: 300 }}
  398. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  399. treeData={treeData2}
  400. multiple
  401. filterTreeNode
  402. maxTagCount={1}
  403. placeholder="maxTagCount=1"
  404. />
  405. </>
  406. );
  407. SearchPosition.story = {
  408. name: 'searchPosition',
  409. };
  410. export const PrefixSuffixInsetLabel = () => (
  411. <div>
  412. <TreeSelect
  413. style={{ width: 300 }}
  414. // value={this.state.value}
  415. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  416. treeData={treeData2}
  417. filterTreeNode
  418. prefix={<IconCreditCard />}
  419. treeNodeFilterProp="value"
  420. placeholder="Please select"
  421. />
  422. <br />
  423. <br />
  424. <TreeSelect
  425. style={{ width: 300 }}
  426. // value={this.state.value}
  427. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  428. treeData={treeData2}
  429. filterTreeNode
  430. prefix={<span>1234</span>}
  431. treeNodeFilterProp="value"
  432. placeholder="Please select"
  433. />
  434. <br />
  435. <br />
  436. <TreeSelect
  437. style={{ width: 300 }}
  438. suffix="RMB"
  439. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  440. treeData={treeData2}
  441. placeholder="Please select"
  442. />
  443. <br />
  444. <br />
  445. <TreeSelect
  446. style={{ width: 300 }}
  447. insetLabel="blablabla"
  448. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  449. treeData={treeData2}
  450. placeholder="Please select"
  451. />
  452. <br />
  453. <br />
  454. <TreeSelect
  455. style={{ width: 300 }}
  456. insetLabel={<span>1234</span>}
  457. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  458. treeData={treeData2}
  459. placeholder="Please select"
  460. />
  461. </div>
  462. );
  463. PrefixSuffixInsetLabel.story = {
  464. name: 'prefix suffix insetLabel',
  465. };
  466. PrefixSuffixInsetLabel.parameters = {
  467. chromatic: { disableSnapshot: false },
  468. }
  469. export const ValidateStatus = () => (
  470. <div>
  471. <TreeSelect
  472. style={{ width: 300 }}
  473. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  474. treeData={treeData2}
  475. multiple
  476. validateStatus="warning"
  477. placeholder="Please select"
  478. onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
  479. onSelect={(e, bool) => console.log('select', e, bool)}
  480. onChange={e => console.log('change', e)}
  481. />
  482. <br />
  483. <br />
  484. <TreeSelect
  485. style={{ width: 300 }}
  486. validateStatus="error"
  487. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  488. treeData={treeData2}
  489. // multiple
  490. placeholder="Please select"
  491. />
  492. </div>
  493. );
  494. ValidateStatus.story = {
  495. name: 'validate status',
  496. };
  497. ValidateStatus.parameters = {
  498. chromatic: { disableSnapshot: false },
  499. }
  500. export const Multiple = () => (
  501. <div>
  502. <TreeSelect
  503. style={{ width: 300 }}
  504. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  505. treeData={treeData2}
  506. multiple
  507. placeholder="Please select"
  508. onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
  509. onSelect={(e, bool) => console.log('select', e, bool)}
  510. onChange={e => console.log('change', e)}
  511. />
  512. <br />
  513. <br />
  514. <TreeSelect
  515. style={{ width: 300 }}
  516. // value={this.state.value}
  517. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  518. treeData={treeData2}
  519. defaultOpen
  520. defaultExpandAll
  521. motion={false}
  522. multiple
  523. placeholder="Please select"
  524. />
  525. </div>
  526. );
  527. Multiple.story = {
  528. name: 'multiple',
  529. };
  530. export const MaxTagCount = () => (
  531. <div>
  532. <TreeSelect
  533. style={{ width: 300 }}
  534. // value={this.state.value}
  535. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  536. treeData={treeData2}
  537. multiple
  538. maxTagCount={2}
  539. placeholder="Please select"
  540. />
  541. {/* <br />
  542. <br />
  543. <TreeSelect
  544. style={{ width: 300 }}
  545. // value={this.state.value}
  546. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  547. treeData={treeData2}
  548. multiple
  549. placeholder="Please select"
  550. /> */}
  551. </div>
  552. );
  553. MaxTagCount.story = {
  554. name: 'maxTagCount',
  555. };
  556. export const MultipleSearchable = () => (
  557. <div>
  558. <TreeSelect
  559. style={{ width: 300 }}
  560. // value={this.state.value}
  561. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  562. treeData={treeData2}
  563. multiple
  564. filterTreeNode
  565. treeNodeFilterProp="value"
  566. placeholder="Please select"
  567. />
  568. </div>
  569. );
  570. MultipleSearchable.story = {
  571. name: 'multiple searchable',
  572. };
  573. export const DefaultValues = () => (
  574. <div>
  575. <TreeSelect
  576. style={{ width: 300 }}
  577. defaultValue={'shanghai'}
  578. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  579. treeData={treeData2}
  580. // multiple
  581. filterTreeNode
  582. treeNodeFilterProp="value"
  583. />
  584. <br />
  585. <br />
  586. <TreeSelect
  587. style={{ width: 300 }}
  588. defaultValue={'shanghai'}
  589. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  590. treeData={treeData2}
  591. filterTreeNode
  592. multiple
  593. treeNodeFilterProp="value"
  594. />
  595. <br />
  596. <br />
  597. <TreeSelect
  598. style={{ width: 300 }}
  599. defaultValue={['shanghai', 'daban', 'dongjing']}
  600. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  601. treeData={treeData2}
  602. filterTreeNode
  603. multiple
  604. treeNodeFilterProp="value"
  605. />
  606. <br />
  607. <br />
  608. <TreeSelect
  609. style={{ width: 300 }}
  610. defaultValue={['meiguo', 'dongjing']}
  611. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  612. treeData={treeData2}
  613. filterTreeNode
  614. multiple
  615. treeNodeFilterProp="value"
  616. />
  617. </div>
  618. );
  619. DefaultValues.story = {
  620. name: 'default values',
  621. };
  622. export const Disabled = () => (
  623. <div>
  624. <TreeSelect
  625. style={{ width: 300 }}
  626. defaultValue={'shanghai'}
  627. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  628. treeData={treeData2}
  629. multiple
  630. filterTreeNode
  631. disabled
  632. treeNodeFilterProp="value"
  633. placeholder="Please select"
  634. />
  635. <br />
  636. <br />
  637. <TreeSelect
  638. style={{ width: 300 }}
  639. defaultValue={'shanghai'}
  640. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  641. treeData={treeData2}
  642. filterTreeNode
  643. disabled
  644. treeNodeFilterProp="value"
  645. placeholder="Please select"
  646. />
  647. <br />
  648. <br />
  649. <TreeSelect
  650. style={{ width: 300 }}
  651. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  652. treeData={treeData2}
  653. multiple
  654. filterTreeNode
  655. disabled
  656. treeNodeFilterProp="value"
  657. placeholder="Please select"
  658. />
  659. </div>
  660. );
  661. Disabled.story = {
  662. name: 'disabled',
  663. };
  664. Disabled.parameters = {
  665. chromatic: { disableSnapshot: false },
  666. }
  667. export const OptionLabelProp = () => (
  668. <>
  669. <TreeSelect
  670. style={{ width: 300 }}
  671. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  672. treeData={treeData2}
  673. multiple
  674. filterTreeNode
  675. treeNodeFilterProp="value"
  676. treeNodeLabelProp="value"
  677. placeholder="Please select"
  678. />
  679. </>
  680. );
  681. OptionLabelProp.story = {
  682. name: 'optionLabelProp',
  683. };
  684. export const ValueInArray = () => (
  685. <>
  686. <TreeSelect
  687. style={{ width: 300 }}
  688. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  689. treeData={treeData2}
  690. multiple
  691. filterTreeNode
  692. valueInArray
  693. onChange={(...args) => console.log(args)}
  694. treeNodeFilterProp="value"
  695. treeNodeLabelProp="value"
  696. placeholder="Please select"
  697. />
  698. </>
  699. );
  700. ValueInArray.story = {
  701. name: 'valueInArray',
  702. };
  703. export const OnBlurOnFocus = () => (
  704. <>
  705. <div>single</div>
  706. <TreeSelect
  707. style={{ width: 300 }}
  708. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  709. treeData={treeData2}
  710. onBlur={(...args) => console.log('blur', args)}
  711. onFocus={(...args) => console.log('focus', args)}
  712. placeholder="Please select"
  713. />
  714. <div>multiple</div>
  715. <TreeSelect
  716. style={{ width: 300 }}
  717. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  718. treeData={treeData2}
  719. multiple
  720. onBlur={(...args) => console.log('blur', args)}
  721. onFocus={(...args) => console.log('focus', args)}
  722. placeholder="Please select"
  723. />
  724. <div>single, filterTreeNode, searchPosition=dropdown</div>
  725. <TreeSelect
  726. filterTreeNode
  727. style={{ width: 300 }}
  728. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  729. treeData={treeData2}
  730. onBlur={(...args) => console.log('blur', args)}
  731. onFocus={(...args) => console.log('focus', args)}
  732. placeholder="Please select"
  733. />
  734. <div>multiple, filterTreeNode, searchPosition=dropdown</div>
  735. <TreeSelect
  736. filterTreeNode
  737. style={{ width: 300 }}
  738. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  739. treeData={treeData2}
  740. multiple
  741. onBlur={(...args) => console.log('blur', args)}
  742. onFocus={(...args) => console.log('focus', args)}
  743. placeholder="Please select"
  744. />
  745. <div>single, filterTreeNode, searchPosition=trigger</div>
  746. <TreeSelect
  747. searchPosition="trigger"
  748. filterTreeNode
  749. style={{ width: 300 }}
  750. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  751. treeData={treeData2}
  752. onBlur={(...args) => console.log('blur', args)}
  753. onFocus={(...args) => console.log('focus', args)}
  754. placeholder="Please select"
  755. />
  756. <div>multiple, filterTreeNode, searchPosition=trigger</div>
  757. <TreeSelect
  758. searchPosition="trigger"
  759. filterTreeNode
  760. style={{ width: 300 }}
  761. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  762. treeData={treeData2}
  763. multiple
  764. onBlur={(...args) => console.log('blur', args)}
  765. onFocus={(...args) => console.log('focus', args)}
  766. placeholder="Please select"
  767. />
  768. </>
  769. );
  770. OnBlurOnFocus.story = {
  771. name: 'onBlur/onFocus',
  772. };
  773. export const LeafOnly = () => (
  774. <div>
  775. <TreeSelect
  776. style={{ width: 300 }}
  777. // value={this.state.value}
  778. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  779. treeData={treeData2}
  780. multiple
  781. leafOnly
  782. placeholder="Please select"
  783. onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
  784. onSelect={(e, bool) => console.log('select', e, bool)}
  785. onChange={e => console.log('change', e)}
  786. />
  787. </div>
  788. );
  789. LeafOnly.story = {
  790. name: 'leafOnly',
  791. };
  792. class Demo extends React.Component {
  793. constructor() {
  794. super();
  795. this.state = {
  796. value: 'shanghai',
  797. };
  798. }
  799. onChange(value) {
  800. this.setState({ value });
  801. }
  802. render() {
  803. return (
  804. <TreeSelect
  805. style={{ width: 300 }}
  806. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  807. treeData={treeData2}
  808. value={this.state.value}
  809. placeholder="Please select"
  810. onChange={e => this.onChange(e)}
  811. />
  812. );
  813. }
  814. }
  815. export const ControlledComponentSingle = () => <Demo />;
  816. ControlledComponentSingle.story = {
  817. name: 'controlled Component single',
  818. };
  819. class Demo2 extends React.Component {
  820. constructor() {
  821. super();
  822. this.state = {
  823. value: ['Shanghai'],
  824. };
  825. }
  826. onChange(value) {
  827. this.setState({ value });
  828. }
  829. render() {
  830. console.log(this.state.value);
  831. const treeData = [
  832. {
  833. label: '亚洲',
  834. value: 'Asia',
  835. key: '0',
  836. children: [
  837. {
  838. label: '中国',
  839. value: 'China',
  840. key: '0-0',
  841. children: [
  842. {
  843. label: '北京',
  844. value: 'Beijing',
  845. key: '0-0-0',
  846. },
  847. {
  848. label: '上海',
  849. value: 'Shanghai',
  850. key: '0-0-1',
  851. },
  852. ],
  853. },
  854. ],
  855. },
  856. {
  857. label: '北美洲',
  858. value: 'North America',
  859. key: '1',
  860. },
  861. ];
  862. return (
  863. <TreeSelect
  864. style={{ width: 300 }}
  865. multiple
  866. dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
  867. treeData={treeData}
  868. value={this.state.value}
  869. placeholder="Please select"
  870. onChange={e => this.onChange(e)}
  871. />
  872. );
  873. }
  874. }
  875. export const ControlledComponentMultiple = () => <Demo2 />;
  876. ControlledComponentMultiple.story = {
  877. name: 'controlled Component multiple',
  878. };
  879. class Demo3 extends React.Component {
  880. constructor() {
  881. super();
  882. this.state = {
  883. value: ['Shanghai'],
  884. };
  885. }
  886. // 获取最底层值
  887. getDeepChildrensByNode = node => {
  888. return flattenDeep(
  889. node.map(item => {
  890. if (item.children) {
  891. return this.getDeepChildrensByNode(item.children);
  892. }
  893. return item.value;
  894. })
  895. );
  896. };
  897. onChange(value, node) {
  898. console.log('onchange', value);
  899. value = this.getDeepChildrensByNode(node);
  900. console.log('modifiled', value);
  901. this.setState({ value });
  902. }
  903. render() {
  904. const treeData = [
  905. {
  906. label: '亚洲',
  907. value: 'Asia',
  908. key: '0',
  909. children: [
  910. {
  911. label: '中国',
  912. value: 'China',
  913. key: '0-0',
  914. children: [
  915. {
  916. label: '北京',
  917. value: 'Beijing',
  918. key: '0-0-0',
  919. },
  920. {
  921. label: '上海',
  922. value: 'Shanghai',
  923. key: '0-0-1',
  924. },
  925. ],
  926. },
  927. ],
  928. },
  929. {
  930. label: '北美洲',
  931. value: 'North America',
  932. key: '1',
  933. },
  934. ];
  935. return (
  936. <TreeSelect
  937. style={{ width: 300 }}
  938. multiple
  939. dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
  940. treeData={treeData}
  941. value={this.state.value}
  942. placeholder="Please select"
  943. onChange={(e, node) => this.onChange(e, node)}
  944. />
  945. );
  946. }
  947. }
  948. export const ControlledComponentMultipleValueModified = () => <Demo3 />;
  949. ControlledComponentMultipleValueModified.story = {
  950. name: 'controlled Component multiple value modified',
  951. };
  952. class ConvertDemo extends React.Component {
  953. constructor(props) {
  954. super(props);
  955. this.formApi = null;
  956. }
  957. handleChange = val => {
  958. let finalVal = val;
  959. let firstClassOption = ['Asia', 'North America'];
  960. // 在这里去做你的value替换逻辑
  961. console.log('originVal:' + val);
  962. if (val.length === 1) {
  963. // do nothing
  964. } else {
  965. if (val.every(item => firstClassOption.includes(item))) {
  966. finalVal = val[val.length - 1];
  967. }
  968. }
  969. console.log('finalVal:' + finalVal);
  970. return finalVal;
  971. };
  972. render() {
  973. const treeData = [
  974. {
  975. label: '亚洲',
  976. value: 'Asia',
  977. key: '0',
  978. children: [
  979. {
  980. label: '中国',
  981. value: 'China',
  982. key: '0-0',
  983. children: [
  984. {
  985. label: '北京',
  986. value: 'Beijing',
  987. key: '0-0-0',
  988. },
  989. {
  990. label: '上海',
  991. value: 'Shanghai',
  992. key: '0-0-1',
  993. },
  994. ],
  995. },
  996. ],
  997. },
  998. {
  999. label: '北美洲',
  1000. value: 'North America',
  1001. key: '1',
  1002. },
  1003. ];
  1004. return (
  1005. <Form getFormApi={this.getFormApi}>
  1006. <Form.TreeSelect
  1007. field="tree"
  1008. label="节点(TreeSelect)"
  1009. placeholder="请选择服务节点"
  1010. treeData={treeData}
  1011. convert={this.handleChange}
  1012. filterTreeNode
  1013. multiple
  1014. ></Form.TreeSelect>
  1015. </Form>
  1016. );
  1017. }
  1018. }
  1019. export const _ConvertDemo = () => <ConvertDemo />;
  1020. _ConvertDemo.story = {
  1021. name: 'convert demo',
  1022. };
  1023. export const TreeselectDefaultOpenInPopover = () => (
  1024. <Popover
  1025. content={
  1026. <TreeSelect
  1027. style={{ width: 200 }}
  1028. dropdownStyle={{ width: 200 }}
  1029. treeData={treeData1}
  1030. defaultOpen
  1031. // value={this.state.value}
  1032. // placeholder="Please select"
  1033. // onChange={(e, node) => this.onChange(e, node)}
  1034. />
  1035. }
  1036. >
  1037. <Button style={{ marginLeft: 150 }}>悬停此处</Button>
  1038. </Popover>
  1039. );
  1040. TreeselectDefaultOpenInPopover.story = {
  1041. name: 'treeselect defaultOpen in popover',
  1042. };
  1043. export const CustomTriggerDemo = () => <CustomTrigger />;
  1044. CustomTriggerDemo.story = { name: 'custom trigger' };
  1045. const AutoParentDemo = () => {
  1046. const [expandedKeys, setExpandedKeys] = useState(['beimeizhou']);
  1047. const [selectedKeys, setSelectedKeys] = useState(['beimeizhou']);
  1048. const [autoExpandParent, setAutoExpandParent] = useState(true);
  1049. const onExpand = expandedKeys => {
  1050. console.log('onExpand', expandedKeys);
  1051. // if not set autoExpandParent to false, if children expanded, parent can not collapse.
  1052. // or, you can remove all expanded children keys.
  1053. setExpandedKeys(expandedKeys);
  1054. setAutoExpandParent(false);
  1055. };
  1056. const onSelect = (selectedKeys, info) => {
  1057. console.log('onSelect:', info);
  1058. setSelectedKeys(selectedKeys);
  1059. };
  1060. return (
  1061. <div>
  1062. <Button
  1063. onClick={() => {
  1064. setSelectedKeys(['beijing']);
  1065. setExpandedKeys(['beijing']);
  1066. setAutoExpandParent(true);
  1067. }}
  1068. >
  1069. Update
  1070. </Button>
  1071. <TreeSelect
  1072. onExpand={onExpand}
  1073. expandedKeys={expandedKeys}
  1074. autoExpandParent={autoExpandParent}
  1075. onChange={onSelect}
  1076. value={selectedKeys}
  1077. treeData={treeData2}
  1078. // multiple
  1079. />
  1080. </div>
  1081. );
  1082. };
  1083. export const AutoExpandParent = () => (
  1084. <>
  1085. <AutoParentDemo />
  1086. </>
  1087. );
  1088. AutoExpandParent.story = {
  1089. name: 'autoExpandParent',
  1090. };
  1091. export const TreeWithoutValueProps = () => (
  1092. <TreeSelect
  1093. treeData={treeDataWithoutValue}
  1094. value="beijing"
  1095. defaultExpandAll
  1096. onChange={(...args) => console.log(args)}
  1097. />
  1098. );
  1099. TreeWithoutValueProps.story = {
  1100. name: 'tree without value props',
  1101. };
  1102. export const TreeSelectRenderSelectedItem = () => {
  1103. const treeData = [
  1104. {
  1105. label: '亚洲',
  1106. value: 'Asia',
  1107. key: '0',
  1108. children: [
  1109. {
  1110. label: '中国',
  1111. value: 'China',
  1112. key: '0-0',
  1113. children: [
  1114. {
  1115. label: '北京',
  1116. value: 'Beijing',
  1117. key: '0-0-0',
  1118. },
  1119. {
  1120. label: '上海',
  1121. value: 'Shanghai',
  1122. key: '0-0-1',
  1123. },
  1124. ],
  1125. },
  1126. ],
  1127. },
  1128. {
  1129. label: '北美洲',
  1130. value: 'North America',
  1131. key: '1',
  1132. },
  1133. {
  1134. label: '南美洲',
  1135. value: 'South America',
  1136. key: '2',
  1137. },
  1138. {
  1139. label: '南极洲',
  1140. value: 'Antarctica',
  1141. key: '3',
  1142. },
  1143. ];
  1144. return (
  1145. <>
  1146. <h4>单选</h4>
  1147. <TreeSelect
  1148. style={{ width: 300 }}
  1149. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1150. treeData={treeData}
  1151. placeholder="请选择"
  1152. renderSelectedItem={item => `${item.value}-${item.label}`}
  1153. />
  1154. <h4>多选</h4>
  1155. <TreeSelect
  1156. style={{ width: 300 }}
  1157. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1158. treeData={treeData}
  1159. multiple
  1160. placeholder="请选择"
  1161. renderSelectedItem={(item, { index, onClose }) => ({
  1162. content: `${item.value}-${item.label}`,
  1163. isRenderInTag: true,
  1164. })}
  1165. />
  1166. <h4>多选 + isRenderInTag=false</h4>
  1167. <TreeSelect
  1168. style={{ width: 300 }}
  1169. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1170. treeData={treeData}
  1171. multiple
  1172. maxTagCount={2}
  1173. placeholder="请选择"
  1174. renderSelectedItem={(item, { index, onClose }) => ({
  1175. content: (
  1176. <Tag key={index} color="white">
  1177. {item.value}
  1178. </Tag>
  1179. ),
  1180. isRenderInTag: false,
  1181. })}
  1182. />
  1183. </>
  1184. );
  1185. };
  1186. TreeSelectRenderSelectedItem.story = {
  1187. name: 'treeSelect renderSelectedItem',
  1188. };
  1189. const DisableStrictlyDemo = () => {
  1190. const [value, setValue] = useState(['Shanghai']);
  1191. const treeData = [
  1192. {
  1193. label: '亚洲',
  1194. value: 'Asia',
  1195. key: '0',
  1196. children: [
  1197. {
  1198. label: '中国',
  1199. value: 'China',
  1200. key: '0-0',
  1201. disabled: true,
  1202. children: [
  1203. {
  1204. label: '北京',
  1205. value: 'Beijing',
  1206. key: '0-0-0',
  1207. },
  1208. {
  1209. label: '上海',
  1210. value: 'Shanghai',
  1211. key: '0-0-1',
  1212. },
  1213. ],
  1214. },
  1215. {
  1216. label: '日本',
  1217. value: 'Japan',
  1218. key: '0-1',
  1219. },
  1220. ],
  1221. },
  1222. {
  1223. label: '北美洲',
  1224. value: 'North America',
  1225. key: '1',
  1226. },
  1227. ];
  1228. return (
  1229. <div>
  1230. <TreeSelect
  1231. style={{ width: 300 }}
  1232. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1233. treeData={treeData}
  1234. disableStrictly
  1235. multiple
  1236. searchPosition="trigger"
  1237. filterTreeNode
  1238. value={value}
  1239. onChange={value => setValue(value)}
  1240. />
  1241. </div>
  1242. );
  1243. };
  1244. export const DisabledStrictly = () => (
  1245. <>
  1246. <DisableStrictlyDemo />
  1247. </>
  1248. );
  1249. DisabledStrictly.story = {
  1250. name: 'disabledStrictly',
  1251. };
  1252. export const CheckRelationDemo = () => {
  1253. const treeData = [
  1254. {
  1255. label: 'Asia',
  1256. value: 'Asia',
  1257. key: '0',
  1258. children: [
  1259. {
  1260. label: 'China',
  1261. value: 'China',
  1262. key: '0-0',
  1263. children: [
  1264. {
  1265. label: 'Beijing',
  1266. value: 'Beijing',
  1267. key: '0-0-0',
  1268. },
  1269. {
  1270. label: 'Shanghai',
  1271. value: 'Shanghai',
  1272. key: '0-0-1',
  1273. },
  1274. {
  1275. label: 'Chengdu',
  1276. value: 'Chengdu',
  1277. key: '0-0-2',
  1278. },
  1279. ],
  1280. },
  1281. {
  1282. label: 'Japan',
  1283. value: 'Japan',
  1284. key: '0-1',
  1285. children: [
  1286. {
  1287. label: 'Osaka',
  1288. value: 'Osaka',
  1289. key: '0-1-0'
  1290. }
  1291. ]
  1292. },
  1293. ],
  1294. },
  1295. {
  1296. label: 'North America',
  1297. value: 'North America',
  1298. key: '1',
  1299. children: [
  1300. {
  1301. label: 'United States',
  1302. value: 'United States',
  1303. key: '1-0'
  1304. },
  1305. {
  1306. label: 'Canada',
  1307. value: 'Canada',
  1308. key: '1-1'
  1309. }
  1310. ]
  1311. }
  1312. ];
  1313. const [value, setValue] = useState('China');
  1314. const [value2, setValue2] = useState();
  1315. const [value3, setValue3] = useState();
  1316. const style = {
  1317. width: 300,
  1318. };
  1319. const dropdownStyle = {
  1320. maxHeight: 400,
  1321. overflow: 'auto'
  1322. };
  1323. const handleChange = value => {
  1324. console.log(value);
  1325. setValue(value);
  1326. };
  1327. const handleChange2 = value => {
  1328. console.log(value);
  1329. setValue2(value);
  1330. };
  1331. const handleChange3 = value => {
  1332. console.log(value);
  1333. setValue3(value);
  1334. };
  1335. return (
  1336. <>
  1337. <div>checkRelation='unRelated'</div>
  1338. <TreeSelect
  1339. dropdownStyle={dropdownStyle}
  1340. treeData={treeData}
  1341. multiple
  1342. checkRelation='unRelated'
  1343. defaultExpandAll
  1344. style={style}
  1345. />
  1346. <br /><br />
  1347. <div>checkRelation='unRelated' + maxTagCount=2</div>
  1348. <TreeSelect
  1349. dropdownStyle={dropdownStyle}
  1350. treeData={treeData}
  1351. multiple
  1352. maxTagCount={2}
  1353. checkRelation='unRelated'
  1354. defaultExpandAll
  1355. style={style}
  1356. />
  1357. <br /><br />
  1358. <div>checkRelation='unRelated' + maxTagCount=2 + 开启搜索</div>
  1359. <TreeSelect
  1360. dropdownStyle={dropdownStyle}
  1361. treeData={treeData}
  1362. multiple
  1363. maxTagCount={2}
  1364. filterTreeNode
  1365. checkRelation='unRelated'
  1366. defaultExpandAll
  1367. style={style}
  1368. />
  1369. <br /><br />
  1370. <div>checkRelation='unRelated' + maxTagCount=2 + 开启搜索 + searchBox in trigger</div>
  1371. <TreeSelect
  1372. dropdownStyle={dropdownStyle}
  1373. treeData={treeData}
  1374. multiple
  1375. maxTagCount={2}
  1376. filterTreeNode
  1377. checkRelation='unRelated'
  1378. searchPosition='trigger'
  1379. defaultExpandAll
  1380. style={style}
  1381. />
  1382. <br /><br />
  1383. <div>checkRelation='unRelated' + 中国节点为 disabled</div>
  1384. <TreeSelect
  1385. dropdownStyle={dropdownStyle}
  1386. treeData={treeDataWithoutValue}
  1387. multiple
  1388. checkRelation='unRelated'
  1389. defaultExpandAll
  1390. style={style}
  1391. />
  1392. <br /><br />
  1393. <div>checkRelation='unRelated' + 中国节点为 disabled + 严格禁用</div>
  1394. <TreeSelect
  1395. dropdownStyle={dropdownStyle}
  1396. treeData={treeDataWithoutValue}
  1397. multiple
  1398. checkRelation='unRelated'
  1399. defaultExpandAll
  1400. disableStrictly
  1401. style={style}
  1402. />
  1403. <br /><br />
  1404. <div>checkRelation='unRelated' + defaultValue 为 China</div>
  1405. <TreeSelect
  1406. dropdownStyle={dropdownStyle}
  1407. treeData={treeData}
  1408. multiple
  1409. checkRelation='unRelated'
  1410. defaultExpandAll
  1411. style={style}
  1412. defaultValue='China'
  1413. />
  1414. <br /><br />
  1415. <div>checkRelation='unRelated' + defaultValue 为 China + 开启搜索</div>
  1416. <TreeSelect
  1417. dropdownStyle={dropdownStyle}
  1418. treeData={treeData}
  1419. multiple
  1420. filterTreeNode
  1421. checkRelation='unRelated'
  1422. defaultExpandAll
  1423. style={style}
  1424. defaultValue='China'
  1425. />
  1426. <br /><br />
  1427. <div>多选 + checkRelation='unRelated' + defaultValue 为 China + 开启搜索 + searchBox in trigger + showClear</div>
  1428. <TreeSelect
  1429. dropdownStyle={dropdownStyle}
  1430. treeData={treeData}
  1431. multiple
  1432. filterTreeNode
  1433. showClear
  1434. checkRelation='unRelated'
  1435. defaultExpandAll
  1436. style={style}
  1437. searchPosition='trigger'
  1438. defaultValue={['China', 'Japan']}
  1439. />
  1440. <br /><br />
  1441. <div>单选 + checkRelation='unRelated' + defaultValue 为 China + 开启搜索 + searchBox in trigger + showClear</div>
  1442. <TreeSelect
  1443. dropdownStyle={dropdownStyle}
  1444. treeData={treeData}
  1445. filterTreeNode
  1446. showClear
  1447. checkRelation='unRelated'
  1448. defaultExpandAll
  1449. style={style}
  1450. searchPosition='trigger'
  1451. defaultValue='China'
  1452. />
  1453. <br /><br />
  1454. <div>checkRelation='unRelated' + 受控 + value 初始为 China</div>
  1455. <TreeSelect
  1456. dropdownStyle={dropdownStyle}
  1457. treeData={treeData}
  1458. multiple
  1459. checkRelation='unRelated'
  1460. defaultExpandAll
  1461. style={style}
  1462. value={value}
  1463. onChange={handleChange}
  1464. />
  1465. <br /><br />
  1466. <div>checkRelation='unRelated' + 受控 + onChangeWithObject</div>
  1467. <TreeSelect
  1468. dropdownStyle={dropdownStyle}
  1469. treeData={treeData}
  1470. multiple
  1471. checkRelation='unRelated'
  1472. defaultExpandAll
  1473. style={style}
  1474. value={value2}
  1475. onChangeWithObject
  1476. onChange={handleChange2}
  1477. />
  1478. <br /><br />
  1479. <div>checkRelation='unRelated' + 受控 + leafOnly,此时 leafOnly 失效</div>
  1480. <TreeSelect
  1481. dropdownStyle={dropdownStyle}
  1482. leafOnly
  1483. treeData={treeData}
  1484. multiple
  1485. checkRelation='unRelated'
  1486. defaultExpandAll
  1487. style={style}
  1488. value={value3}
  1489. onChange={handleChange3}
  1490. />
  1491. <br /><br />
  1492. <div>checkRelation='unRelated' + onSelect </div>
  1493. <TreeSelect
  1494. dropdownStyle={dropdownStyle}
  1495. treeData={treeData}
  1496. multiple
  1497. checkRelation='unRelated'
  1498. defaultExpandAll
  1499. style={style}
  1500. onSelect={(value,status,node)=>console.log('select', value, status, node)}
  1501. />
  1502. </>
  1503. );
  1504. };
  1505. export const SearchableAndExpandedKeys = () => {
  1506. const [expandedKeys1, setExpandedKeys1] = useState([]);
  1507. const [expandedKeys2, setExpandedKeys2] = useState([]);
  1508. const [expandedKeys3, setExpandedKeys3] = useState([]);
  1509. return (
  1510. <>
  1511. <Title heading={6}>expandedKeys 受控</Title>
  1512. <TreeSelect
  1513. style={{ width: 300, marginBottom: 30 }}
  1514. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1515. treeData={treeData2}
  1516. expandedKeys={expandedKeys1}
  1517. defaultValue='beijing'
  1518. onExpand={v => {
  1519. console.log('onExpand value: ', v);
  1520. setExpandedKeys1(v);
  1521. }}
  1522. />
  1523. <Title heading={6}>expandedKeys 受控 + 开启搜索</Title>
  1524. <TreeSelect
  1525. style={{ width: 300, marginBottom: 30 }}
  1526. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1527. treeData={treeData2}
  1528. filterTreeNode
  1529. defaultValue='beijing'
  1530. expandedKeys={expandedKeys2}
  1531. onExpand={v => {
  1532. console.log('onExpand value: ', v);
  1533. setExpandedKeys2(v);
  1534. }}
  1535. />
  1536. <Title heading={6}>expandedKeys 受控 + 开启搜索 + 搜索时更新 expandedKeys</Title>
  1537. <TreeSelect
  1538. style={{ width: 300, marginBottom: 30 }}
  1539. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1540. treeData={treeData2}
  1541. filterTreeNode
  1542. expandedKeys={expandedKeys3}
  1543. defaultValue='beijing'
  1544. onExpand={v => {
  1545. console.log('onExpand value: ', v);
  1546. setExpandedKeys3(v)
  1547. }}
  1548. onSearch={(input, filterExpandedKeys) => {
  1549. console.log('onExpand filterExpandedKeys: ', filterExpandedKeys);
  1550. setExpandedKeys3(filterExpandedKeys);
  1551. }}
  1552. />
  1553. </>
  1554. )
  1555. }
  1556. export const loadData = () => {
  1557. const initialData = [
  1558. {
  1559. label: 'Expand to load',
  1560. value: '0',
  1561. key: '0',
  1562. },
  1563. {
  1564. label: 'Expand to load',
  1565. value: '1',
  1566. key: '1',
  1567. },
  1568. {
  1569. label: 'Leaf Node',
  1570. value: '2',
  1571. key: '2',
  1572. isLeaf: true,
  1573. },
  1574. ];
  1575. const [treeData, setTreeData] = useState(initialData);
  1576. const [loadedKeys, setLoadedKeys] = useState(['2']);
  1577. function updateTreeData(list, key, children) {
  1578. return list.map(node => {
  1579. if (node.key === key) {
  1580. return { ...node, children };
  1581. }
  1582. if (node.children) {
  1583. return { ...node, children: updateTreeData(node.children, key, children) };
  1584. }
  1585. return node;
  1586. });
  1587. }
  1588. function onLoadData({ key, children }) {
  1589. return new Promise(resolve => {
  1590. if (children) {
  1591. resolve();
  1592. return;
  1593. }
  1594. setTimeout(() => {
  1595. setTreeData(origin =>
  1596. updateTreeData(origin, key, [
  1597. {
  1598. label: 'Child Node',
  1599. key: `${key}-0`,
  1600. },
  1601. {
  1602. label: 'Child Node',
  1603. key: `${key}-1`,
  1604. },
  1605. ]),
  1606. );
  1607. resolve();
  1608. }, 1000);
  1609. });
  1610. }
  1611. return (
  1612. <TreeSelect
  1613. loadData={onLoadData}
  1614. filterTreeNode
  1615. treeData={treeData}
  1616. style={{ width: 300 }}
  1617. placeholder="请选择"
  1618. />
  1619. );
  1620. }
  1621. export const loadDataAndLoadedkeys = () => {
  1622. const initialData = [
  1623. {
  1624. label: 'Expand to load',
  1625. value: '0',
  1626. key: '0',
  1627. },
  1628. {
  1629. label: 'Expand to load',
  1630. value: '1',
  1631. key: '1',
  1632. },
  1633. {
  1634. label: 'Leaf Node',
  1635. value: '2',
  1636. key: '2',
  1637. isLeaf: true,
  1638. },
  1639. ];
  1640. const [treeData, setTreeData] = useState(initialData);
  1641. const [loadedKeys, setLoadedKeys] = useState(['2']);
  1642. function updateTreeData(list, key, children) {
  1643. return list.map(node => {
  1644. if (node.key === key) {
  1645. return { ...node, children };
  1646. }
  1647. if (node.children) {
  1648. return { ...node, children: updateTreeData(node.children, key, children) };
  1649. }
  1650. return node;
  1651. });
  1652. }
  1653. function updateLoadedKeys(key) {
  1654. if(!loadedKeys.includes(key)){
  1655. setLoadedKeys([...loadedKeys, key]);
  1656. console.log('[...loadedKeys, key]', [...loadedKeys, key]);
  1657. }
  1658. }
  1659. function onLoadData({ key, children }) {
  1660. return new Promise(resolve => {
  1661. if (children) {
  1662. resolve();
  1663. return;
  1664. }
  1665. setTimeout(() => {
  1666. setTreeData(origin =>
  1667. updateTreeData(origin, key, [
  1668. {
  1669. label: 'Child Node',
  1670. key: `${key}-0`,
  1671. },
  1672. {
  1673. label: 'Child Node',
  1674. key: `${key}-1`,
  1675. },
  1676. ]),
  1677. );
  1678. // updateLoadedKeys(key);
  1679. resolve();
  1680. }, 1000);
  1681. });
  1682. }
  1683. return (
  1684. <TreeSelect
  1685. loadData={onLoadData}
  1686. filterTreeNode
  1687. // loadedKeys={loadedKeys}
  1688. treeData={treeData}
  1689. style={{ width: 300 }}
  1690. placeholder="请选择"
  1691. />
  1692. );
  1693. }
  1694. export const size = () => {
  1695. const props = {
  1696. style: { width: 300 },
  1697. dropdownStyle: { maxHeight: 400, overflow: 'auto' },
  1698. defaultValue: ['0-0-1', '0-0-2', '0-0-3', '0-0-4', '0-0-5', '0-0-6', '0-0-7'],
  1699. treeData: treeData3,
  1700. multiple: true,
  1701. filterTreeNode: true,
  1702. searchPosition: "trigger"
  1703. };
  1704. return (<>
  1705. <TreeSelect {...props} size={'small'} placeholder={'small'} />
  1706. <br/><br/>
  1707. <TreeSelect {...props} size={'default'} placeholder={'default'} />
  1708. <br/><br/>
  1709. <TreeSelect {...props} size={'large'} placeholder={'large'} />
  1710. </>);
  1711. }
  1712. export const valueNotInTreeDataIssue = () => {
  1713. const treeData = [
  1714. {
  1715. key: "test",
  1716. label: "测试标签",
  1717. children: [
  1718. {
  1719. key: "test_2",
  1720. label: "测试二级标签"
  1721. },
  1722. {
  1723. key: "jzr_test",
  1724. label: "之睿测试"
  1725. }
  1726. ]
  1727. },
  1728. {
  1729. key: "create",
  1730. label: "创作构思",
  1731. children: [
  1732. {
  1733. key: "material",
  1734. label: "素材积累"
  1735. },
  1736. {
  1737. key: "lens_script",
  1738. label: "分镜脚本"
  1739. }
  1740. ]
  1741. }
  1742. ];
  1743. const treeDataWithValue = [
  1744. {
  1745. value: "test",
  1746. key: "0",
  1747. label: "测试标签",
  1748. children: [
  1749. {
  1750. value: "test_2",
  1751. key: "0-1",
  1752. label: "测试二级标签"
  1753. },
  1754. {
  1755. value: "jzr_test",
  1756. key: "0-2",
  1757. label: "之睿测试"
  1758. }
  1759. ]
  1760. },
  1761. {
  1762. value: "create",
  1763. key: "1",
  1764. label: "创作构思",
  1765. children: [
  1766. {
  1767. value: "material",
  1768. key: "1-1",
  1769. label: "素材积累"
  1770. },
  1771. {
  1772. value: "lens_script",
  1773. key: "1-2",
  1774. label: "分镜脚本"
  1775. }
  1776. ]
  1777. }
  1778. ];
  1779. const commonProps = useMemo(() => {
  1780. return {
  1781. multiple: true,
  1782. style: { width: 300 },
  1783. dropdownStyle: { maxHeight: 400, overflow: 'auto' },
  1784. onChange: (value) => {
  1785. console.log('onChange', value);
  1786. },
  1787. onSelect: (value) => {
  1788. console.log('onSelect', value);
  1789. },
  1790. };
  1791. }, []);
  1792. return (
  1793. <>
  1794. <p style={{ backgroundColor: 'yellowgreen', width: 'fit-content' }}>多选,无 value</p>
  1795. <p>checkRelation='related'</p>
  1796. <TreeSelect
  1797. defaultExpandAll
  1798. defaultValue={["test_2", 0]}
  1799. treeData={treeData}
  1800. {...commonProps}
  1801. />
  1802. <p>checkRelation='unRelated'</p>
  1803. <TreeSelect
  1804. defaultExpandAll
  1805. defaultValue={["test_2", "fish"]}
  1806. checkRelation='unRelated'
  1807. treeData={treeData}
  1808. {...commonProps}
  1809. />
  1810. <p>onChangeWithObject, checkRelation='related'</p>
  1811. <TreeSelect
  1812. defaultExpandAll
  1813. onChangeWithObject
  1814. defaultValue={[
  1815. {
  1816. key: "test_2",
  1817. label: "测试二级标签"
  1818. },
  1819. {
  1820. key: "fish",
  1821. label: "鱼"
  1822. }
  1823. ]}
  1824. treeData={treeData}
  1825. {...commonProps}
  1826. />
  1827. <p>onChangeWithObject, checkRelation='unRelated'</p>
  1828. <TreeSelect
  1829. defaultExpandAll
  1830. onChangeWithObject
  1831. defaultValue={[
  1832. {
  1833. key: "test_2",
  1834. label: "测试二级标签"
  1835. },
  1836. {
  1837. key: "fish",
  1838. label: "鱼"
  1839. }
  1840. ]}
  1841. treeData={treeData}
  1842. {...commonProps}
  1843. />
  1844. <p style={{ backgroundColor: 'yellowgreen', width: 'fit-content' }}>多选,有 value</p>
  1845. <p>checkRelation='related'</p>
  1846. <TreeSelect
  1847. defaultExpandAll
  1848. defaultValue={["test", "fish"]}
  1849. treeData={treeDataWithValue}
  1850. {...commonProps}
  1851. />
  1852. <p>checkRelation='unRelated'</p>
  1853. <TreeSelect
  1854. defaultExpandAll
  1855. defaultValue={["test", "fish"]}
  1856. checkRelation='unRelated'
  1857. treeData={treeDataWithValue}
  1858. {...commonProps}
  1859. />
  1860. <p>onChangeWithObject, checkRelation='unRelated'</p>
  1861. <TreeSelect
  1862. defaultExpandAll
  1863. onChangeWithObject
  1864. defaultValue={[
  1865. {
  1866. value: "test_2",
  1867. key: "0-1",
  1868. label: "测试二级标签"
  1869. },
  1870. {
  1871. key: "fish",
  1872. value: "Fish",
  1873. label: "鱼"
  1874. }
  1875. ]}
  1876. treeData={treeDataWithValue}
  1877. {...commonProps}
  1878. />
  1879. <p>onChangeWithObject, checkRelation='unRelated'</p>
  1880. <TreeSelect
  1881. defaultExpandAll
  1882. onChangeWithObject
  1883. defaultValue={[
  1884. {
  1885. value: "test_2",
  1886. key: "0-1",
  1887. label: "测试二级标签"
  1888. },
  1889. {
  1890. key: "fish",
  1891. value: "Fish",
  1892. label: "鱼"
  1893. }
  1894. ]}
  1895. treeData={treeDataWithValue}
  1896. {...commonProps}
  1897. />
  1898. <p style={{ backgroundColor: 'yellowgreen', width: 'fit-content' }}>单选,无 value</p>
  1899. <TreeSelect
  1900. defaultExpandAll
  1901. defaultValue={"fish"}
  1902. treeData={treeData}
  1903. {...commonProps}
  1904. multiple={false}
  1905. />
  1906. <p>onChangeWithObject</p>
  1907. <TreeSelect
  1908. defaultExpandAll
  1909. defaultValue={{
  1910. key: "fish",
  1911. value: "Fish",
  1912. label: "鱼"
  1913. }}
  1914. treeData={treeData}
  1915. {...commonProps}
  1916. multiple={false}
  1917. onChangeWithObject
  1918. />
  1919. <p style={{ backgroundColor: 'yellowgreen', width: 'fit-content' }}>单选,有 value</p>
  1920. <TreeSelect
  1921. defaultExpandAll
  1922. defaultValue={"fish"}
  1923. treeData={treeDataWithValue}
  1924. {...commonProps}
  1925. multiple={false}
  1926. />
  1927. <p>onChangeWithObject</p>
  1928. <TreeSelect
  1929. defaultExpandAll
  1930. defaultValue={{
  1931. key: "fish",
  1932. value: "Fish",
  1933. label: "鱼"
  1934. }}
  1935. treeData={treeDataWithValue}
  1936. {...commonProps}
  1937. multiple={false}
  1938. onChangeWithObject
  1939. />
  1940. </>
  1941. );
  1942. };
  1943. class ValueTypeIsNumber extends React.Component {
  1944. constructor() {
  1945. super();
  1946. this.state = {
  1947. value: 1
  1948. };
  1949. }
  1950. onChange(value) {
  1951. console.log('onChange', value);
  1952. this.setState({ value });
  1953. }
  1954. render() {
  1955. const treeData = [
  1956. {
  1957. label: '北美洲',
  1958. value: 'North America',
  1959. key: '1',
  1960. },
  1961. {
  1962. label: '亚洲',
  1963. value: 'Asia',
  1964. key: '0',
  1965. children: [
  1966. {
  1967. label: '中国',
  1968. value: 'China',
  1969. key: '0-0',
  1970. children: [
  1971. {
  1972. label: '北京',
  1973. value: 'Beijing',
  1974. key: '0-0-0',
  1975. },
  1976. {
  1977. label: '上海',
  1978. value: 'Shanghai',
  1979. key: '0-0-1',
  1980. },
  1981. ],
  1982. },
  1983. ],
  1984. },
  1985. ];
  1986. return (
  1987. <TreeSelect
  1988. style={{ width: 300 }}
  1989. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  1990. treeData={treeData}
  1991. value={this.state.value}
  1992. placeholder="请选择"
  1993. multiple
  1994. onChange={e => this.onChange(e)}
  1995. />
  1996. );
  1997. }
  1998. }
  1999. export const valueIsNumber = () => <ValueTypeIsNumber />
  2000. export const searchPositionInTriggerAndVirtualize = () => {
  2001. return (
  2002. <>
  2003. <TreeSelect
  2004. searchPosition="trigger"
  2005. style={{ width: 300 }}
  2006. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2007. treeData={treeData2}
  2008. filterTreeNode
  2009. placeholder="单选"
  2010. virtualize={{
  2011. itemSize: 28,
  2012. // dropDown height 300 minus search box height minus padding 8 * 2
  2013. // or if you set dropdown height, it will fill 100% of rest space
  2014. height: 236
  2015. }}
  2016. />
  2017. </>
  2018. );
  2019. };
  2020. export const clickTriggerToHide = () => (
  2021. <>
  2022. <p>clickTriggerToHide 未设置,默认为 true</p>
  2023. <TreeSelect
  2024. style={{ width: 300 }}
  2025. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2026. treeData={treeData2}
  2027. placeholder="单选"
  2028. />
  2029. <p>clickTriggerToHide 设置为 false</p>
  2030. <TreeSelect
  2031. style={{ width: 300 }}
  2032. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2033. treeData={treeData2}
  2034. placeholder="单选"
  2035. clickTriggerToHide={false}
  2036. />
  2037. </>
  2038. );
  2039. export const triggerRenderAddMethod = () => {
  2040. const treeData = useMemo(() => [
  2041. {
  2042. label: '亚洲',
  2043. value: '亚洲',
  2044. key: '0',
  2045. children: [
  2046. {
  2047. label: '中国',
  2048. value: '中国',
  2049. key: '0-0',
  2050. children: [
  2051. {
  2052. label: '北京',
  2053. value: '北京',
  2054. key: '0-0-0',
  2055. },
  2056. {
  2057. label: '上海',
  2058. value: '上海',
  2059. key: '0-0-1',
  2060. },
  2061. ],
  2062. },
  2063. ],
  2064. },
  2065. {
  2066. label: '北美洲',
  2067. value: '北美洲',
  2068. key: '1',
  2069. }
  2070. ], []);
  2071. const onValueChange = useCallback((value) => {
  2072. console.log('onChange', value);
  2073. });
  2074. const closeIcon = useCallback((value, onClear) => {
  2075. return value && value.length ? <IconClose onClick={onClear} /> : <IconChevronDown />;
  2076. }, []);
  2077. const renderTagItem = useCallback((item, onRemove) => (
  2078. <Tag closable key={item.key} onClose={() => { onRemove(item.key); }}>{item.label}</Tag>
  2079. ), []);
  2080. const renderTrigger1 = useCallback((props) => {
  2081. const { value, placeholder, onClear } = props;
  2082. return (
  2083. <Button theme={'light'} icon={closeIcon(value, onClear)} iconPosition={'right'}>
  2084. {value && value.length ? value.map(item => item.label).join(',') : placeholder}
  2085. </Button>
  2086. );
  2087. }, []);
  2088. const renderTrigger2 = useCallback((props) => {
  2089. const { value, onSearch, onRemove, onClear } = props;
  2090. return (
  2091. <div style={{ border: '1px solid grey', width: 'fit-content', padding: 5, borderRadius: 5 }}>
  2092. {value && value.length > 0 &&
  2093. <div style={{ width: 'fit-content', minWidth: 10, padding: 5 }}>
  2094. {value.map(item => renderTagItem(item, onRemove))}
  2095. </div>
  2096. }
  2097. <Input style={{ width: 200 }} onChange={onSearch} />
  2098. {closeIcon(value, onClear)}
  2099. </div>
  2100. );
  2101. }, []);
  2102. const renderTrigger3 = useCallback((props) => {
  2103. const { value, onSearch, onRemove, inputValue } = props;
  2104. const tagInputValue = value.map(item => item.key);
  2105. const renderTagInMultiple = (key) => {
  2106. const label = value.find(item => item.key === key).label;
  2107. const onCloseTag = (value, e, tagKey) => {
  2108. onRemove(tagKey);
  2109. }
  2110. return <Tag style={{ marginLeft: 2 }} tagKey={key} key={key} onClose={onCloseTag} closable>{label}</Tag>
  2111. }
  2112. return (
  2113. <TagInput
  2114. inputValue={inputValue}
  2115. value={tagInputValue}
  2116. onInputChange={onSearch}
  2117. renderTagItem={renderTagInMultiple}
  2118. />
  2119. )
  2120. }, []);
  2121. return (
  2122. <>
  2123. <TreeSelect
  2124. triggerRender={renderTrigger1}
  2125. multiple
  2126. treeData={treeData}
  2127. placeholder='Custom Trigger'
  2128. onChange={onValueChange}
  2129. style={{ width: 300 }}
  2130. />
  2131. <br />
  2132. <TreeSelect
  2133. triggerRender={renderTrigger2}
  2134. filterTreeNode
  2135. searchPosition="trigger"
  2136. multiple
  2137. treeData={treeData}
  2138. placeholder='Custom Trigger'
  2139. onChange={onValueChange}
  2140. style={{ width: 300 }}
  2141. />
  2142. <br />
  2143. <TreeSelect
  2144. triggerRender={renderTrigger3}
  2145. filterTreeNode
  2146. searchPosition="trigger"
  2147. multiple
  2148. treeData={treeData}
  2149. placeholder='Custom Trigger'
  2150. onChange={onValueChange}
  2151. style={{ width: 300 }}
  2152. />
  2153. </>
  2154. );
  2155. }
  2156. export const AutoSearchFocusPlusPreventScroll = () => {
  2157. return (
  2158. <div>
  2159. <div style={{height: '100vh' }}>我是一个高度和视窗高度一致的div。
  2160. <br />由于 TreeSelect 设置了 searchAutoFocus 以及 preventScroll,
  2161. <br /> 符合预期的情况是在没有滚动屏幕情况下,你不会看到 TreeSelect 的 trigger
  2162. </div>
  2163. <TreeSelect
  2164. searchAutoFocus
  2165. searchPosition="trigger"
  2166. preventScroll={true}
  2167. style={{ width: 300 }}
  2168. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2169. treeData={treeData2}
  2170. filterTreeNode
  2171. placeholder="单选"
  2172. />
  2173. </div>
  2174. );
  2175. };
  2176. export const LongLabel = () => {
  2177. const treeData = [
  2178. {
  2179. label: '这是一个超长的中文测试用标题这是一个超长的中文测试用标题这是一个超长的中文测试用标题这是一个超长的中文测试用标题',
  2180. value: 'v1',
  2181. key: '0',
  2182. },
  2183. {
  2184. label: 'ThisISAVeryLongTestSentenceThisISAVeryLongTestSentenceThisISAVeryLongTestSentence',
  2185. value: 'v2',
  2186. key: '1',
  2187. }
  2188. ];
  2189. return (
  2190. <>
  2191. <p>单选</p>
  2192. <TreeSelect
  2193. defaultValue='v1'
  2194. style={{ width: 300 }}
  2195. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2196. treeData={treeData}
  2197. placeholder="请选择"
  2198. />
  2199. <p>单选,可搜索, searchPosition='trigger'</p>
  2200. <TreeSelect
  2201. filterTreeNode
  2202. searchPosition='trigger'
  2203. defaultValue='v1'
  2204. style={{ width: 300 }}
  2205. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2206. treeData={treeData}
  2207. placeholder="请选择"
  2208. />
  2209. <p>单选,可搜索, searchPosition='dropDown'</p>
  2210. <TreeSelect
  2211. filterTreeNode
  2212. defaultValue='v1'
  2213. style={{ width: 300 }}
  2214. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2215. treeData={treeData}
  2216. placeholder="请选择"
  2217. />
  2218. <p>单选</p>
  2219. <TreeSelect
  2220. defaultValue='v2'
  2221. style={{ width: 300 }}
  2222. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2223. treeData={treeData}
  2224. placeholder="请选择"
  2225. />
  2226. <p>单选,可搜索, searchPosition='trigger'</p>
  2227. <TreeSelect
  2228. filterTreeNode
  2229. searchPosition='trigger'
  2230. defaultValue='v2'
  2231. style={{ width: 300 }}
  2232. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2233. treeData={treeData}
  2234. placeholder="请选择"
  2235. />
  2236. <p>单选,可搜索, searchPosition='dropDown'</p>
  2237. <TreeSelect
  2238. filterTreeNode
  2239. defaultValue='v2'
  2240. style={{ width: 300 }}
  2241. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  2242. treeData={treeData}
  2243. placeholder="请选择"
  2244. />
  2245. </>
  2246. );
  2247. }