@fibrae/semi-ui-svelte 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/README.md +8 -4
  2. package/README.zh-CN.md +8 -4
  3. package/dist/components/anchor/interface.d.ts +14 -0
  4. package/dist/components/audio-player/interface.d.ts +5 -0
  5. package/dist/components/auto-complete/interface.d.ts +29 -0
  6. package/dist/components/avatar/interface.d.ts +24 -0
  7. package/dist/components/backtop/interface.d.ts +2 -0
  8. package/dist/components/badge/interface.d.ts +7 -0
  9. package/dist/components/banner/interface.d.ts +7 -0
  10. package/dist/components/breadcrumb/interface.d.ts +10 -0
  11. package/dist/components/button/interface.d.ts +18 -0
  12. package/dist/components/calendar/interface.d.ts +16 -0
  13. package/dist/components/card/interface.d.ts +18 -0
  14. package/dist/components/carousel/interface.d.ts +16 -0
  15. package/dist/components/cascader/interface.d.ts +57 -0
  16. package/dist/components/checkbox/interface.d.ts +19 -0
  17. package/dist/components/code-highlight/interface.d.ts +3 -0
  18. package/dist/components/collapse/interface.d.ts +16 -0
  19. package/dist/components/collapsible/interface.d.ts +10 -0
  20. package/dist/components/color-picker/interface.d.ts +10 -0
  21. package/dist/components/config-provider/interface.d.ts +7 -0
  22. package/dist/components/cropper/interface.d.ts +11 -0
  23. package/dist/components/date-picker/interface.d.ts +47 -0
  24. package/dist/components/descriptions/interface.d.ts +6 -0
  25. package/dist/components/divider/interface.d.ts +4 -0
  26. package/dist/components/dropdown/interface.d.ts +8 -0
  27. package/dist/components/empty/interface.d.ts +7 -0
  28. package/dist/components/feedback/interface.d.ts +16 -0
  29. package/dist/components/float-button/interface.d.ts +14 -0
  30. package/dist/components/form/interface.d.ts +47 -0
  31. package/dist/components/grid/interface.d.ts +13 -0
  32. package/dist/components/highlight/interface.d.ts +7 -0
  33. package/dist/components/hot-keys/interface.d.ts +3 -0
  34. package/dist/components/image/interface.d.ts +59 -0
  35. package/dist/components/input/interface.d.ts +67 -0
  36. package/dist/components/input-number/interface.d.ts +24 -0
  37. package/dist/components/json-viewer/interface.d.ts +7 -0
  38. package/dist/components/layout/interface.d.ts +3 -0
  39. package/dist/components/list/interface.d.ts +18 -0
  40. package/dist/components/locale/interface.d.ts +4 -0
  41. package/dist/components/lottie/interface.d.ts +2 -0
  42. package/dist/components/markdown-render/interface.d.ts +5 -0
  43. package/dist/components/modal/interface.d.ts +29 -0
  44. package/dist/components/navigation/interface.d.ts +47 -0
  45. package/dist/components/overflow-list/interface.d.ts +11 -0
  46. package/dist/components/pagination/interface.d.ts +12 -0
  47. package/dist/components/pincode/interface.d.ts +8 -0
  48. package/dist/components/popconfirm/interface.d.ts +12 -0
  49. package/dist/components/popover/interface.d.ts +30 -0
  50. package/dist/components/progress/interface.d.ts +13 -0
  51. package/dist/components/radio/interface.d.ts +22 -0
  52. package/dist/components/rating/interface.d.ts +12 -0
  53. package/dist/components/resizable/interface.d.ts +30 -0
  54. package/dist/components/scroll-list/interface.d.ts +6 -0
  55. package/dist/components/select/interface.d.ts +63 -0
  56. package/dist/components/side-sheet/interface.d.ts +19 -0
  57. package/dist/components/skeleton/interface.d.ts +7 -0
  58. package/dist/components/slider/interface.d.ts +23 -0
  59. package/dist/components/space/interface.d.ts +4 -0
  60. package/dist/components/spin/interface.d.ts +7 -0
  61. package/dist/components/steps/interface.d.ts +9 -0
  62. package/dist/components/switch/interface.d.ts +7 -0
  63. package/dist/components/table/interface.d.ts +48 -0
  64. package/dist/components/tabs/interface.d.ts +29 -0
  65. package/dist/components/tag/interface.d.ts +22 -0
  66. package/dist/components/tag-input/interface.d.ts +29 -0
  67. package/dist/components/time-picker/interface.d.ts +31 -0
  68. package/dist/components/timeline/interface.d.ts +5 -0
  69. package/dist/components/tooltip/interface.d.ts +20 -0
  70. package/dist/components/transfer/interface.d.ts +18 -0
  71. package/dist/components/tree/interface.d.ts +45 -0
  72. package/dist/components/tree-select/interface.d.ts +55 -0
  73. package/dist/components/typography/interface.d.ts +33 -0
  74. package/dist/components/upload/interface.d.ts +64 -0
  75. package/dist/components/user-guide/interface.d.ts +15 -0
  76. package/dist/components/video-player/interface.d.ts +22 -0
  77. package/docs/advanced/dark-mode.md +288 -0
  78. package/docs/basic/button.md +605 -0
  79. package/docs/basic/divider.md +103 -0
  80. package/docs/basic/float-button.md +246 -0
  81. package/docs/basic/grid.md +427 -0
  82. package/docs/basic/layout.md +459 -0
  83. package/docs/basic/resizable.md +584 -0
  84. package/docs/basic/space.md +163 -0
  85. package/docs/basic/tokens.md +425 -0
  86. package/docs/basic/typography.md +615 -0
  87. package/docs/changes-from-semi.md +105 -0
  88. package/docs/ecosystem/tailwind.md +210 -0
  89. package/docs/experience/accessibility.md +82 -0
  90. package/docs/experience/content-guidelines.md +819 -0
  91. package/docs/experience/internationalization.md +7 -0
  92. package/docs/feedback/banner.md +198 -0
  93. package/docs/feedback/feedback.md +294 -0
  94. package/docs/feedback/notification.md +401 -0
  95. package/docs/feedback/popconfirm.md +243 -0
  96. package/docs/feedback/progress.md +389 -0
  97. package/docs/feedback/skeleton.md +388 -0
  98. package/docs/feedback/spin.md +172 -0
  99. package/docs/feedback/toast.md +393 -0
  100. package/docs/input/auto-complete.md +399 -0
  101. package/docs/input/cascader.md +1558 -0
  102. package/docs/input/checkbox.md +408 -0
  103. package/docs/input/color-picker.md +175 -0
  104. package/docs/input/date-picker.md +942 -0
  105. package/docs/input/form.md +2550 -0
  106. package/docs/input/input-number.md +451 -0
  107. package/docs/input/input.md +640 -0
  108. package/docs/input/pincode.md +191 -0
  109. package/docs/input/radio.md +337 -0
  110. package/docs/input/rating.md +214 -0
  111. package/docs/input/select.md +1230 -0
  112. package/docs/input/slider.md +347 -0
  113. package/docs/input/switch.md +206 -0
  114. package/docs/input/tag-input.md +465 -0
  115. package/docs/input/time-picker.md +358 -0
  116. package/docs/input/transfer.md +1061 -0
  117. package/docs/input/tree-select.md +1300 -0
  118. package/docs/input/upload.md +1811 -0
  119. package/docs/llms.txt +147 -0
  120. package/docs/navigation/anchor.md +377 -0
  121. package/docs/navigation/backtop.md +100 -0
  122. package/docs/navigation/breadcrumb.md +284 -0
  123. package/docs/navigation/navigation.md +851 -0
  124. package/docs/navigation/pagination.md +217 -0
  125. package/docs/navigation/steps.md +315 -0
  126. package/docs/navigation/tabs.md +754 -0
  127. package/docs/navigation/tree.md +1956 -0
  128. package/docs/other/config-provider.md +599 -0
  129. package/docs/other/locale.md +353 -0
  130. package/docs/plus/audio-player.md +155 -0
  131. package/docs/plus/code-highlight.md +150 -0
  132. package/docs/plus/drag-move.md +214 -0
  133. package/docs/plus/hot-keys.md +174 -0
  134. package/docs/plus/json-viewer.md +392 -0
  135. package/docs/plus/lottie.md +176 -0
  136. package/docs/plus/markdown-render.md +240 -0
  137. package/docs/plus/video-player.md +325 -0
  138. package/docs/show/avatar.md +475 -0
  139. package/docs/show/badge.md +276 -0
  140. package/docs/show/calendar.md +352 -0
  141. package/docs/show/card.md +485 -0
  142. package/docs/show/carousel.md +592 -0
  143. package/docs/show/collapse.md +289 -0
  144. package/docs/show/collapsible.md +216 -0
  145. package/docs/show/cropper.md +285 -0
  146. package/docs/show/descriptions.md +325 -0
  147. package/docs/show/dropdown.md +466 -0
  148. package/docs/show/empty.md +225 -0
  149. package/docs/show/highlight.md +144 -0
  150. package/docs/show/image.md +433 -0
  151. package/docs/show/list.md +927 -0
  152. package/docs/show/modal.md +517 -0
  153. package/docs/show/overflow-list.md +272 -0
  154. package/docs/show/popover.md +534 -0
  155. package/docs/show/scroll-list.md +156 -0
  156. package/docs/show/side-sheet.md +274 -0
  157. package/docs/show/table.md +5437 -0
  158. package/docs/show/tag.md +428 -0
  159. package/docs/show/timeline.md +277 -0
  160. package/docs/show/tooltip.md +442 -0
  161. package/docs/show/user-guide.md +419 -0
  162. package/docs/start/getting-started.md +234 -0
  163. package/docs/start/introduction.md +57 -0
  164. package/docs/start/overview.md +21 -0
  165. package/package.json +5 -4
@@ -0,0 +1,1300 @@
1
+ # TreeSelect
2
+
3
+ > TreeSelector is used for structured display & selection of multi-level tree data, such as displaying a list of folders and files, displaying a list of organizational structure members, and so on.
4
+
5
+ Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/tree-select/
6
+
7
+ ## When to Use
8
+
9
+ When the options to select is in tree structure, you could use TreeSelect, e.g. department hierarchy, subject system, category directory and etc.
10
+
11
+ ## Demos
12
+
13
+ ### How to import
14
+
15
+ ```svelte
16
+ <script lang="ts">
17
+ import { TreeSelect } from '@fibrae/semi-ui-svelte';
18
+ </script>
19
+ ```
20
+
21
+ ### Basic Usage
22
+
23
+ By default, TreeSelect is in single select mode and each item is selectable.
24
+
25
+ ```svelte
26
+ <script lang="ts">
27
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
28
+
29
+ const treeData: TreeNodeData[] = [
30
+ {
31
+ label: '亚洲',
32
+ value: 'Asia',
33
+ key: '0',
34
+ children: [
35
+ {
36
+ label: '中国',
37
+ value: 'China',
38
+ key: '0-0',
39
+ children: [
40
+ {
41
+ label: '北京',
42
+ value: 'Beijing',
43
+ key: '0-0-0',
44
+ },
45
+ {
46
+ label: '上海',
47
+ value: 'Shanghai',
48
+ key: '0-0-1',
49
+ },
50
+ ],
51
+ },
52
+ ],
53
+ },
54
+ {
55
+ label: '北美洲',
56
+ value: 'North America',
57
+ key: '1',
58
+ },
59
+ ];
60
+ </script>
61
+
62
+ <TreeSelect placeholder="请选择" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
63
+ ```
64
+
65
+ ### Multi-choice
66
+
67
+ You could use `multiple` to set mode to multi-choice. When all child items are selected, the parent item will be selected.
68
+
69
+ In multiple mode `bind:value` and `value` are arrays. Use `leafOnly` if you prefer to render leaf nodes only, and the value of `bind:value` and the arguments of `onChange` will also hold leaf node values only.
70
+
71
+ ```svelte
72
+ <script lang="ts">
73
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
74
+
75
+ const treeData: TreeNodeData[] = [
76
+ {
77
+ label: 'Asia',
78
+ value: 'Asia',
79
+ key: '0',
80
+ children: [
81
+ {
82
+ label: 'China',
83
+ value: 'China',
84
+ key: '0-0',
85
+ children: [
86
+ {
87
+ label: 'Beijing',
88
+ value: 'Beijing',
89
+ key: '0-0-0',
90
+ },
91
+ {
92
+ label: 'Shanghai',
93
+ value: 'Shanghai',
94
+ key: '0-0-1',
95
+ },
96
+ {
97
+ label: 'Chengdu',
98
+ value: 'Chengdu',
99
+ key: '0-0-2',
100
+ },
101
+ ],
102
+ },
103
+ {
104
+ label: 'Japan',
105
+ value: 'Japan',
106
+ key: '0-1',
107
+ children: [
108
+ {
109
+ label: 'Osaka',
110
+ value: 'Osaka',
111
+ key: '0-1-0',
112
+ },
113
+ ],
114
+ },
115
+ ],
116
+ },
117
+ {
118
+ label: 'North America',
119
+ value: 'North America',
120
+ key: '1',
121
+ children: [
122
+ {
123
+ label: 'United States',
124
+ value: 'United States',
125
+ key: '1-0',
126
+ },
127
+ {
128
+ label: 'Canada',
129
+ value: 'Canada',
130
+ key: '1-1',
131
+ },
132
+ ],
133
+ },
134
+ ];
135
+ </script>
136
+
137
+ <div>
138
+ <TreeSelect multiple placeholder="请选择" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
139
+ <br />
140
+ <br />
141
+ <TreeSelect leafOnly multiple placeholder="只渲染叶子节点" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
142
+ <br />
143
+ <br />
144
+ </div>
145
+ ```
146
+
147
+ ### Limit Tags Number
148
+
149
+ In the multi-selection scenario, `maxTagCount` can be used to limit the number of tags displayed, and the excess part will be displayed in the form of +N.\
150
+ Use `showRestTagsPopover` to set whether hover +N displays Popover after exceeding `maxTagCount`, the default is `false`. Also, popovers can be configured in the `restTagsPopoverProps` property.
151
+
152
+ ```svelte
153
+ <script lang="ts">
154
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
155
+
156
+ const treeData: TreeNodeData[] = [
157
+ {
158
+ label: 'Asia',
159
+ value: 'Asia',
160
+ key: '0',
161
+ children: [
162
+ {
163
+ label: 'China',
164
+ value: 'China',
165
+ key: '0-0',
166
+ children: [
167
+ {
168
+ label: 'Beijing',
169
+ value: 'Beijing',
170
+ key: '0-0-0',
171
+ },
172
+ {
173
+ label: 'Shanghai',
174
+ value: 'Shanghai',
175
+ key: '0-0-1',
176
+ },
177
+ {
178
+ label: 'Chengdu',
179
+ value: 'Chengdu',
180
+ key: '0-0-2',
181
+ },
182
+ ],
183
+ },
184
+ {
185
+ label: 'Japan',
186
+ value: 'Japan',
187
+ key: '0-1',
188
+ children: [
189
+ {
190
+ label: 'Osaka',
191
+ value: 'Osaka',
192
+ key: '0-1-0',
193
+ },
194
+ ],
195
+ },
196
+ ],
197
+ },
198
+ {
199
+ label: 'North America',
200
+ value: 'North America',
201
+ key: '1',
202
+ children: [
203
+ {
204
+ label: 'United States',
205
+ value: 'United States',
206
+ key: '1-0',
207
+ },
208
+ {
209
+ label: 'Canada',
210
+ value: 'Canada',
211
+ key: '1-1',
212
+ },
213
+ ],
214
+ },
215
+ ];
216
+
217
+ const textStyle = 'margin: 20px 0 10px';
218
+ </script>
219
+
220
+ <div>
221
+ <h4 style={textStyle}>maxTagCount=2:</h4>
222
+ <TreeSelect maxTagCount={2} multiple placeholder="当选中标签超过两个将折叠" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} value={['Beijing', 'Chengdu', 'Canada']} />
223
+ <h4 style={textStyle}>maxTagCount=2, showRestTagsPopover:</h4>
224
+ <TreeSelect maxTagCount={2} multiple placeholder="hover +N 查看" restTagsPopoverProps={{ position: 'top' }} showRestTagsPopover style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} value={['Beijing', 'Chengdu', 'Canada']} />
225
+ </div>
226
+ ```
227
+
228
+ ### Searchable
229
+
230
+ Use `filterTreeNode` to support search input. By default it searches the `label` property of the data. You can use `treeNodeFilterProp` to set another property to search or pass in a function to `filterTreeNode` to customize search behavior.
231
+
232
+ You could also use `showFilteredOnly` if you prefer to display filtered results only.
233
+
234
+ If you want to get specific information about the search results, you can use the `onSearch` callback function. See the API list for the specific parameters of the function.
235
+
236
+ ```svelte
237
+ <script lang="ts">
238
+ import { Switch, TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
239
+
240
+ let showFilteredOnly = $state(false);
241
+
242
+ const treeData: TreeNodeData[] = [
243
+ {
244
+ label: 'Asia',
245
+ value: 'Asia',
246
+ key: '0',
247
+ children: [
248
+ {
249
+ label: 'China',
250
+ value: 'China',
251
+ key: '0-0',
252
+ children: [
253
+ { label: 'Beijing', value: 'Beijing', key: '0-0-0' },
254
+ { label: 'Shanghai', value: 'Shanghai', key: '0-0-1' },
255
+ ],
256
+ },
257
+ {
258
+ label: 'Japan',
259
+ value: 'Japan',
260
+ key: '0-1',
261
+ children: [{ label: 'Osaka', value: 'Osaka', key: '0-1-0' }],
262
+ },
263
+ ],
264
+ },
265
+ {
266
+ label: 'North America',
267
+ value: 'North America',
268
+ key: '1',
269
+ children: [
270
+ { label: 'United States', value: 'United States', key: '1-0' },
271
+ { label: 'Canada', value: 'Canada', key: '1-1' },
272
+ ],
273
+ },
274
+ ];
275
+
276
+ const onSearch = (inputValue: string, filteredExpandedKeys: string[], filteredNodes: TreeNodeData[]) => {
277
+ console.log('onSearch', inputValue, filteredExpandedKeys, filteredNodes);
278
+ };
279
+ </script>
280
+
281
+ <span id="treeselect-searchable-filtered-only">showFilteredOnly</span>
282
+ <Switch aria-labelledby="treeselect-searchable-filtered-only" bind:checked={showFilteredOnly} size="small" />
283
+ <br />
284
+ <br />
285
+ <TreeSelect filterTreeNode {onSearch} placeholder="单选可搜索的" {showFilteredOnly} style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
286
+ <br />
287
+ <br />
288
+ <TreeSelect filterTreeNode maxTagCount={2} multiple {onSearch} placeholder="多选可搜索的" searchPlaceholder="请输入关键字开始搜索" {showFilteredOnly} style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
289
+ <br />
290
+ <br />
291
+ <TreeSelect filterTreeNode maxTagCount={2} multiple {onSearch} placeholder="搜索框autofocus" searchAutoFocus searchPlaceholder="autofocus" {showFilteredOnly} style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
292
+ ```
293
+
294
+ ### Remote Search
295
+
296
+ By setting the `remote` property, you can enable remote search. When enabled, local filtering is skipped on input and only the `onSearch` callback is triggered, allowing users to handle remote data fetching and update `treeData` (only a new array updates it).
297
+
298
+ ```svelte
299
+ <script lang="ts">
300
+ import { TreeSelect, type TreeNodeData, type TreeSelectValue } from '@fibrae/semi-ui-svelte';
301
+
302
+ let value = $state<TreeSelectValue | undefined>();
303
+ let treeData = $state.raw<TreeNodeData[]>([]);
304
+
305
+ let latestInput = '';
306
+
307
+ const handleSearch = (inputValue: string) => {
308
+ latestInput = inputValue;
309
+ if (!inputValue) {
310
+ treeData = [];
311
+ return;
312
+ }
313
+
314
+ setTimeout(() => {
315
+ if (latestInput !== inputValue) {
316
+ return;
317
+ }
318
+ const mockData = [
319
+ { label: `${inputValue} - 结果1`, value: `${inputValue}-1`, key: `${inputValue}-1` },
320
+ { label: `${inputValue} - 结果2`, value: `${inputValue}-2`, key: `${inputValue}-2` },
321
+ { label: `${inputValue} - 结果3`, value: `${inputValue}-3`, key: `${inputValue}-3` },
322
+ ];
323
+ treeData = mockData;
324
+ }, 500);
325
+ };
326
+ </script>
327
+
328
+ <TreeSelect bind:value filterTreeNode onSearch={handleSearch} placeholder="请输入关键字进行远程搜索" remote style="width: 300px" {treeData} />
329
+ ```
330
+
331
+ ### Search Box Position
332
+
333
+ You can use `searchPosition` to set the position of the search box, optional: `dropdown` (default), `trigger`.
334
+
335
+ When the input box is at trigger:
336
+
337
+ 1. The placeholder of the search box is controlled by `placeholder`;
338
+ 2. When `showClear=true`, click the clear button of the input box, the inputValue and value will be cleared at the same time.
339
+
340
+ ```svelte
341
+ <script lang="ts">
342
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
343
+
344
+ const treeData: TreeNodeData[] = [
345
+ {
346
+ label: 'Asia',
347
+ value: 'Asia',
348
+ key: '0',
349
+ children: [
350
+ {
351
+ label: 'China',
352
+ value: 'China',
353
+ key: '0-0',
354
+ children: [
355
+ {
356
+ label: 'Beijing',
357
+ value: 'Beijing',
358
+ key: '0-0-0',
359
+ },
360
+ {
361
+ label: 'Shanghai',
362
+ value: 'Shanghai',
363
+ key: '0-0-1',
364
+ },
365
+ ],
366
+ },
367
+ {
368
+ label: 'Japan',
369
+ value: 'Japan',
370
+ key: '0-1',
371
+ children: [
372
+ {
373
+ label: 'Osaka',
374
+ value: 'Osaka',
375
+ key: '0-1-0',
376
+ },
377
+ ],
378
+ },
379
+ ],
380
+ },
381
+ {
382
+ label: 'North America',
383
+ value: 'North America',
384
+ key: '1',
385
+ children: [
386
+ {
387
+ label: 'United States',
388
+ value: 'United States',
389
+ key: '1-0',
390
+ },
391
+ {
392
+ label: 'Canada',
393
+ value: 'Canada',
394
+ key: '1-1',
395
+ },
396
+ ],
397
+ },
398
+ ];
399
+ </script>
400
+
401
+ <TreeSelect filterTreeNode placeholder="单选" searchPosition="trigger" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
402
+ <br />
403
+ <br />
404
+ <TreeSelect filterTreeNode maxTagCount={2} multiple placeholder="多选" searchPosition="trigger" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
405
+ ```
406
+
407
+ ### Wrap tags in trigger (triggerTagWrap)
408
+
409
+ In **multiple + searchable + searchPosition="trigger"** mode, if there are many selected items or the input is long, the trigger may prefer to keep a single-line layout by default.
410
+
411
+ Turn on `triggerTagWrap` to allow selected tags to wrap into multiple lines within the trigger.
412
+
413
+ ```svelte
414
+ <script lang="ts">
415
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
416
+
417
+ const treeData: TreeNodeData[] = [
418
+ {
419
+ label: 'Asia',
420
+ value: 'Asia',
421
+ key: '0',
422
+ children: [
423
+ {
424
+ label: 'China',
425
+ value: 'China',
426
+ key: '0-0',
427
+ children: [
428
+ { label: 'Beijing', value: 'Beijing', key: '0-0-0' },
429
+ { label: 'Shanghai', value: 'Shanghai', key: '0-0-1' },
430
+ { label: 'Shenzhen', value: 'Shenzhen', key: '0-0-2' },
431
+ { label: 'Guangzhou', value: 'Guangzhou', key: '0-0-3' },
432
+ ],
433
+ },
434
+ {
435
+ label: 'Japan',
436
+ value: 'Japan',
437
+ key: '0-1',
438
+ children: [{ label: 'Osaka', value: 'Osaka', key: '0-1-0' }],
439
+ },
440
+ ],
441
+ },
442
+ {
443
+ label: 'North America',
444
+ value: 'North America',
445
+ key: '1',
446
+ children: [
447
+ { label: 'United States', value: 'United States', key: '1-0' },
448
+ { label: 'Canada', value: 'Canada', key: '1-1' },
449
+ ],
450
+ },
451
+ ];
452
+ </script>
453
+
454
+ <TreeSelect filterTreeNode multiple placeholder="请选择多个选项或输入长文本" searchPosition="trigger" style="width: 260px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} triggerTagWrap value={['Beijing', 'Shanghai', 'Shenzhen', 'Guangzhou']} />
455
+ ```
456
+
457
+ ### Size
458
+
459
+ You can set the size by `size`, one of: 'small'、'default'、'large'
460
+
461
+ ```svelte
462
+ <script lang="ts">
463
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
464
+
465
+ const treeData: TreeNodeData[] = [
466
+ {
467
+ label: '亚洲',
468
+ value: 'Asia',
469
+ key: '0',
470
+ children: [
471
+ {
472
+ label: '中国',
473
+ value: 'China',
474
+ key: '0-0',
475
+ children: [
476
+ { label: '北京', value: 'Beijing', key: '0-0-0' },
477
+ { label: '上海', value: 'Shanghai', key: '0-0-1' },
478
+ ],
479
+ },
480
+ ],
481
+ },
482
+ { label: '北美洲', value: 'North America', key: '1' },
483
+ ];
484
+ </script>
485
+
486
+ <div>
487
+ <TreeSelect multiple placeholder="small" size="small" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
488
+ <br />
489
+ <br />
490
+ <TreeSelect multiple placeholder="default" size="default" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
491
+ <br />
492
+ <br />
493
+ <TreeSelect multiple placeholder="large" size="large" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
494
+ </div>
495
+ ```
496
+
497
+ ### Default Expand All
498
+
499
+ Both `defaultExpandAll` and `expandAll` can set the default expanded/collapsed state of `TreeSelect`. The difference between the two is that `defaultExpandAll` only takes effect during initialization, while `expandAll` will take effect not only during initialization, but also when the data (`treeData`) is dynamically updated.
500
+
501
+ In the demo below, after `TreeData` is updated, `defaultExpandAll` becomes invalid, and `expandAll` still takes effect.
502
+
503
+ ```svelte
504
+ <script lang="ts">
505
+ import { onMount } from 'svelte';
506
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
507
+
508
+ const treeData: TreeNodeData[] = [
509
+ {
510
+ label: '亚洲',
511
+ value: 'Asia',
512
+ key: '0',
513
+ children: [
514
+ {
515
+ label: '中国',
516
+ value: 'China',
517
+ key: '0-0',
518
+ children: [
519
+ {
520
+ label: '北京',
521
+ value: 'Beijing',
522
+ key: '0-0-0',
523
+ },
524
+ {
525
+ label: '上海',
526
+ value: 'Shanghai',
527
+ key: '0-0-1',
528
+ },
529
+ ],
530
+ },
531
+ ],
532
+ },
533
+ {
534
+ label: '北美洲',
535
+ value: 'North America',
536
+ key: '1',
537
+ },
538
+ ];
539
+ let data = $state.raw<TreeNodeData[]>([]);
540
+
541
+ onMount(() => {
542
+ const timer = setTimeout(() => {
543
+ data = treeData;
544
+ }, 500);
545
+ return () => clearTimeout(timer);
546
+ });
547
+ </script>
548
+
549
+ <TreeSelect expandAll placeholder="expandAll" style="width: 300px; margin-bottom: 20px" treeData={data} />
550
+ <TreeSelect defaultExpandAll placeholder="defaultExpandAll" style="width: 300px" treeData={data} />
551
+ ```
552
+
553
+ ### Disabled
554
+
555
+ ```svelte
556
+ <script lang="ts">
557
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
558
+
559
+ const treeData: TreeNodeData[] = [
560
+ {
561
+ label: '亚洲',
562
+ value: 'Asia',
563
+ key: '0',
564
+ children: [
565
+ {
566
+ label: '中国',
567
+ value: 'China',
568
+ key: '0-0',
569
+ children: [
570
+ {
571
+ label: '北京',
572
+ value: 'Beijing',
573
+ key: '0-0-0',
574
+ },
575
+ {
576
+ label: '上海',
577
+ value: 'Shanghai',
578
+ key: '0-0-1',
579
+ },
580
+ ],
581
+ },
582
+ ],
583
+ },
584
+ {
585
+ label: '北美洲',
586
+ value: 'North America',
587
+ key: '1',
588
+ },
589
+ ];
590
+ </script>
591
+
592
+ <div>
593
+ <TreeSelect disabled placeholder="禁用下拉菜单" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
594
+ <br />
595
+ <br />
596
+ <TreeSelect disabled style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} value="Shanghai" />
597
+ <br />
598
+ <br />
599
+ <TreeSelect disabled multiple style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} value={['Shanghai', 'North America']} />
600
+ </div>
601
+ ```
602
+
603
+ ### Disable Strictly
604
+
605
+ You can use `disableStrictly` to enable strict disabling. After enabling strict disabling, when the node is disabled, the selected state cannot be changed through the relationship between the child or the parent.
606
+
607
+ Take the following demo as an example, the node "China" is strictly disabled. Therefore, when we change the selected state of its parent node "Asia", it will not affect the selected state of the node "China".
608
+
609
+ ```svelte
610
+ <script lang="ts">
611
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
612
+
613
+ const treeData: TreeNodeData[] = [
614
+ {
615
+ label: '亚洲',
616
+ value: 'Asia',
617
+ key: '0',
618
+ children: [
619
+ {
620
+ label: '中国',
621
+ value: 'China',
622
+ key: '0-0',
623
+ disabled: true,
624
+ children: [
625
+ {
626
+ label: '北京',
627
+ value: 'Beijing',
628
+ key: '0-0-0',
629
+ },
630
+ {
631
+ label: '上海',
632
+ value: 'Shanghai',
633
+ key: '0-0-1',
634
+ },
635
+ ],
636
+ },
637
+ {
638
+ label: '日本',
639
+ value: 'Japan',
640
+ key: '0-1',
641
+ },
642
+ ],
643
+ },
644
+ {
645
+ label: '北美洲',
646
+ value: 'North America',
647
+ key: '1',
648
+ },
649
+ ];
650
+ </script>
651
+
652
+ <div>
653
+ <TreeSelect disableStrictly multiple style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} value={['Shanghai']} />
654
+ </div>
655
+ ```
656
+
657
+ ### Controlled Component
658
+
659
+ Bind the selected value with `bind:value` to use TreeSelect as a controlled component; changes are written back automatically. You can also pass `value` along with `onChange`. TreeSelect has no `defaultValue`: a one-way `value={x}` only seeds the selection, and for a fully controlled select use the function binding `bind:value={get, set}`. Binding it to `undefined` clears the selection.
660
+
661
+ ```svelte
662
+ <script lang="ts">
663
+ import { TreeSelect, type TreeNodeData, type TreeSelectValue } from '@fibrae/semi-ui-svelte';
664
+
665
+ const treeData: TreeNodeData[] = [
666
+ {
667
+ label: '亚洲',
668
+ value: 'Asia',
669
+ key: '0',
670
+ children: [
671
+ {
672
+ label: '中国',
673
+ value: 'China',
674
+ key: '0-0',
675
+ children: [
676
+ {
677
+ label: '北京',
678
+ value: 'Beijing',
679
+ key: '0-0-0',
680
+ },
681
+ {
682
+ label: '上海',
683
+ value: 'Shanghai',
684
+ key: '0-0-1',
685
+ },
686
+ ],
687
+ },
688
+ ],
689
+ },
690
+ {
691
+ label: '北美洲',
692
+ value: 'North America',
693
+ key: '1',
694
+ },
695
+ ];
696
+ let value = $state<TreeSelectValue | undefined>('Shanghai');
697
+ </script>
698
+
699
+ <TreeSelect bind:value placeholder="请选择" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
700
+ ```
701
+
702
+ ### Checked RelationShip
703
+
704
+ In multiple, `checkRelation` can be used to set the type of node selection relationship, optional: 'related' (default), 'unRelated'. When the selection relationship is 'unRelated', it means that selections between nodes do not affect each other.
705
+
706
+ ```svelte
707
+ <script lang="ts">
708
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
709
+
710
+ const treeData: TreeNodeData[] = [
711
+ {
712
+ label: '亚洲',
713
+ value: 'Asia',
714
+ key: '0',
715
+ children: [
716
+ {
717
+ label: '中国',
718
+ value: 'China',
719
+ key: '0-0',
720
+ children: [
721
+ {
722
+ label: '北京',
723
+ value: 'Beijing',
724
+ key: '0-0-0',
725
+ },
726
+ {
727
+ label: '上海',
728
+ value: 'Shanghai',
729
+ key: '0-0-1',
730
+ },
731
+ ],
732
+ },
733
+ ],
734
+ },
735
+ {
736
+ label: '北美洲',
737
+ value: 'North America',
738
+ key: '1',
739
+ },
740
+ ];
741
+ </script>
742
+
743
+ <TreeSelect checkRelation="unRelated" multiple style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} value={['Asia']} />
744
+ ```
745
+
746
+ ### Controlled Expansion with Search
747
+
748
+ Bind the expanded nodes with `bind:expandedKeys` to make the expansion controlled; you can also pass `expandedKeys` along with `onExpand`. TreeSelect has no `defaultExpandedKeys`. When the expansion is controlled, if the `filterTreeNode` is turned on and the search is performed, the node will no longer be automatically expanded. At this time, the expansion of the node is completely controlled by the `expandedKeys`. You can use the parameter `filteredExpandedKeys` of `onSearch` to realize the search expansion effect when the expansion is controlled.
749
+
750
+ ```svelte
751
+ <script lang="ts">
752
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
753
+
754
+ let expandedKeys = $state<string[]>([]);
755
+ const treeData: TreeNodeData[] = [
756
+ {
757
+ label: '亚洲',
758
+ value: 'Asia',
759
+ key: '0',
760
+ children: [
761
+ {
762
+ label: '中国',
763
+ value: 'China',
764
+ key: '0-0',
765
+ children: [
766
+ {
767
+ label: '北京',
768
+ value: 'Beijing',
769
+ key: '0-0-0',
770
+ },
771
+ {
772
+ label: '上海',
773
+ value: 'Shanghai',
774
+ key: '0-0-1',
775
+ },
776
+ ],
777
+ },
778
+ {
779
+ label: '日本',
780
+ value: 'Japan',
781
+ key: '0-1',
782
+ },
783
+ ],
784
+ },
785
+ {
786
+ label: '北美洲',
787
+ value: 'North America',
788
+ key: '1',
789
+ },
790
+ ];
791
+
792
+ const onSearch = (_inputValue: string, filteredExpandedKeys: string[]) => {
793
+ expandedKeys = [...filteredExpandedKeys, ...expandedKeys];
794
+ };
795
+ </script>
796
+
797
+ <TreeSelect bind:expandedKeys filterTreeNode {onSearch} style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
798
+ ```
799
+
800
+ ### Virtualized TreeSelect
801
+
802
+ If you need to render large sets of tree structured data, you could use virtualized tree. In virtualized mode, animation / motion is disabled for better performance.
803
+
804
+ The property `virtualize` is an object consisting of the following values:
805
+
806
+ - height: Height of the dropDown, If passed in as a string, computed height should not be zero for render purpose, in other words, parent node should have offsetHeight. Pass in a number recommended.
807
+ - width: Width of the dropDown.
808
+ - itemSize: Height for each line of treeNode, required
809
+
810
+ If tree is searchable, you could also turn on `showFilteredOnly` to reduce time of rendering for results.
811
+
812
+ ```svelte
813
+ <script lang="ts">
814
+ import { Button, TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
815
+
816
+ // x: nodes per level. y: nodes with children per level. z: depth (0 is one level).
817
+ const generateData = (x = 5, y = 4, z = 3) => {
818
+ const data: TreeNodeData[] = [];
819
+
820
+ const fill = (level: number, preKey: string, nodes: TreeNodeData[]) => {
821
+ const parents: string[] = [];
822
+ for (let i = 0; i < x; i++) {
823
+ const key = `${preKey}-${i}`;
824
+ nodes.push({ label: `${key}-标签`, key: `${key}-key`, value: `${key}-value` });
825
+ if (i < y) {
826
+ parents.push(key);
827
+ }
828
+ }
829
+ if (level < 0) {
830
+ return;
831
+ }
832
+ parents.forEach((key, index) => {
833
+ const children: TreeNodeData[] = [];
834
+ nodes[index].children = children;
835
+ fill(level - 1, key, children);
836
+ });
837
+ };
838
+ fill(z, '0', data);
839
+
840
+ let total = 0;
841
+ for (let n = z + 1; n >= 0; n--) {
842
+ total += x * y ** n;
843
+ }
844
+ return { gData: data, total };
845
+ };
846
+
847
+ let gData = $state.raw<TreeNodeData[]>([]);
848
+ let total = $state(0);
849
+
850
+ const onGen = () => {
851
+ const generated = generateData();
852
+ gData = generated.gData;
853
+ total = generated.total;
854
+ };
855
+ </script>
856
+
857
+ <div style="padding: 0 20px">
858
+ <Button onclick={onGen}>生成数据:</Button>
859
+ <span>共 {total} 个节点</span>
860
+ <br />
861
+ <br />
862
+ {#if gData.length > 0}
863
+ <!-- Dropdown height 300 minus the search box and 8 * 2 padding; a set height fills the rest -->
864
+ <TreeSelect filterTreeNode placeholder="Please select" showFilteredOnly style="width: 300px" styles={{ dropdown: 'overflow: hidden' }} treeData={gData} virtualize={{ itemSize: 28, height: 236 }} />
865
+ {/if}
866
+ </div>
867
+ ```
868
+
869
+ ### Dynamic Update of Data
870
+
871
+ ```svelte
872
+ <script lang="ts">
873
+ import { Button, TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
874
+
875
+ // Only a new array updates the options, so the list is replaced as a whole.
876
+ let treeData = $state.raw<TreeNodeData[]>([]);
877
+
878
+ const add = () => {
879
+ const itemLength = Math.floor(Math.random() * 5) + 1;
880
+ treeData = Array.from({ length: itemLength }, (_, i) => {
881
+ const length = Math.floor(Math.random() * 3);
882
+ const children = Array.from({ length }, (_, ci) => ({
883
+ key: `${i}-${ci}`,
884
+ label: `Leaf-${i}-${ci}`,
885
+ value: `${i}-${ci}`,
886
+ }));
887
+ return {
888
+ key: `${i}`,
889
+ label: `Item-${i}`,
890
+ value: `${i}`,
891
+ children,
892
+ };
893
+ });
894
+ };
895
+ </script>
896
+
897
+ <TreeSelect placeholder="请选择" style="width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
898
+ <br />
899
+ <br />
900
+ <Button onclick={add}>动态改变数据</Button>
901
+ ```
902
+
903
+ ### Load Data Asynchronously
904
+
905
+ You could use `loadData` to load treeData asynchronously on node expansion. Notice `isLeaf` is required to mark node as leaf in treeData.
906
+
907
+ ```svelte
908
+ <script lang="ts">
909
+ import { TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
910
+
911
+ const initialData: TreeNodeData[] = [
912
+ {
913
+ label: 'Expand to load',
914
+ value: '0',
915
+ key: '0',
916
+ },
917
+ {
918
+ label: 'Expand to load',
919
+ value: '1',
920
+ key: '1',
921
+ },
922
+ {
923
+ label: 'Leaf Node',
924
+ value: '2',
925
+ key: '2',
926
+ isLeaf: true,
927
+ },
928
+ ];
929
+
930
+ const updateTreeData = (list: TreeNodeData[], key: string | undefined, children: TreeNodeData[]): TreeNodeData[] => {
931
+ return list.map((node) => {
932
+ if (node.key === key) {
933
+ return { ...node, children };
934
+ }
935
+ if (node.children) {
936
+ return { ...node, children: updateTreeData(node.children, key, children) };
937
+ }
938
+ return node;
939
+ });
940
+ };
941
+
942
+ let treeData = $state.raw(initialData);
943
+
944
+ const onLoadData = ({ key, children }: TreeNodeData) => {
945
+ return new Promise<void>((resolve) => {
946
+ if (children) {
947
+ resolve();
948
+ return;
949
+ }
950
+ setTimeout(() => {
951
+ treeData = updateTreeData(treeData, key, [
952
+ {
953
+ label: 'Child Node',
954
+ key: `${key}-0`,
955
+ },
956
+ {
957
+ label: 'Child Node',
958
+ key: `${key}-1`,
959
+ },
960
+ ]);
961
+ resolve();
962
+ }, 1000);
963
+ });
964
+ };
965
+ </script>
966
+
967
+ <TreeSelect loadData={onLoadData} placeholder="请选择" style="width: 300px" {treeData} />
968
+ ```
969
+
970
+ ### Custom Trigger
971
+
972
+ If the default trigger style cannot meet your needs, you can use the `trigger` snippet to customize the display of the select box.
973
+
974
+ The parameters of the `trigger` snippet are as follows, typed as `TreeSelectTriggerSnippetProps`:
975
+
976
+ ```typescript
977
+ interface TreeSelectTriggerSnippetProps {
978
+ componentProps: TreeSelectProps; // all the props given to TreeSelect
979
+ disabled: boolean; // whether the TreeSelect is disabled
980
+ value: TreeNodeData[]; // the data of the selected nodes
981
+ inputValue: string; // the current value of the input box
982
+ placeholder?: string; // placeholder
983
+ // Clears the value; pass the click event when bound to a control inside the trigger,
984
+ // so the click does not also open the dropdown
985
+ onClear: (event?: MouseEvent) => void;
986
+ // Called to remove a single item, with the key of the item
987
+ onRemove: (key: string) => void;
988
+ // Starts a search when the value of your Input changes; filterTreeNode must not be false
989
+ // and searchPosition must be 'trigger'
990
+ onSearch: (inputValue: string) => void;
991
+ }
992
+ ```
993
+
994
+ ```svelte
995
+ <script lang="ts">
996
+ import { Tag, TagInput, TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
997
+
998
+ const treeData: TreeNodeData[] = [
999
+ {
1000
+ label: '亚洲',
1001
+ value: '亚洲',
1002
+ key: '0',
1003
+ children: [
1004
+ {
1005
+ label: '中国',
1006
+ value: '中国',
1007
+ key: '0-0',
1008
+ children: [
1009
+ { label: '北京', value: '北京', key: '0-0-0' },
1010
+ { label: '上海', value: '上海', key: '0-0-1' },
1011
+ ],
1012
+ },
1013
+ ],
1014
+ },
1015
+ { label: '北美洲', value: '北美洲', key: '1' },
1016
+ ];
1017
+
1018
+ const onChange = (value: unknown) => {
1019
+ console.log('onChange', value);
1020
+ };
1021
+ </script>
1022
+
1023
+ <TreeSelect filterTreeNode multiple {onChange} placeholder="Custom Trigger" searchPosition="trigger" style="width: 300px" {treeData}>
1024
+ {#snippet trigger(triggerState)}
1025
+ <TagInput inputValue={triggerState.inputValue} onInputChange={triggerState.onSearch} value={triggerState.value.flatMap((item) => item.key ?? [])}>
1026
+ {#snippet tag(tagItem)}
1027
+ <Tag closable onClose={() => triggerState.onRemove(tagItem.value)} style="margin-inline-start: 2px" tagKey={tagItem.value}>
1028
+ {triggerState.value.find((item) => item.key === tagItem.value)?.label}
1029
+ </Tag>
1030
+ {/snippet}
1031
+ </TagInput>
1032
+ {/snippet}
1033
+ </TreeSelect>
1034
+ ```
1035
+
1036
+ ### Custom Rendering Selected Item
1037
+
1038
+ You can use the `selectedItem` and `tag` snippets to customize the rendering structure of the selected items in the selection box. Both take the same parameters, typed as `TreeSelectSelectedItemSnippetProps`: `item` (the node data), `index`, `disabled` and `onClose` (removes the tag, or clears the selection in single mode).
1039
+
1040
+ - In single mode the content of `selectedItem` is what the select box shows; empty content shows the `placeholder`
1041
+ - In multiple mode the content of `selectedItem` is rendered inside the built-in Tag (with background color and close button); `tag` replaces the whole Tag and takes precedence over `selectedItem`, so wire `onClose` to your own Tag when it needs a close button (see the demo, which calls it from the Tag's `onClose`)
1042
+ - In multiple mode, empty content from either snippet leaves the tag out
1043
+
1044
+ ```svelte
1045
+ <script lang="ts">
1046
+ import { Tag, TreeSelect, type TreeNodeData } from '@fibrae/semi-ui-svelte';
1047
+
1048
+ const treeData: TreeNodeData[] = [
1049
+ {
1050
+ label: '亚洲',
1051
+ value: 'Asia',
1052
+ key: '0',
1053
+ children: [
1054
+ {
1055
+ label: '中国',
1056
+ value: 'China',
1057
+ key: '0-0',
1058
+ children: [
1059
+ {
1060
+ label: '北京',
1061
+ value: 'Beijing',
1062
+ key: '0-0-0',
1063
+ },
1064
+ {
1065
+ label: '上海',
1066
+ value: 'Shanghai',
1067
+ key: '0-0-1',
1068
+ },
1069
+ ],
1070
+ },
1071
+ ],
1072
+ },
1073
+ {
1074
+ label: '北美洲',
1075
+ value: 'North America',
1076
+ key: '1',
1077
+ },
1078
+ {
1079
+ label: '南美洲',
1080
+ value: 'South America',
1081
+ key: '2',
1082
+ },
1083
+ {
1084
+ label: '南极洲',
1085
+ value: 'Antarctica',
1086
+ key: '3',
1087
+ },
1088
+ ];
1089
+ </script>
1090
+
1091
+ <h4>单选</h4>
1092
+ <TreeSelect style="width: 300px" {treeData}>
1093
+ {#snippet selectedItem(selected)}
1094
+ {selected.item.label}
1095
+ {/snippet}
1096
+ </TreeSelect>
1097
+ <h4>多选 + 标签内渲染</h4>
1098
+ <TreeSelect multiple style="width: 300px" {treeData}>
1099
+ {#snippet selectedItem(selected)}
1100
+ {selected.item.label}
1101
+ {/snippet}
1102
+ </TreeSelect>
1103
+ <h4>多选 + 替换整个标签</h4>
1104
+ <TreeSelect maxTagCount={2} multiple style="width: 300px" {treeData}>
1105
+ {#snippet tag(selected)}
1106
+ <Tag closable color="white" onClose={selected.onClose}>{selected.item.value}</Tag>
1107
+ {/snippet}
1108
+ </TreeSelect>
1109
+ ```
1110
+
1111
+ ## API Reference
1112
+
1113
+ ### TreeSelect
1114
+
1115
+ **Props**
1116
+
1117
+ | Property | Description | Type | Default |
1118
+ | - | - | - | - |
1119
+ | arrowIcon | Snippet for the dropdown arrow icon on the right; `null` shows no arrow. With `showClear` on and a value selected, hovering shows the clear icon first. | `Snippet \| null` | - |
1120
+ | autoAdjustOverflow | Whether the popup flips its direction automatically when it is covered. | `boolean` | `true` |
1121
+ | autoExpandParent | Whether parent nodes expand automatically. | `boolean` | `false` |
1122
+ | autoMergeValue | Whether to merge the value: when on, selecting a parent node keeps its descendants out of the value. Works only when `leafOnly` is false. | `boolean` | `true` |
1123
+ | borderless | Whether to use the borderless style. | `boolean` | `false` |
1124
+ | checkRelation | In multiple mode, the relationship between the checked states of nodes: `related` or `unRelated`. With `unRelated`, the checked states of nodes do not affect each other. | `CheckRelation` | `"related"` |
1125
+ | classNames | Class names of the inner parts, keyed by dropdown (the dropdown panel) and optionList (the option list, the role="tree" element); values take anything class takes (string, array or object) and merge with the built-in classes. | `Partial<Record<TreeSelectPart, ClassValue>>` | - |
1126
+ | clearIcon | Snippet for the icon of the clear button, effective when `showClear` is true. | `Snippet` | - |
1127
+ | clickToHide | Whether the dropdown closes automatically after a selection; only works in single mode. | `boolean` | `true` |
1128
+ | clickTriggerToHide | When the panel is open, whether clicking the trigger closes it. | `boolean` | `true` |
1129
+ | defaultExpandAll | Whether to expand all nodes on initialization. After `treeData` changes this prop no longer takes effect; use `expandAll` if you need that. | `boolean` | `false` |
1130
+ | defaultOpen | Whether the dropdown is open on mount. TreeSelect has no controlled open state; call `close()` to close it. | `boolean` | `false` |
1131
+ | disabled | Whether the component is disabled. | `boolean` | - |
1132
+ | disableStrictly | Strict disabling: when a node is disabled, its checked state cannot be changed through its parent or child nodes. | `boolean` | `false` |
1133
+ | dropdownMatchSelectWidth | Whether the minimum width of the dropdown panel matches the width of the select box. | `boolean` | `true` |
1134
+ | emptyContent | Snippet for the empty state shown when there is no data or the search finds no result. Without it the locale text is shown; `null` hides it. | `Snippet \| null` | - |
1135
+ | expandAction | How a node expands: `false` (only the expand icon expands it), `click` or `doubleClick`. | `TreeSelectExpandAction` | `false` |
1136
+ | expandAll | Whether to expand all nodes by default. The expansion still follows this prop after `treeData` changes. | `boolean` | `false` |
1137
+ | expandedKeys | Keys of the expanded nodes, supports `bind:expandedKeys`; their direct children are displayed. Left out, the component manages them; for fully controlled expansion use the function binding `bind:expandedKeys={get, set}`. There is no defaultExpandedKeys. | `string[]` | - |
1138
+ | expandIcon | Snippet for the expand icon, receiving `class`, `onClick` and `expanded`; usage is the same as the `expandIcon` of Tree. A single element gets the switcher class and the expand click from the component. | `Snippet<[TreeExpandIconSnippetProps]>` | - |
1139
+ | filterTreeNode | Whether the component is searchable, or a function that customizes the search; its third argument is the node data `data`. | `boolean \| ((inputValue: string, treeNodeString: string, data?: TreeNodeData) => boolean)` | `false` |
1140
+ | fullLabel | Snippet for the content of a whole row, still wrapped in the row element that carries the `id`, `role="treeitem"` and the state attributes; usage is the same as the `fullLabel` of Tree. | `Snippet<[TreeFullLabelSnippetProps]>` | - |
1141
+ | icon | Snippet for a node's icon, receiving `{ item, level, expanded, isLeaf, loading, selected, checked, halfChecked }`; usage is the same as the `icon` of Tree. | `Snippet<[TreeIconSnippetProps]>` | - |
1142
+ | insetLabel | Snippet for a label inside the select box, which also names the dropdown tree. It is not rendered, and does not name the component, when `prefix` is used. | `Snippet` | - |
1143
+ | insetLabelId | The id of the element around `insetLabel`, for `aria-labelledby` to point at. | `string` | - |
1144
+ | keyMaps | Custom names of the key, label, value, disabled, children, isLeaf and icon fields in a node. If you rename the label field and enable search, set `treeNodeFilterProp` to one of the fields in `treeData`, or pass a custom search function to `filterTreeNode`. | `TreeSelectKeyMapProps` | - |
1145
+ | label | Snippet for a node's label, receiving `{ item, label, searchWord }`: the node data, the original label and the search word; usage is the same as the `label` of Tree. | `Snippet<[TreeLabelSnippetProps]>` | - |
1146
+ | labelEllipsis | Whether labels are truncated with an ellipsis on overflow. Without it, it is true when virtualized and false otherwise. | `boolean` | - |
1147
+ | leafOnly | In multiple mode, whether only leaf nodes are displayed as tags, and the values passed to `onChange` are leaf nodes only. | `boolean` | `false` |
1148
+ | loadData | Loads child nodes asynchronously and returns a Promise. Mark leaf nodes with `isLeaf` in `treeData`. | `(data: TreeNodeData) => Promise<void>` | - |
1149
+ | loadedKeys | Keys of the nodes that have finished loading, supports `bind:loadedKeys`, used together with `loadData`. | `string[]` | - |
1150
+ | maxTagCount | Maximum number of tags displayed; the rest are shown as +N. | `number` | - |
1151
+ | motion | Whether the dropdown animates in and out. | `boolean` | `true` |
1152
+ | motionExpand | Whether expanding and collapsing nodes animates. | `boolean` | `true` |
1153
+ | multiple | Whether several nodes can be selected. | `boolean` | `false` |
1154
+ | onBlur | Called when the TreeSelect loses focus, once after each onFocus. Focus leaving the trigger and the dropdown passes a native FocusEvent, a click outside a native MouseEvent, and selecting a node that closes the dropdown the click or key event of that selection. | `(event: MouseEvent \| KeyboardEvent \| FocusEvent) => void` | - |
1155
+ | onChange | Called when the selected value changes, with the value of the node (an array in multiple mode), the node data and the event. The event is null when a tag is closed and a KeyboardEvent when a node is selected from the keyboard; clearing a single selection passes `undefined`. With `onChangeWithObject` set to true, the value and the node are both the node data. | `(value: TreeSelectValue \| undefined, node: TreeNodeData \| TreeNodeData[] \| undefined, event: TreeSelectChangeEvent) => void` | - |
1156
+ | onChangeWithObject | Whether `value` and the arguments of `onChange` carry all properties of the node. When true, the value and the node in `value` and `onChange` are both the node data. | `boolean` | `false` |
1157
+ | onClear | Called when the clear button is clicked. | `(event: TreeSelectChangeEvent) => void` | - |
1158
+ | onExpand | Called when a node expands or collapses, with the array of expanded keys and `{ expanded, node }`. | `(expandedKeys: string[], info: { expanded: boolean; node: TreeNodeData }) => void` | - |
1159
+ | onFocus | Called when focus enters the trigger (including its search input and clear button) or the dropdown from outside, with the native FocusEvent; moving focus among them does not call it again. Opening again with a click or key after a selection closed the dropdown also calls it, with that click or key event, and the focus `searchAutoFocus` gives on mount passes null. | `(event: MouseEvent \| KeyboardEvent \| FocusEvent \| null) => void` | - |
1160
+ | onLoad | Called when a node has finished loading. | `(loadedKeys: Set<string>, node: TreeNodeData) => void` | - |
1161
+ | onSearch | Called when the search value changes, with the search value, `filteredExpandedKeys` (keys of the nodes expanded by the search or by the value, useful when the expansion is controlled) and `filteredNodes` (the nodes that match the search). | `(input: string, filteredExpandedKeys: string[], filteredNodes: TreeNodeData[]) => void` | - |
1162
+ | onSelect | Called when a node is selected or deselected, with the key of the node, whether it is selected, and the node data. | `(selectedKey: string, selected: boolean, node: TreeNodeData) => void` | - |
1163
+ | onVisibleChange | Called when the dropdown panel is shown or hidden, with whether it is visible. | `(visible: boolean) => void` | - |
1164
+ | outerBottomSlot | Snippet rendered at the bottom of the dropdown panel, at the same level as the option list. | `Snippet` | - |
1165
+ | outerTopSlot | Snippet rendered at the top of the dropdown panel, at the same level as the option list. With `filterTreeNode` on, it replaces the search box; to customize the search, use the `search` method through `bind:this`. | `Snippet` | - |
1166
+ | placeholder | Placeholder of the input box. | `string` | - |
1167
+ | position | Position of the popup; the values follow the position of Tooltip. Defaults to `bottomLeft` (`bottomRight` in RTL). | `Position` | - |
1168
+ | prefix | Snippet for the content in front of the select box. | `Snippet` | - |
1169
+ | preventScroll | Whether the browser avoids scrolling the document to show the newly focused element when the component calls `focus` internally. It does not apply to elements passed in by the user. | `boolean` | - |
1170
+ | remote | Whether remote search is enabled. When enabled, input skips local filtering and only triggers `onSearch`; the caller fetches the data and updates `treeData`. | `boolean` | `false` |
1171
+ | restTagsPopoverProps | Popover configuration for the collapsed tags beyond `maxTagCount`. | `PopoverProps` | - |
1172
+ | search | Snippet that replaces the search box. Its parameters carry the ARIA attributes (`aria-activedescendant`, `aria-controls`, `aria-autocomplete`, the name; the whole combobox set while the search box is in the trigger), `class`, `value`, `placeholder`, `showClear`, `onChange(value)` and so on; spread them with `{...props}` onto a Semi Input. `false` renders no search box, while `filterTreeNode` still filters. | `Snippet<[TreeSelectSearchSnippetProps]> \| false` | - |
1173
+ | searchAutoFocus | Whether the search box is focused on mount. | `boolean` | `false` |
1174
+ | searchPlaceholder | Placeholder of the search box in the dropdown. | `string` | - |
1175
+ | searchPosition | Position of the search box: `dropdown` or `trigger`. | `TreeSelectSearchPosition` | `"dropdown"` |
1176
+ | selectedItem | Snippet for the selected items, receiving `{ item, index, disabled, onClose }`. In single mode its content is what the select box shows, and `placeholder` shows when it is empty; in multiple mode its content goes into the built-in Tag, and an empty content renders no tag. `onClose` removes the tag, or clears the single selection. | `Snippet<[TreeSelectSelectedItemSnippetProps]>` | - |
1177
+ | showClear | Whether the trigger shows the clear button when the value is not empty. | `boolean` | `false` |
1178
+ | showFilteredOnly | Whether only the filtered results are displayed while searching. | `boolean` | `false` |
1179
+ | showLine | Whether the nodes in the option panel show connecting lines. | `boolean` | `false` |
1180
+ | showRestTagsPopover | When the number of tags exceeds `maxTagCount`, whether hovering +N shows the remaining tags in a Popover. | `boolean` | `false` |
1181
+ | showSearchClear | Whether the search box in the dropdown can be cleared. | `boolean` | `true` |
1182
+ | size | Size of the input box: `large`, `small` or `default`. | `TreeSelectSize` | - |
1183
+ | stopPropagation | Whether click events on the dropdown panel stop bubbling. | `boolean \| string` | `true` |
1184
+ | styles | Style strings of the inner parts, keyed like classNames. | `Partial<Record<TreeSelectPart, string>>` | - |
1185
+ | suffix | Snippet for the content after the select box. | `Snippet` | - |
1186
+ | tag | Snippet that replaces each tag in multiple mode, with the same parameters as `selectedItem` and ahead of it. To get a close button, wire `onClose` to your own Tag. | `Snippet<[TreeSelectSelectedItemSnippetProps]>` | - |
1187
+ | treeData | Node data; keys are unique across the tree. Only a new array updates the options, changes made in place are not seen. | `TreeNodeData[]` | `[]` |
1188
+ | treeNodeFilterProp | Property of `TreeNodeData` matched by search. | `string` | `"label"` |
1189
+ | treeNodeLabelProp | Property of `TreeNodeData` used to display the text. | `string` | `"label"` |
1190
+ | trigger | Snippet that replaces the trigger content. Its parameters are `value` (the data of the selected nodes), `inputValue`, `placeholder`, `disabled`, `componentProps` (all the props given to TreeSelect), `onSearch` (updates the search keyword; needs `filterTreeNode` and a `searchPosition` of `trigger`), `onClear` (pass the click event when bound to a control inside the trigger, so the click does not open the dropdown) and `onRemove` (unchecks the node with the key). | `Snippet<[TreeSelectTriggerSnippetProps]>` | - |
1191
+ | triggerTagWrap | Whether selected tags wrap onto multiple lines within the trigger. Only works when `multiple` and search are enabled and `searchPosition` is `trigger`. | `boolean` | `false` |
1192
+ | validateStatus | Validation status: `warning`, `error` or `default`. It only affects the background color of the component. | `ValidateStatus` | - |
1193
+ | value | The selected value, supports `bind:value`; an array in multiple mode. Left out, the component manages it; a one-way `value={x}` only seeds it, and for a fully controlled select use the function binding `bind:value={get, set}`. Binding it to `undefined` clears the selection. There is no defaultValue. | `TreeSelectValue` | - |
1194
+ | virtualize | Virtual list configuration: an object with `itemSize` (required, the height of each row), `height` (the height of the dropdown, a number recommended) and `width`. Animation is disabled when virtualized. | `TreeVirtualize` | - |
1195
+
1196
+ **Methods**
1197
+
1198
+ | Method | Description | Type |
1199
+ | - | - | - |
1200
+ | close | Closes the dropdown. | `() => void` |
1201
+ | search | Searches as if the value were typed, opening the dropdown first. Needs `filterTreeNode`. | `(input: string) => void` |
1202
+
1203
+ The Svelte TreeSelect has no `className` property: `class` (a string, an array or an object), `style` (a string), `data-*` and other undeclared attributes and event handlers (such as `onclick`) land on the root element (the trigger), and `onkeydown` is called after the component has handled the key. `aria-label`, `aria-labelledby`, `aria-describedby`, `aria-errormessage`, `aria-invalid` and `aria-required` land on the current combobox (see [ARIA](#aria)). The lowercase `onchange`, `onselect`, `onload`, `onfocus` and `onblur` are not passed through as native listeners; use the callbacks `onChange`, `onSelect`, `onLoad`, `onFocus` and `onBlur`. Each value of `styles` is a style string. `value`, `expandedKeys` and `loadedKeys` are bindable, and there is no `defaultValue` or `defaultExpandedKeys`; the default of `multiple` can be set through the global defaults.
1204
+
1205
+ ### TreeNodeData
1206
+
1207
+ > **Key for `TreeNodeData` is required and must be unique**, `label` can be duplicated. Value is not required. In this case, the value property in `bind:value`, `onChange` and `onChangeWithObject` will point to key property. To ensure everything behave as expected, keep a consistency of whether to have value or not to have value.
1208
+
1209
+ | Properties | Instructions | type | Default |
1210
+ | - | - | - | - |
1211
+ | value | Value | string\|number | - |
1212
+ | label | Displayed label; use the `label` snippet for custom content | string\|number | - |
1213
+ | disabled | Disabled, supported in multiple select mode | boolean | false |
1214
+ | key | Required and must be unique | string | - |
1215
+ | isLeaf | Whether it is a leaf node | boolean | - |
1216
+ | children | Child nodes | TreeNodeData\[] | - |
1217
+
1218
+ The icon of a node comes from the `icon` snippet and is not declared in the data.
1219
+
1220
+ ## Methods
1221
+
1222
+ TreeSelect exposes the `search(value)` and `close()` methods through `bind:this`, typed as `TreeSelectHandle`. `search` searches as if the value were typed, opening the dropdown first, and filterTreeNode must be set; `close` closes the dropdown. If you need to customize the search box externally, call `search` when the value of the custom search box changes to change the filtering results.
1223
+
1224
+ ```svelte
1225
+ <script lang="ts">
1226
+ import { TreeSelect, type TreeSelectHandle } from '@fibrae/semi-ui-svelte';
1227
+
1228
+ let treeSelect = $state<TreeSelectHandle>();
1229
+ </script>
1230
+
1231
+ <TreeSelect bind:this={treeSelect} filterTreeNode {treeData} />
1232
+ <button onclick={() => treeSelect?.close()}>Close</button>
1233
+ ```
1234
+
1235
+ ## Accessibility
1236
+
1237
+ ### ARIA
1238
+
1239
+ - Following the ARIA 1.2 combobox pattern, exactly one element is the combobox. Its name comes from, in order of priority: `aria-labelledby`, `aria-label`, the rendered insetLabel (`#insetLabel` in Vue; without `insetLabelId` the component generates the id; with a prefix the insetLabel is not rendered and does not name it), and otherwise the name in the locale:
1240
+ - Without search, or with `searchPosition="dropdown"`, the trigger is a select-only combobox. The search input in the dropdown stays a text box with `aria-controls`, `aria-autocomplete` and `aria-activedescendant`
1241
+ - With `searchPosition="trigger"`, the search input is the combobox and the only Tab stop, with `aria-autocomplete="list"`; the trigger has no role. In single mode the input is empty until the user types, so the selected text is linked to it as its description (`aria-describedby`). Clicking anywhere on the trigger moves focus to the input;
1242
+ - TreeSelect allows users to set `aria-describedby`, `aria-errormessage`, `aria-invalid`, `aria-labelledby`, `aria-required`, in addition, Form will automatically set these properties for FormTreeSelect;
1243
+ - The `role="tree"` list in the dropdown uses the same name source as the combobox: the same `aria-labelledby` ids, the same `aria-label` or the same insetLabel; with none of them it takes the name in the locale, like the combobox;
1244
+
1245
+ * `aria-label`, `aria-labelledby`, `aria-describedby`, `aria-errormessage`, `aria-invalid` and `aria-required` land on the current combobox: the root element without search, the native `input` of the search box in a single-choice trigger search, and the tag input in a multi-choice trigger search. With `aria-labelledby` set, the combobox no longer adds the default `aria-label`; with only the `insetLabel` snippet, the combobox's `aria-labelledby` points at it;
1246
+ * The nodes in the dropdown are the same as in [Tree](../navigation/tree.md#accessibility): `role="treeitem"` with `aria-level`, `aria-setsize`, `aria-posinset` and `aria-disabled`, and `aria-expanded` on nodes that can expand; a single-choice TreeSelect uses `aria-selected`, a multi-choice one uses `aria-checked` (`mixed` when half checked). The content of the `fullLabel` snippet is wrapped in an `li` carrying the `id`, `role="treeitem"` and these states;
1247
+
1248
+ - The expand arrow and the checkbox in front of a node only picture its state: they are hidden from screen readers and take no focus.
1249
+
1250
+ ### Keyboard Interaction
1251
+
1252
+ TreeSelect follows the [WAI-ARIA Combobox](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/) pattern with a tree popup: focus always stays on the trigger or the search input, `aria-activedescendant` points at the current node, and the current node shows the focus ring. There is no current node when the dropdown opens.
1253
+
1254
+ - While the dropdown is closed: `ArrowDown`, `ArrowUp`, `Enter` and `Space` open it; `Home` and `End` open it and move to the first or last visible node
1255
+ - `ArrowDown`, `ArrowUp`: move to the next or previous visible node; the first `ArrowDown` moves to the first node; `Home`, `End`: move to the first or last visible node
1256
+ - `ArrowRight`: expand a collapsed node; on an expanded node, move to its first child (swapped with `ArrowLeft` in RTL)
1257
+ - `ArrowLeft`: collapse an expanded node; otherwise move to the parent
1258
+ - `Enter`, `Space`: select the current node, or check and uncheck it in a multi-choice TreeSelect; disabled nodes do not respond
1259
+ - Typing characters: while the dropdown is open, move to the next visible node after the current one whose label starts with the typed text; characters typed in quick succession form one search string. A closed dropdown ignores them
1260
+ - `Esc`: close the dropdown
1261
+
1262
+ While focus is in a search input, only `ArrowDown`, `ArrowUp` and `Enter` move and select; the other keys (including characters, `Space`, `Home`, `End`, `ArrowLeft` and `ArrowRight`) edit the text.
1263
+
1264
+ The parameters of the `search` snippet include these ARIA attributes (`aria-activedescendant`, `aria-controls`, `aria-autocomplete` and the name; on the trigger, the whole set of combobox attributes including `role` and `aria-expanded`); spread the whole parameter object onto a Semi `Input` with `{...props}`, or screen readers do not announce the current node. The component finds the text field inside the rendered snippet to focus it itself, so no ref is needed.
1265
+
1266
+ With `showClear`, a selected value or search text, and no `disabled`, the trigger renders a clear button. It is a native `button` named "Clear TreeSelect value" from the locale, shown on hover, while the dropdown is open, or while focus is inside the TreeSelect. From the trigger or the search input, `Tab` moves to the clear button; `Enter` or `Space` clears, as a mouse click does, and the focus goes back to the trigger or the search input. In multiple mode `Backspace` in the search input also removes tags.
1267
+
1268
+ Demo:
1269
+
1270
+ ```svelte
1271
+ <TreeSelect aria-label="example treeSelect" {treeData} />
1272
+ ```
1273
+
1274
+ ## Design Tokens
1275
+
1276
+ The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/input/tree-select/>
1277
+
1278
+ ## Changes from Semi Design
1279
+
1280
+ From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
1281
+
1282
+ - 破坏性:删除 `dropdownClassName`、`dropdownStyle`、`optionListStyle`,改用 `classNames`、`styles` 的 `dropdown`(下拉面板)、`optionList`(选项列表,原来只能设样式)键。
1283
+ - `expandAction="click"` 加 `loadData` 时,点击 `isLeaf` 节点不再调用 `loadData`。
1284
+ - 行为变化:`searchPosition="dropdown"` 时,焦点在触发器上按 ArrowUp、ArrowDown 不再把焦点送进下拉里的搜索框,React、Vue 与 Solid、Svelte 一致(焦点留在触发器,方向键在树里移动)。
1285
+ - 行为变化:触发器上带 Ctrl、Meta 的按键,以及 Alt 加 ArrowDown、ArrowUp 以外的按键(如 Ctrl+Enter、Alt+Enter)交给浏览器,不再开合下拉、不再 `preventDefault`;Alt+ArrowDown、Alt+ArrowUp 照旧打开下拉(APG combobox),Alt+Tab(Safari 的 Option+Tab)与 Tab 一样处理。
1286
+ - 行为变化:`treeData` 换了引用但结构不变(如每次新建 ReactNode 的 `label`)时,不再重置展开与动画状态,受控 `expandedKeys` 的展开动画照常播放;搜索中 `treeData` 更新时,已收起的节点不会被重新展开;展开动画状态在 `treeData` 结构变化时重置(原来比较键集合)。
1287
+ - 行为变化:受控 `expandedKeys` 变化、搜索展开与 `treeData` 结构变化时的展开动画改由 `motionExpand` 决定,不再受下拉弹出动画 `motion` 影响:`motion={false}` 时这些展开照常有动画,`motionExpand={false}` 时都没有动画。
1288
+ - 破坏性:删除 `getPopupContainer`、`zIndex`、`dropdownMargin`;`dropdownMatchSelectWidth` 让下拉最小宽度跟随触发器的当前宽度(`--semi-tooltip-trigger-width`),`style.width` 不再复制到下拉。删除从未生效的 SCSS 变量 `$font-treeSelect_default-fontSize` 等,`$height-treeSelect_popover`(300px)开始生效。
1289
+ - 破坏性(类型):`TreeSelectProps` 改为泛型 `TreeSelectProps<T, Multiple, WithObject>`,`onChange` 参数随 `multiple` 与 `onChangeWithObject` 区分,`OnChange` 接口改为 `OnChangeArgs`(FormTreeSelect 的行内 `onChange` 参数推断不出来);`onClear` 参数改为 `React.MouseEvent`;删除 `mouseEnterDelay`、`mouseLeaveDelay`;`searchPosition` 收窄为 `'dropdown' | 'trigger'`;`TreeSelectTriggerRenderProps` 删除索引签名。
1290
+ - 破坏性:`onFocus`、`onBlur` 跟随 DOM 焦点,以整个组件(触发器、搜索框、标签、清除按钮与下拉)为界成对触发,Tab 进入也触发 `onFocus`,组件内部移动不触发。`searchRender` 参数新增 `ref` 需写到输入框上,`autofocus` 键改为 `autoFocus`;清除按钮改为带名称的原生 `button`;键盘按 APG combobox,`aria-activedescendant` 指向当前节点。
1291
+ - Solid 破坏性(类型):`treeData` 同 Tree 收紧,`label` 只接受 `string | number`,节点数据不带 `icon`;新增 `icon` 属性(元素或 `(row: TreeRowProps) => JSX.Element`),用法同 Tree 的 `icon`。单选的 `renderSelectedItem` 只在内置触发器显示已选内容时调用,传 `triggerRender` 时不调用。
1292
+ - Svelte:`value`、`expandedKeys`、`loadedKeys` 可绑定,删除 `defaultValue`、`defaultExpandedKeys`,`defaultOpen`、`defaultExpandAll` 保留(没有对应的可绑定 prop);回调同 React:`onChange(value, node, event)`、`onExpand`、`onLoad`、`onSelect`、`onSearch`、`onVisibleChange`、`onFocus`、`onBlur`、`onClear`;`search(value)`、`close()` 经 `bind:this` 调用。
1293
+ - Svelte:插槽改为同名 snippet:`label`、`icon`、`expandIcon`、`fullLabel`、`selectedItem`、`tag`、`trigger`、`search`、`prefix`、`suffix`、`insetLabel`、`arrowIcon`、`clearIcon`、`emptyContent`、`outerTopSlot`、`outerBottomSlot`;`search={false}` 隐藏搜索框但仍过滤,`arrowIcon={null}`、`emptyContent={null}` 隐藏。
1294
+ - 下拉打开时按 Tab 离开会关闭下拉并触发一次 `onBlur`(APG combobox 模式),原来只触发 `onBlur`、下拉保持打开;窗口失焦时下拉保持打开。
1295
+ - Svelte:设置 `trigger` snippet 后根元素不带 `semi-tree-select` 类,只保留传入的 `class`、`style`、`data-*`。
1296
+ - Svelte:`value` 被父级设为 `undefined` 时,选择框清空显示。
1297
+ - `checkRelation="unRelated"` 多选加触发器内搜索时,已有标签后不再带 `tagInput-empty` 类,左侧间距恢复正常。
1298
+ - `expandedKeys={null}`、`loadedKeys={null}` 按受控处理(同 `value={null}`)。
1299
+ - 触发器内的搜索框随 TreeSelect 解析出的 `size`(含 InputGroup 下发的)变化,原来固定为默认尺寸。Svelte 的 `TreeSelectSearchSnippetProps`、Vue 的 `TreeSelectSearchSlotProps` 新增 `size`,只在触发器搜索框上有值。
1300
+ - `removeTag` 在组件 `disabled` 时不再生效,key 找不到节点数据时不再抛错。React、Solid:`checkRelation="unRelated"` 加 `leafOnly` 时按 `realCheckedKeys` 显示全部标签,与 Vue、Svelte 一致(原来过滤掉非叶子键的标签)。