@fibrae/semi-ui-svelte 0.9.0 → 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.
- package/README.md +8 -4
- package/README.zh-CN.md +8 -4
- package/dist/components/anchor/interface.d.ts +14 -0
- package/dist/components/audio-player/interface.d.ts +5 -0
- package/dist/components/auto-complete/interface.d.ts +29 -0
- package/dist/components/avatar/interface.d.ts +24 -0
- package/dist/components/backtop/interface.d.ts +2 -0
- package/dist/components/badge/interface.d.ts +7 -0
- package/dist/components/banner/interface.d.ts +7 -0
- package/dist/components/breadcrumb/interface.d.ts +10 -0
- package/dist/components/button/interface.d.ts +18 -0
- package/dist/components/calendar/interface.d.ts +16 -0
- package/dist/components/card/interface.d.ts +18 -0
- package/dist/components/carousel/interface.d.ts +16 -0
- package/dist/components/cascader/cascader.svelte +1 -0
- package/dist/components/cascader/interface.d.ts +57 -0
- package/dist/components/checkbox/interface.d.ts +19 -0
- package/dist/components/code-highlight/interface.d.ts +3 -0
- package/dist/components/collapse/interface.d.ts +16 -0
- package/dist/components/collapsible/interface.d.ts +10 -0
- package/dist/components/color-picker/interface.d.ts +10 -0
- package/dist/components/config-provider/interface.d.ts +7 -0
- package/dist/components/cropper/interface.d.ts +11 -0
- package/dist/components/date-picker/interface.d.ts +47 -0
- package/dist/components/descriptions/interface.d.ts +6 -0
- package/dist/components/divider/interface.d.ts +4 -0
- package/dist/components/dropdown/interface.d.ts +8 -0
- package/dist/components/empty/interface.d.ts +7 -0
- package/dist/components/feedback/interface.d.ts +16 -0
- package/dist/components/float-button/interface.d.ts +14 -0
- package/dist/components/form/interface.d.ts +47 -0
- package/dist/components/form/label.svelte +2 -2
- package/dist/components/grid/interface.d.ts +13 -0
- package/dist/components/highlight/interface.d.ts +7 -0
- package/dist/components/hot-keys/interface.d.ts +3 -0
- package/dist/components/image/interface.d.ts +59 -0
- package/dist/components/input/interface.d.ts +67 -0
- package/dist/components/input-number/interface.d.ts +24 -0
- package/dist/components/json-viewer/interface.d.ts +7 -0
- package/dist/components/layout/interface.d.ts +3 -0
- package/dist/components/list/interface.d.ts +18 -0
- package/dist/components/locale/interface.d.ts +4 -0
- package/dist/components/lottie/interface.d.ts +2 -0
- package/dist/components/markdown-render/interface.d.ts +5 -0
- package/dist/components/modal/interface.d.ts +29 -0
- package/dist/components/navigation/interface.d.ts +47 -0
- package/dist/components/overflow-list/interface.d.ts +11 -0
- package/dist/components/pagination/interface.d.ts +12 -0
- package/dist/components/pincode/interface.d.ts +8 -0
- package/dist/components/popconfirm/interface.d.ts +12 -0
- package/dist/components/popover/interface.d.ts +30 -0
- package/dist/components/progress/interface.d.ts +13 -0
- package/dist/components/radio/interface.d.ts +22 -0
- package/dist/components/rating/interface.d.ts +12 -0
- package/dist/components/resizable/interface.d.ts +30 -0
- package/dist/components/scroll-list/interface.d.ts +6 -0
- package/dist/components/select/interface.d.ts +63 -0
- package/dist/components/side-sheet/interface.d.ts +19 -0
- package/dist/components/skeleton/interface.d.ts +7 -0
- package/dist/components/slider/interface.d.ts +23 -0
- package/dist/components/space/interface.d.ts +4 -0
- package/dist/components/spin/interface.d.ts +7 -0
- package/dist/components/steps/interface.d.ts +9 -0
- package/dist/components/switch/interface.d.ts +7 -0
- package/dist/components/table/interface.d.ts +48 -0
- package/dist/components/tabs/interface.d.ts +29 -0
- package/dist/components/tag/interface.d.ts +22 -0
- package/dist/components/tag-input/interface.d.ts +29 -0
- package/dist/components/time-picker/interface.d.ts +31 -0
- package/dist/components/timeline/interface.d.ts +5 -0
- package/dist/components/tooltip/interface.d.ts +20 -0
- package/dist/components/tooltip/tooltip.svelte +3 -0
- package/dist/components/transfer/interface.d.ts +18 -0
- package/dist/components/tree/interface.d.ts +45 -0
- package/dist/components/tree-select/interface.d.ts +55 -0
- package/dist/components/typography/interface.d.ts +33 -0
- package/dist/components/upload/interface.d.ts +64 -0
- package/dist/components/user-guide/interface.d.ts +15 -0
- package/dist/components/video-player/interface.d.ts +22 -0
- package/dist/styles.css +1 -1
- package/docs/advanced/dark-mode.md +288 -0
- package/docs/basic/button.md +605 -0
- package/docs/basic/divider.md +103 -0
- package/docs/basic/float-button.md +246 -0
- package/docs/basic/grid.md +427 -0
- package/docs/basic/layout.md +459 -0
- package/docs/basic/resizable.md +584 -0
- package/docs/basic/space.md +163 -0
- package/docs/basic/tokens.md +425 -0
- package/docs/basic/typography.md +615 -0
- package/docs/changes-from-semi.md +105 -0
- package/docs/ecosystem/tailwind.md +210 -0
- package/docs/experience/accessibility.md +82 -0
- package/docs/experience/content-guidelines.md +819 -0
- package/docs/experience/internationalization.md +7 -0
- package/docs/feedback/banner.md +198 -0
- package/docs/feedback/feedback.md +294 -0
- package/docs/feedback/notification.md +401 -0
- package/docs/feedback/popconfirm.md +243 -0
- package/docs/feedback/progress.md +389 -0
- package/docs/feedback/skeleton.md +388 -0
- package/docs/feedback/spin.md +172 -0
- package/docs/feedback/toast.md +393 -0
- package/docs/input/auto-complete.md +399 -0
- package/docs/input/cascader.md +1558 -0
- package/docs/input/checkbox.md +408 -0
- package/docs/input/color-picker.md +175 -0
- package/docs/input/date-picker.md +942 -0
- package/docs/input/form.md +2550 -0
- package/docs/input/input-number.md +451 -0
- package/docs/input/input.md +640 -0
- package/docs/input/pincode.md +191 -0
- package/docs/input/radio.md +337 -0
- package/docs/input/rating.md +214 -0
- package/docs/input/select.md +1230 -0
- package/docs/input/slider.md +347 -0
- package/docs/input/switch.md +206 -0
- package/docs/input/tag-input.md +465 -0
- package/docs/input/time-picker.md +358 -0
- package/docs/input/transfer.md +1061 -0
- package/docs/input/tree-select.md +1300 -0
- package/docs/input/upload.md +1811 -0
- package/docs/llms.txt +147 -0
- package/docs/navigation/anchor.md +377 -0
- package/docs/navigation/backtop.md +100 -0
- package/docs/navigation/breadcrumb.md +284 -0
- package/docs/navigation/navigation.md +851 -0
- package/docs/navigation/pagination.md +217 -0
- package/docs/navigation/steps.md +315 -0
- package/docs/navigation/tabs.md +754 -0
- package/docs/navigation/tree.md +1956 -0
- package/docs/other/config-provider.md +599 -0
- package/docs/other/locale.md +353 -0
- package/docs/plus/audio-player.md +155 -0
- package/docs/plus/code-highlight.md +150 -0
- package/docs/plus/drag-move.md +214 -0
- package/docs/plus/hot-keys.md +174 -0
- package/docs/plus/json-viewer.md +392 -0
- package/docs/plus/lottie.md +176 -0
- package/docs/plus/markdown-render.md +240 -0
- package/docs/plus/video-player.md +325 -0
- package/docs/show/avatar.md +475 -0
- package/docs/show/badge.md +276 -0
- package/docs/show/calendar.md +352 -0
- package/docs/show/card.md +485 -0
- package/docs/show/carousel.md +592 -0
- package/docs/show/collapse.md +289 -0
- package/docs/show/collapsible.md +216 -0
- package/docs/show/cropper.md +285 -0
- package/docs/show/descriptions.md +325 -0
- package/docs/show/dropdown.md +466 -0
- package/docs/show/empty.md +225 -0
- package/docs/show/highlight.md +144 -0
- package/docs/show/image.md +433 -0
- package/docs/show/list.md +927 -0
- package/docs/show/modal.md +517 -0
- package/docs/show/overflow-list.md +272 -0
- package/docs/show/popover.md +534 -0
- package/docs/show/scroll-list.md +156 -0
- package/docs/show/side-sheet.md +274 -0
- package/docs/show/table.md +5437 -0
- package/docs/show/tag.md +428 -0
- package/docs/show/timeline.md +277 -0
- package/docs/show/tooltip.md +442 -0
- package/docs/show/user-guide.md +419 -0
- package/docs/start/getting-started.md +234 -0
- package/docs/start/introduction.md +57 -0
- package/docs/start/overview.md +21 -0
- package/package.json +5 -4
|
@@ -0,0 +1,1230 @@
|
|
|
1
|
+
# Select
|
|
2
|
+
|
|
3
|
+
> The user can select one or more options from a set of options through the Select selector and present the final selection result
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/select/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The Svelte version has no `Select.Option` or `Select.OptGroup`: the data of child components is not available in the first server render, in keyboard navigation, in filtering or in select all. The options come only from `optionList`, and groups are written on the `group` field of an entry.
|
|
18
|
+
|
|
19
|
+
### Basic Usage
|
|
20
|
+
|
|
21
|
+
Write the options in `optionList`. Each entry must declare `value`, and `label` is the text of the option. A one-way `value="video"` only seeds the selection; use `bind:value` to read and write it
|
|
22
|
+
|
|
23
|
+
```svelte
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
26
|
+
|
|
27
|
+
const optionList = [
|
|
28
|
+
{ value: 'video', label: '短视频' },
|
|
29
|
+
{ value: 'camera', label: '相机' },
|
|
30
|
+
{ value: 'editing', label: '剪辑', disabled: true },
|
|
31
|
+
{ value: 'movie', label: '长视频' },
|
|
32
|
+
];
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<Select aria-label="业务线" {optionList} style="width: 120px" value="video" />
|
|
36
|
+
<br />
|
|
37
|
+
<br />
|
|
38
|
+
<Select aria-label="业务线" disabled optionList={optionList.filter((option) => !option.disabled)} style="width: 120px" value="video" />
|
|
39
|
+
<br />
|
|
40
|
+
<br />
|
|
41
|
+
<Select aria-label="业务线" {optionList} placeholder="请选择业务线" style="width: 120px" />
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Pass Option as an array
|
|
45
|
+
|
|
46
|
+
You can pass an array of objects directly through `optionList`. Each object must contain the value / label attribute.
|
|
47
|
+
|
|
48
|
+
`label` accepts a string or a number; option text with markup uses the `optionLabel` snippet, see "Custom Option Render" below.
|
|
49
|
+
|
|
50
|
+
```svelte
|
|
51
|
+
<script lang="ts">
|
|
52
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
53
|
+
|
|
54
|
+
const list = [
|
|
55
|
+
{ value: 'video', label: '短视频', otherKey: 0 },
|
|
56
|
+
{ value: 'camera', label: '相机', disabled: true, otherKey: 1 },
|
|
57
|
+
{ value: 'editing', label: '剪辑', otherKey: 2 },
|
|
58
|
+
{ value: 'news', label: '资讯', otherKey: 3 },
|
|
59
|
+
];
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<Select aria-label="业务线" optionList={list} placeholder="请选择业务线" style="width: 180px" />
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Multi-choice
|
|
66
|
+
|
|
67
|
+
The dropdown list of Select has a default `maxHeight` of 270, and the content can be viewed by scrolling vertically after it exceeds.
|
|
68
|
+
|
|
69
|
+
Configuration `multiple` properties that can support multi-selection
|
|
70
|
+
|
|
71
|
+
Configuration `maxTagCount`. You can limit the number of options displayed, and the excess will be displayed in the form of + N
|
|
72
|
+
|
|
73
|
+
Configure `ellipsisTrigger` to do adaptive processing on the overflow part of the tag. When the width is insufficient, the last tag content will be truncated. After enabling this function, there will be a certain performance loss, and it is not recommended to use it in large form scenarios
|
|
74
|
+
|
|
75
|
+
Configure `expandRestTagsOnClick` to display all remaining tags by clicking when `maxTagCount` is set
|
|
76
|
+
|
|
77
|
+
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
|
|
78
|
+
|
|
79
|
+
Configuration `max` Properties can limit the maximum number of options and cannot be selected beyond the maximum limit, while triggering the `onExceed` callback
|
|
80
|
+
|
|
81
|
+
```svelte
|
|
82
|
+
<script lang="ts">
|
|
83
|
+
import { Select, Toast } from '@fibrae/semi-ui-svelte';
|
|
84
|
+
|
|
85
|
+
const optionList = [
|
|
86
|
+
{ value: 'video', label: '短视频' },
|
|
87
|
+
{ value: 'camera', label: '相机' },
|
|
88
|
+
{ value: 'editing', label: '剪辑' },
|
|
89
|
+
{ value: 'movie', label: '长视频' },
|
|
90
|
+
];
|
|
91
|
+
const onExceed = () => Toast.warning('最多只允许选择两项');
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<Select aria-label="Select 示例" multiple {optionList} style="width: 320px" value={['video', 'camera']} />
|
|
95
|
+
<br />
|
|
96
|
+
<br />
|
|
97
|
+
<Select aria-label="Select 示例" maxTagCount={2} multiple {optionList} restTagsPopoverProps={{ position: 'top' }} showRestTagsPopover style="width: 320px" value={['video', 'camera', 'editing']} />
|
|
98
|
+
<br />
|
|
99
|
+
<br />
|
|
100
|
+
<Select aria-label="Select 示例" max={2} multiple {onExceed} {optionList} style="width: 320px" value={['video']} />
|
|
101
|
+
<br />
|
|
102
|
+
<br />
|
|
103
|
+
<Select aria-label="Select 示例" ellipsisTrigger expandRestTagsOnClick maxTagCount={2} multiple {optionList} restTagsPopoverProps={{ position: 'top' }} showRestTagsPopover style="width: 220px" value={['movie', 'camera', 'editing', 'video']} />
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### With Group
|
|
107
|
+
|
|
108
|
+
Group entries by writing `group: { key, label }` on the `optionList` entries. Entries of one group must be adjacent: adjacent entries with the same `key` form one group, and `label` is the group title; a group without a `label` renders no title. A group renders as `role="group"` named by its title. While searching, a group with no visible option is hidden entirely, and a keyword that matches a group title shows all options of that group. Customize the title with the `groupLabel` snippet, whose parameter is `{ group }`; without it `group.label` is shown. With `virtualize` no group titles or `role="group"` are rendered and the options are laid out flat in order
|
|
109
|
+
|
|
110
|
+
```svelte
|
|
111
|
+
<script lang="ts">
|
|
112
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
113
|
+
|
|
114
|
+
const asia = { key: 'asia', label: 'Asia' };
|
|
115
|
+
const europe = { key: 'europe', label: 'Europe' };
|
|
116
|
+
const southAmerica = { key: 'south-america', label: 'South America' };
|
|
117
|
+
|
|
118
|
+
const optionList = [
|
|
119
|
+
{ value: 'a-1', label: 'China', group: asia },
|
|
120
|
+
{ value: 'a-2', label: 'Korea', group: asia },
|
|
121
|
+
{ value: 'b-1', label: 'Germany', group: europe },
|
|
122
|
+
{ value: 'b-2', label: 'France', group: europe },
|
|
123
|
+
{ value: 'c-1', label: 'Peru', group: southAmerica },
|
|
124
|
+
];
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<Select aria-label="地区" filter {optionList} placeholder="" style="width: 180px" />
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```svelte
|
|
131
|
+
<script lang="ts">
|
|
132
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
133
|
+
|
|
134
|
+
const data = [
|
|
135
|
+
{
|
|
136
|
+
label: 'Asia',
|
|
137
|
+
children: [
|
|
138
|
+
{ value: 'a-1', label: 'China' },
|
|
139
|
+
{ value: 'a-2', label: 'Korea' },
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
label: 'Europe',
|
|
144
|
+
children: [
|
|
145
|
+
{ value: 'b-1', label: 'Germany' },
|
|
146
|
+
{ value: 'b-2', label: 'France' },
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
label: 'South America',
|
|
151
|
+
children: [{ value: 'c-1', label: 'Peru' }],
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
const optionList = data.flatMap(({ label, children }) => children.map((option) => ({ ...option, group: { key: label, label } })));
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<Select aria-label="地区" filter {optionList} placeholder="" style="width: 180px" />
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Different sizes
|
|
162
|
+
|
|
163
|
+
Size: small / default / large
|
|
164
|
+
|
|
165
|
+
```svelte
|
|
166
|
+
<script lang="ts">
|
|
167
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
168
|
+
|
|
169
|
+
const optionList = [{ value: 'camera', label: '相机' }];
|
|
170
|
+
</script>
|
|
171
|
+
|
|
172
|
+
<Select aria-label="small" {optionList} placeholder="请选择业务线" size="small" style="width: 180px" />
|
|
173
|
+
<br />
|
|
174
|
+
<br />
|
|
175
|
+
<Select aria-label="default" {optionList} placeholder="请选择业务线" style="width: 180px" />
|
|
176
|
+
<br />
|
|
177
|
+
<br />
|
|
178
|
+
<Select aria-label="large" {optionList} placeholder="请选择业务线" size="large" style="width: 180px" />
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Different validate status
|
|
182
|
+
|
|
183
|
+
validateStatus: default / warning / error
|
|
184
|
+
|
|
185
|
+
```svelte
|
|
186
|
+
<script lang="ts">
|
|
187
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
188
|
+
|
|
189
|
+
const optionList = [{ value: 'camera', label: '相机' }];
|
|
190
|
+
</script>
|
|
191
|
+
|
|
192
|
+
<Select aria-label="default" {optionList} style="width: 180px" />
|
|
193
|
+
<br />
|
|
194
|
+
<br />
|
|
195
|
+
<Select aria-label="warning" {optionList} style="width: 180px" validateStatus="warning" />
|
|
196
|
+
<br />
|
|
197
|
+
<br />
|
|
198
|
+
<Select aria-label="error" {optionList} style="width: 180px" validateStatus="error" />
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Configure Prefix, Suffix, Clear Button
|
|
202
|
+
|
|
203
|
+
- You can pass the selection box prefix through the `prefix` snippet, the selection box suffix through the `suffix` snippet, for text or a node\
|
|
204
|
+
The left and right padding is automatically brought when the snippet content is text or Icon. If it is a custom node, the left and right padding is 0.
|
|
205
|
+
|
|
206
|
+
* Whether to show the clear button is displayed by `showClear`
|
|
207
|
+
* Whether to show the right drop-down arrow is displayed by `showArrow`
|
|
208
|
+
|
|
209
|
+
```svelte
|
|
210
|
+
<script lang="ts">
|
|
211
|
+
import { IconGift, IconVigoLogo } from '@fibrae/semi-icons-svelte';
|
|
212
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
213
|
+
|
|
214
|
+
const optionList = [
|
|
215
|
+
{ value: 'video', label: '短视频' },
|
|
216
|
+
{ value: 'camera', label: '相机' },
|
|
217
|
+
{ value: 'editing', label: '剪辑' },
|
|
218
|
+
{ value: 'movie', label: '长视频' },
|
|
219
|
+
];
|
|
220
|
+
</script>
|
|
221
|
+
|
|
222
|
+
<Select aria-label="Select 示例" {optionList} showClear style="width: 320px" value="camera">
|
|
223
|
+
{#snippet prefix()}
|
|
224
|
+
<IconVigoLogo />
|
|
225
|
+
{/snippet}
|
|
226
|
+
</Select>
|
|
227
|
+
<br />
|
|
228
|
+
<br />
|
|
229
|
+
<Select aria-label="Select 示例" {optionList} showArrow={false} style="width: 320px" value="camera">
|
|
230
|
+
{#snippet prefix()}
|
|
231
|
+
<IconVigoLogo />
|
|
232
|
+
{/snippet}
|
|
233
|
+
{#snippet suffix()}
|
|
234
|
+
<IconGift />
|
|
235
|
+
{/snippet}
|
|
236
|
+
</Select>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Additional items
|
|
240
|
+
|
|
241
|
+
We have reserved two slots at the bottom of the pop-up layer, which you can use when you need to add a custom node to the pop-up layer.\
|
|
242
|
+
Use`innerTopSlot` or `outerTopSlot` to pass the custom node, which will be rendered at the top of the pop-up layer. Use`innerBottomSlot` or `outerBottomSlot` instead at the bottom.
|
|
243
|
+
|
|
244
|
+
In Svelte they are snippets of the same names, written as `{#snippet innerBottomSlot()}...{/snippet}`, and likewise for the other three.
|
|
245
|
+
|
|
246
|
+
- `innerTopSlot` and `innerBottomSlot` will be rendered inside the Option List
|
|
247
|
+
- `outerTopSlot` and `outerBottomSlot` will be rendered to level with the option List
|
|
248
|
+
|
|
249
|
+
```svelte
|
|
250
|
+
<script lang="ts">
|
|
251
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
252
|
+
|
|
253
|
+
const optionList = [
|
|
254
|
+
{ value: 'video', label: '短视频' },
|
|
255
|
+
{ value: 'camera', label: '相机' },
|
|
256
|
+
{ value: 'editing', label: '剪辑' },
|
|
257
|
+
{ value: 'social', label: '社交' },
|
|
258
|
+
{ value: 'movie', label: '长视频' },
|
|
259
|
+
];
|
|
260
|
+
const innerSlotStyle = 'background-color: var(--color-white); height: 36px; display: flex; align-items: center; cursor: pointer; padding-left: 32px; border-top: 1px solid var(--semi-color-border); border-radius: 0 0 6px 6px; color: var(--semi-color-link)';
|
|
261
|
+
const outSlotStyle = 'background-color: var(--semi-color-fill-0); height: 36px; display: flex; padding-left: 32px; color: var(--semi-color-link); align-items: center; cursor: pointer; border-top: 1px solid var(--semi-color-border); border-radius: 0 0 6px 6px';
|
|
262
|
+
</script>
|
|
263
|
+
|
|
264
|
+
<div>
|
|
265
|
+
<p>outerBottomSlot:</p>
|
|
266
|
+
<Select aria-label="outerBottomSlot" autoAdjustOverflow={false} defaultOpen maxHeight={150} {optionList} placeholder="自定义外侧底部slot,始终显示" position="bottom" style="width: 300px" styles={{ dropdown: 'width: 180px' }}>
|
|
267
|
+
{#snippet outerBottomSlot()}
|
|
268
|
+
<div style={outSlotStyle}>
|
|
269
|
+
<span style="color: var(--semi-color-link)">未找到应用?</span>
|
|
270
|
+
</div>
|
|
271
|
+
{/snippet}
|
|
272
|
+
</Select>
|
|
273
|
+
<p style="margin-top: 200px">innerBottomSlot:</p>
|
|
274
|
+
<Select aria-label="innerBottomSlot" maxHeight={150} {optionList} placeholder="自定义内侧底部slot,滚动至底部显示" style="width: 300px" styles={{ dropdown: 'width: 180px' }}>
|
|
275
|
+
{#snippet innerBottomSlot()}
|
|
276
|
+
<div style={innerSlotStyle}>点击加载更多</div>
|
|
277
|
+
{/snippet}
|
|
278
|
+
</Select>
|
|
279
|
+
</div>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Using outerTopSlot to insert content
|
|
283
|
+
|
|
284
|
+
```svelte
|
|
285
|
+
<script lang="ts">
|
|
286
|
+
import { RadioGroup, Select, type RadioChangeEvent, type SelectValue } from '@fibrae/semi-ui-svelte';
|
|
287
|
+
|
|
288
|
+
interface Item {
|
|
289
|
+
value: string;
|
|
290
|
+
label: string;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const list: Record<string, Item[]> = {
|
|
294
|
+
component: [
|
|
295
|
+
{ value: 'select', label: '选择器' },
|
|
296
|
+
{ value: 'tabs', label: '标签' },
|
|
297
|
+
{ value: 'avatar', label: '头像' },
|
|
298
|
+
{ value: 'button', label: '按钮' },
|
|
299
|
+
],
|
|
300
|
+
design: [
|
|
301
|
+
{ value: 'color', label: '颜色' },
|
|
302
|
+
{ value: 'dark', label: '暗色模式' },
|
|
303
|
+
{ value: 'icon', label: '图标' },
|
|
304
|
+
{ value: 'font', label: '字体' },
|
|
305
|
+
],
|
|
306
|
+
feedback: [
|
|
307
|
+
{ value: 'faq', label: '常见问题' },
|
|
308
|
+
{ value: 'join', label: '加入用户群' },
|
|
309
|
+
{ value: 'hornbill', label: '犀鸟反馈问题' },
|
|
310
|
+
],
|
|
311
|
+
};
|
|
312
|
+
const categoryOptions = [
|
|
313
|
+
{ value: 'component', label: '组件' },
|
|
314
|
+
{ value: 'design', label: '设计' },
|
|
315
|
+
{ value: 'feedback', label: '反馈' },
|
|
316
|
+
];
|
|
317
|
+
|
|
318
|
+
let key = $state('component');
|
|
319
|
+
let value = $state<SelectValue>({ value: 'faq', label: '常见问题' });
|
|
320
|
+
|
|
321
|
+
const changeCategory = (event: RadioChangeEvent) => {
|
|
322
|
+
key = String(event.target.value);
|
|
323
|
+
};
|
|
324
|
+
</script>
|
|
325
|
+
|
|
326
|
+
<Select aria-label="选项" autoAdjustOverflow={false} bind:value defaultOpen onChangeWithObject optionList={list[key]} style="width: 200px">
|
|
327
|
+
{#snippet outerTopSlot()}
|
|
328
|
+
<!-- The radio group switches with arrow keys, so categories need no tabpanel association -->
|
|
329
|
+
<div style="padding: 8px 12px; border-bottom: 0.5px solid var(--semi-color-border)">
|
|
330
|
+
<RadioGroup aria-label="选项分类" buttonSize="small" onChange={changeCategory} options={categoryOptions} type="button" value={key} />
|
|
331
|
+
</div>
|
|
332
|
+
{/snippet}
|
|
333
|
+
</Select>
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Controlled component
|
|
337
|
+
|
|
338
|
+
Use `bind:value={x}` to keep the selected value in sync both ways; with the function binding `bind:value={() => x, (next) => { ... }}` Select is fully controlled and the setter may reject or rewrite the value. A one-way `value={x}` only seeds the selection. There is no `defaultValue`.
|
|
339
|
+
|
|
340
|
+
```svelte
|
|
341
|
+
<script lang="ts">
|
|
342
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
343
|
+
|
|
344
|
+
const optionList = [
|
|
345
|
+
{ value: 'video', label: '短视频' },
|
|
346
|
+
{ value: 'camera', label: '相机' },
|
|
347
|
+
{ value: 'editing', label: '剪辑' },
|
|
348
|
+
{ value: 'movie', label: '长视频' },
|
|
349
|
+
];
|
|
350
|
+
|
|
351
|
+
let value = $state<string | undefined>('movie');
|
|
352
|
+
</script>
|
|
353
|
+
|
|
354
|
+
<Select aria-label="业务线" bind:value {optionList} placeholder="受控的Select" style="width: 300px" />
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Dynamic Modification Options
|
|
358
|
+
|
|
359
|
+
If you need to update Options dynamically, you should use `bind:value`, or write the value back in `onChange`
|
|
360
|
+
|
|
361
|
+
```svelte
|
|
362
|
+
<script lang="ts">
|
|
363
|
+
import { Button, Select } from '@fibrae/semi-ui-svelte';
|
|
364
|
+
|
|
365
|
+
let options = $state([1, 2, 3, 4]);
|
|
366
|
+
|
|
367
|
+
const optionList = $derived(options.map((option) => ({ value: option, label: String(option) })));
|
|
368
|
+
|
|
369
|
+
const add = () => {
|
|
370
|
+
const length = Math.ceil(Math.random() * 10);
|
|
371
|
+
options = Array.from({ length }, (_, i) => i + 1);
|
|
372
|
+
};
|
|
373
|
+
</script>
|
|
374
|
+
|
|
375
|
+
<Select aria-label="数字" {optionList} placeholder="请选择" style="width: 180px" value={4} />
|
|
376
|
+
<br />
|
|
377
|
+
<br />
|
|
378
|
+
<Button onclick={add}>changeOptions Dynamic</Button>
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Linkage Select
|
|
382
|
+
|
|
383
|
+
Use `bind:value`, or write the value back in `onChange`, to link different Selects. If it is a complex linkage with a hierarchical relationship, it is recommended to use Cascader components directly
|
|
384
|
+
|
|
385
|
+
```svelte
|
|
386
|
+
<script lang="ts">
|
|
387
|
+
import { Select, type SelectValue } from '@fibrae/semi-ui-svelte';
|
|
388
|
+
|
|
389
|
+
const provinces = ['四川', '广东'];
|
|
390
|
+
const maps: Record<string, string[]> = {
|
|
391
|
+
四川: ['成都', '都江堰'],
|
|
392
|
+
广东: ['广州', '深圳', '东莞'],
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
let province = $state(provinces[0]);
|
|
396
|
+
let city = $state<string | undefined>(maps[provinces[0]][0]);
|
|
397
|
+
|
|
398
|
+
const provinceList = provinces.map((item) => ({ value: item, label: item }));
|
|
399
|
+
const cityList = $derived(maps[province].map((item) => ({ value: item, label: item })));
|
|
400
|
+
|
|
401
|
+
const provinceChange = (next: SelectValue) => {
|
|
402
|
+
if (typeof next !== 'string') {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
province = next;
|
|
406
|
+
city = maps[next][0];
|
|
407
|
+
};
|
|
408
|
+
</script>
|
|
409
|
+
|
|
410
|
+
<Select aria-label="省份" onChange={provinceChange} optionList={provinceList} style="width: 150px; margin: 10px" value={province} />
|
|
411
|
+
<Select aria-label="城市" bind:value={city} optionList={cityList} style="width: 150px; margin: 10px" />
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Search
|
|
415
|
+
|
|
416
|
+
You can turn on the search capability by setting `filter` to true.\
|
|
417
|
+
The default search strategy will include comparison of the input value with the label value of option
|
|
418
|
+
|
|
419
|
+
By default, the search keywords will be cleared automatically after multiple selection is selected. If you want to keep it, you can turn off the default behavior by setting `autoClearSearchValue` to false
|
|
420
|
+
|
|
421
|
+
```svelte
|
|
422
|
+
<script lang="ts">
|
|
423
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
424
|
+
|
|
425
|
+
const businessList = [
|
|
426
|
+
{ value: 'video', label: '短视频' },
|
|
427
|
+
{ value: 'camera', label: '相机' },
|
|
428
|
+
{ value: 'editing', label: '剪辑' },
|
|
429
|
+
{ value: 'movie', label: '长视频' },
|
|
430
|
+
];
|
|
431
|
+
const semiList = Array.from({ length: 5 }, (_, i) => ({ value: `semi-${i}`, label: `Semi-${i}` }));
|
|
432
|
+
</script>
|
|
433
|
+
|
|
434
|
+
<Select aria-label="单选" filter optionList={businessList} placeholder="带搜索功能的单选" style="width: 180px" />
|
|
435
|
+
<br />
|
|
436
|
+
<br />
|
|
437
|
+
<Select aria-label="多选" autoClearSearchValue={false} filter multiple optionList={semiList} placeholder="带搜索功能的多选" style="width: 300px" />
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Search position
|
|
441
|
+
|
|
442
|
+
The default search input is displayed on the Select Trigger. You can specify different positions through `searchPosition`, and you can choose `dropdown` or `trigger`.\
|
|
443
|
+
If you want to customize the placeholder of the Input search box in the dropdown, you can control it through `searchPlaceholder`\
|
|
444
|
+
If the `searchPosition` is `trigger`, when `showClear=true`, clicking the clear button of the input will clear the selected items and the search text in the input at the same time\
|
|
445
|
+
If the `searchPosition` is `dropdown`, when `showClear=true`, clicking the clear button of the trigger will clear the selected items, clicking the clear button in the dropdown input will clear search text
|
|
446
|
+
|
|
447
|
+
```svelte
|
|
448
|
+
<script lang="ts">
|
|
449
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
450
|
+
|
|
451
|
+
const businessList = [
|
|
452
|
+
{ value: 'video', label: '短视频' },
|
|
453
|
+
{ value: 'camera', label: '相机' },
|
|
454
|
+
{ value: 'editing', label: '剪辑' },
|
|
455
|
+
{ value: 'movie', label: '长视频' },
|
|
456
|
+
];
|
|
457
|
+
const semiList = Array.from({ length: 5 }, (_, i) => ({ value: `semi-${i}`, label: `Semi-${i}` }));
|
|
458
|
+
</script>
|
|
459
|
+
|
|
460
|
+
<Select aria-label="单选" filter optionList={businessList} placeholder="我的搜索框在下拉菜单中" searchPlaceholder="带搜索功能的单选" searchPosition="dropdown" style="width: 200px" value="camera" />
|
|
461
|
+
<br />
|
|
462
|
+
<br />
|
|
463
|
+
<Select aria-label="多选" autoClearSearchValue={false} filter multiple optionList={semiList} placeholder="我的搜索框在下拉菜单中" searchPlaceholder="带搜索功能的多选" searchPosition="dropdown" style="width: 300px" value={['semi-1']} />
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### Remote search
|
|
467
|
+
|
|
468
|
+
A multi-select example with remote search, request debounce, loading status.
|
|
469
|
+
|
|
470
|
+
- Use `filter` turn on the search capability.
|
|
471
|
+
- Use `remote` to disabled local filter
|
|
472
|
+
- Dynamic Update `optionList` after `onSearch` callback
|
|
473
|
+
- Update `loading` when fetching data / finish
|
|
474
|
+
|
|
475
|
+
* Use `bind:value`, and get the keyword from `onSearch`; pass `emptyContent={null}` to hide the empty state
|
|
476
|
+
|
|
477
|
+
```svelte
|
|
478
|
+
<script lang="ts">
|
|
479
|
+
import { debounce } from 'es-toolkit';
|
|
480
|
+
import { Select, type SelectValue } from '@fibrae/semi-ui-svelte';
|
|
481
|
+
|
|
482
|
+
interface Item {
|
|
483
|
+
value: string;
|
|
484
|
+
label: string;
|
|
485
|
+
type: number;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const mockSearch = (inputValue: string): Item[] => {
|
|
489
|
+
const length = Math.ceil(Math.random() * 100);
|
|
490
|
+
return Array.from({ length }, (_v, i) => {
|
|
491
|
+
return { value: inputValue + i, label: `相近业务 ${inputValue}${i}`, type: i + 1 };
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
let loading = $state(false);
|
|
496
|
+
let list = $state<Item[]>([
|
|
497
|
+
{ value: 'video', label: '短视频', type: 1 },
|
|
498
|
+
{ value: 'retouch', label: '修图', type: 2 },
|
|
499
|
+
{ value: 'editing', label: '剪辑', type: 3 },
|
|
500
|
+
{ value: 'news', label: '资讯', type: 4 },
|
|
501
|
+
]);
|
|
502
|
+
let value = $state<SelectValue>([]);
|
|
503
|
+
|
|
504
|
+
const handleSearch = debounce((inputValue: string) => {
|
|
505
|
+
loading = true;
|
|
506
|
+
if (inputValue) {
|
|
507
|
+
const result = mockSearch(inputValue);
|
|
508
|
+
setTimeout(() => {
|
|
509
|
+
loading = false;
|
|
510
|
+
list = result;
|
|
511
|
+
}, 1000);
|
|
512
|
+
} else {
|
|
513
|
+
loading = false;
|
|
514
|
+
}
|
|
515
|
+
}, 1000);
|
|
516
|
+
</script>
|
|
517
|
+
|
|
518
|
+
<Select aria-label="远程搜索" bind:value emptyContent={null} filter {loading} multiple onChangeWithObject onSearch={handleSearch} optionList={list} remote style="width: 300px" />
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
### Custom search strategy
|
|
522
|
+
|
|
523
|
+
By default, the user's search input will be compared with the option's label value as a string include.\
|
|
524
|
+
You can set `filter` as a custom function to customize your filter strategy.
|
|
525
|
+
|
|
526
|
+
```svelte
|
|
527
|
+
<script lang="ts">
|
|
528
|
+
import { Select, type SelectOptionProps } from '@fibrae/semi-ui-svelte';
|
|
529
|
+
|
|
530
|
+
const optionList = [
|
|
531
|
+
{ value: 'video', label: 'video' },
|
|
532
|
+
{ value: 'camera', label: 'LIVE' },
|
|
533
|
+
{ value: 'editing', label: 'COMMUNITY' },
|
|
534
|
+
{ value: 'movie', label: 'MOVIE' },
|
|
535
|
+
];
|
|
536
|
+
|
|
537
|
+
const searchLabel = (sugInput: string, option: SelectOptionProps) => {
|
|
538
|
+
const label = String(option.label).toUpperCase();
|
|
539
|
+
const sug = sugInput.toUpperCase();
|
|
540
|
+
return label.includes(sug);
|
|
541
|
+
};
|
|
542
|
+
</script>
|
|
543
|
+
|
|
544
|
+
<Select aria-label="业务线" filter={searchLabel} {optionList} placeholder="try video" style="width: 180px" />
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
### Custom selection rendering
|
|
548
|
+
|
|
549
|
+
By default, the `label` of the selected option is backfilled into the selection box.\
|
|
550
|
+
But you can customize the rendering of the selection box through snippets, whose parameters are `{ option, index, disabled, onClose }`
|
|
551
|
+
|
|
552
|
+
- `selectedItem`: in a single Select it replaces the content shown in the selection box; in a multiple Select it replaces only the content inside the built-in tag, which keeps its background color and close button
|
|
553
|
+
- `tag`: in a multiple Select it replaces the whole tag, and takes precedence over `selectedItem` when both are given
|
|
554
|
+
- Call `onClose` to remove the option; in a single Select it clears the value
|
|
555
|
+
- Other fields written on the `optionList` entries (such as `email` and `avatar` in the demo) are passed in with `option`
|
|
556
|
+
|
|
557
|
+
```svelte
|
|
558
|
+
<script lang="ts">
|
|
559
|
+
import { Avatar, Select, Tag, type SelectOptionProps, type SelectValue } from '@fibrae/semi-ui-svelte';
|
|
560
|
+
|
|
561
|
+
const optionStyle = 'display: flex; padding-left: 24px; padding-top: 10px; padding-bottom: 10px';
|
|
562
|
+
|
|
563
|
+
const list = [
|
|
564
|
+
{
|
|
565
|
+
name: '夏可漫',
|
|
566
|
+
email: 'xiakeman@example.com',
|
|
567
|
+
avatar: '/assets/placeholder/avatar-a.svg',
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
name: '申悦',
|
|
571
|
+
email: 'shenyue@example.com',
|
|
572
|
+
avatar: '/assets/root-web-sites/bag.jpeg',
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
name: '曲晨一',
|
|
576
|
+
email: 'quchenyi@example.com',
|
|
577
|
+
avatar: '/assets/placeholder/avatar-c.svg',
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
name: '文嘉茂',
|
|
581
|
+
email: 'wenjiamao@example.com',
|
|
582
|
+
avatar: '/assets/root-web-sites/6fbafc2d-e3e6-4cff-a1e2-17709c680624.png',
|
|
583
|
+
},
|
|
584
|
+
].map((item) => ({ ...item, value: item.name, label: item.name, showTick: true, style: optionStyle }));
|
|
585
|
+
|
|
586
|
+
const onChange = (value: SelectValue) => console.log(value);
|
|
587
|
+
</script>
|
|
588
|
+
|
|
589
|
+
{#snippet optionLabel(optionItem: { option: SelectOptionProps })}
|
|
590
|
+
<Avatar alt="" size="small" src={optionItem.option.avatar} />
|
|
591
|
+
<div style="margin-left: 8px">
|
|
592
|
+
<div style="font-size: 14px">{optionItem.option.name}</div>
|
|
593
|
+
<div style="color: var(--color-text-2); font-size: 12px; line-height: 16px; font-weight: normal">
|
|
594
|
+
{optionItem.option.email}
|
|
595
|
+
</div>
|
|
596
|
+
</div>
|
|
597
|
+
{/snippet}
|
|
598
|
+
|
|
599
|
+
<Select aria-label="单选" {onChange} {optionLabel} optionList={list} placeholder="请选择" style="width: 280px; height: 40px" value="申悦">
|
|
600
|
+
{#snippet selectedItem(selected)}
|
|
601
|
+
<div style="display: flex; align-items: center">
|
|
602
|
+
<Avatar alt="" size="small" src={selected.option.avatar} />
|
|
603
|
+
<span style="margin-left: 8px">{selected.option.email}</span>
|
|
604
|
+
</div>
|
|
605
|
+
{/snippet}
|
|
606
|
+
</Select>
|
|
607
|
+
<Select aria-label="多选圆形头像" maxTagCount={2} multiple {onChange} {optionLabel} optionList={list} placeholder="请选择" style="width: 280px; margin-top: 20px" value={['申悦', '曲晨一']}>
|
|
608
|
+
{#snippet tag(tagItem)}
|
|
609
|
+
<Tag avatarShape="circle" avatarSrc={tagItem.option.avatar} closable onClose={tagItem.onClose} size="large">
|
|
610
|
+
{tagItem.option.name}
|
|
611
|
+
</Tag>
|
|
612
|
+
{/snippet}
|
|
613
|
+
</Select>
|
|
614
|
+
<Select aria-label="多选方形头像" maxTagCount={2} multiple {onChange} {optionLabel} optionList={list} placeholder="请选择" style="width: 280px; margin-top: 20px" value={['申悦', '曲晨一']}>
|
|
615
|
+
{#snippet tag(tagItem)}
|
|
616
|
+
<Tag avatarShape="square" avatarSrc={tagItem.option.avatar} closable onClose={tagItem.onClose} size="large">
|
|
617
|
+
{tagItem.option.name}
|
|
618
|
+
</Tag>
|
|
619
|
+
{/snippet}
|
|
620
|
+
</Select>
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
### Custom pop-up layer style
|
|
624
|
+
|
|
625
|
+
You can control the style of the pop-up layer through the `dropdown` key of `classNames` and `styles`\
|
|
626
|
+
For example, when you customize the width of the pop-up layer, you can pass the width through `styles.dropdown`
|
|
627
|
+
|
|
628
|
+
```svelte
|
|
629
|
+
<script lang="ts">
|
|
630
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
631
|
+
|
|
632
|
+
const optionList = [
|
|
633
|
+
{ value: 'video', label: '短视频' },
|
|
634
|
+
{ value: 'camera', label: '相机' },
|
|
635
|
+
{ value: 'editing', label: '剪辑' },
|
|
636
|
+
{ value: 'movie', label: '长视频' },
|
|
637
|
+
];
|
|
638
|
+
</script>
|
|
639
|
+
|
|
640
|
+
<Select aria-label="业务线" classNames={{ dropdown: 'test' }} {optionList} placeholder="自定义弹出层样式的" style="width: 180px" styles={{ dropdown: 'width: 250px' }} />
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
### Get all attribute of selected option
|
|
644
|
+
|
|
645
|
+
By default, through `onChange` you can only get value attribute of selected option.\
|
|
646
|
+
If you need to take other attributes of the selected option, you can use `onChangeWithObject` Properties\
|
|
647
|
+
At this time, the argument of `onChange` will be object, containing various attributes of selected option, eg: `onChange({ value, label, ...rest })`
|
|
648
|
+
|
|
649
|
+
> **Notice**
|
|
650
|
+
>
|
|
651
|
+
> Note that when onChangeWithObject is set to true, 
|
|
652
|
+
>
|
|
653
|
+
> `value`
|
|
654
|
+
>
|
|
655
|
+
>  should also be an object and must have 
|
|
656
|
+
>
|
|
657
|
+
> `value`
|
|
658
|
+
>
|
|
659
|
+
>  and 
|
|
660
|
+
>
|
|
661
|
+
> `label`
|
|
662
|
+
>
|
|
663
|
+
>  keys
|
|
664
|
+
|
|
665
|
+
```svelte
|
|
666
|
+
<script lang="ts">
|
|
667
|
+
import { Select, TextArea, type SelectValue } from '@fibrae/semi-ui-svelte';
|
|
668
|
+
|
|
669
|
+
interface Item {
|
|
670
|
+
value: string;
|
|
671
|
+
label: string;
|
|
672
|
+
type: number;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const list: Item[] = [
|
|
676
|
+
{ value: 'video', label: '短视频', type: 1 },
|
|
677
|
+
{ value: 'camera', label: '相机', type: 2 },
|
|
678
|
+
{ value: 'editing', label: '剪辑', type: 3 },
|
|
679
|
+
{ value: 'news', label: '资讯', type: 4 },
|
|
680
|
+
];
|
|
681
|
+
|
|
682
|
+
let cbValue = $state<SelectValue>();
|
|
683
|
+
let multipleCbValue = $state<SelectValue>();
|
|
684
|
+
|
|
685
|
+
const onChange = (value: SelectValue) => {
|
|
686
|
+
cbValue = value;
|
|
687
|
+
console.log(value);
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
const onMultipleChange = (value: SelectValue) => {
|
|
691
|
+
multipleCbValue = value;
|
|
692
|
+
console.log(value);
|
|
693
|
+
};
|
|
694
|
+
</script>
|
|
695
|
+
|
|
696
|
+
<div>
|
|
697
|
+
<div>
|
|
698
|
+
<Select aria-label="单选" {onChange} onChangeWithObject optionList={list} placeholder="单选" style="width: 150px" value={{ ...list[0] }} />
|
|
699
|
+
<h4 id="select-on-change-with-object-single">onChange回调:</h4>
|
|
700
|
+
<TextArea aria-labelledby="select-on-change-with-object-single" autosize rows={2} style="width: 320px; margin-bottom: 48px" value={JSON.stringify(cbValue)} />
|
|
701
|
+
</div>
|
|
702
|
+
<div>
|
|
703
|
+
<Select aria-label="多选" multiple onChange={onMultipleChange} onChangeWithObject optionList={list} placeholder="多选" style="width: 320px" value={[]} />
|
|
704
|
+
<h4 id="select-on-change-with-object-multiple">onChange回调:</h4>
|
|
705
|
+
<TextArea aria-labelledby="select-on-change-with-object-multiple" autosize style="width: 320px" value={JSON.stringify(multipleCbValue)} />
|
|
706
|
+
</div>
|
|
707
|
+
</div>
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
### Create entries
|
|
711
|
+
|
|
712
|
+
You can create and select entries that do not exist in the options by setting `allowCreate=true`
|
|
713
|
+
|
|
714
|
+
You can customize the content display when creating the label through the `createItem` snippet (note that you need to customize the style, and with virtualization you must apply `style` to the custom element). Its parameter is `{ inputValue, focus, style }`. Without it the locale text for "Create" followed by the input is shown. `onCreate` fires when an option is created
|
|
715
|
+
|
|
716
|
+
In addition, can be used with the `defaultActiveFirstOption` property to automatically select the first item. When you enter directly and press Enter, you can immediately create an Option
|
|
717
|
+
|
|
718
|
+
```svelte
|
|
719
|
+
<script lang="ts">
|
|
720
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
721
|
+
|
|
722
|
+
const optionList = [
|
|
723
|
+
{ value: 'video', label: '短视频' },
|
|
724
|
+
{ value: 'camera', label: '相机' },
|
|
725
|
+
{ value: 'editing', label: '剪辑' },
|
|
726
|
+
{ value: 'news', label: '资讯' },
|
|
727
|
+
];
|
|
728
|
+
</script>
|
|
729
|
+
|
|
730
|
+
<Select allowCreate aria-label="业务线" defaultActiveFirstOption filter multiple onChange={(value) => console.log(value)} {optionList} style="width: 400px" />
|
|
731
|
+
<br />
|
|
732
|
+
<br />
|
|
733
|
+
<Select allowCreate aria-label="业务线" defaultActiveFirstOption filter multiple onChange={(value) => console.log(value)} {optionList} placeholder="With renderCreateItem" style="width: 400px">
|
|
734
|
+
{#snippet createItem(create)}
|
|
735
|
+
<div style={`padding: 10px; ${create.style ?? ''}`}>Create Item:{create.inputValue}</div>
|
|
736
|
+
{/snippet}
|
|
737
|
+
</Select>
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
### Virtualize
|
|
741
|
+
|
|
742
|
+
Turn on list virtualization when passing in `virtualize` to optimize performance when there are a large number of Option nodes virtualize is an object containing the following values:
|
|
743
|
+
|
|
744
|
+
- height: Option list height value, default 270
|
|
745
|
+
- width: Option list width value, default 100%
|
|
746
|
+
- itemSize: The height of each line of Option, must be passed
|
|
747
|
+
|
|
748
|
+
> **Note**
|
|
749
|
+
>
|
|
750
|
+
> When virtualize.height is greater than the default value of 270px, to avoid the double scrollbar issue, you need to set the maxHeight property to the same value as virtualize.height. For example: when setting virtualize.height to 400px, you should also set maxHeight to 400.
|
|
751
|
+
|
|
752
|
+
```svelte
|
|
753
|
+
<script lang="ts">
|
|
754
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
755
|
+
|
|
756
|
+
const options = Array.from({ length: 3000 }, (_, i) => ({ label: `option-${i}`, value: i }));
|
|
757
|
+
const virtualize = {
|
|
758
|
+
height: 270,
|
|
759
|
+
width: '100%',
|
|
760
|
+
itemSize: 36,
|
|
761
|
+
};
|
|
762
|
+
</script>
|
|
763
|
+
|
|
764
|
+
<Select aria-label="virtualize" filter optionList={options} placeholder="拥有3k个Option的Select" style="width: 260px" {virtualize} />
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
### Custom Trigger
|
|
768
|
+
|
|
769
|
+
If the default layout style of the selection box does not meet your needs, you can use the `trigger` snippet to customize the content of the selection box
|
|
770
|
+
|
|
771
|
+
If you want to keep the search and filter ability without rendering the Input structure yourself, you can also set searchPosition='dropdown' to put the default search box in the dropdown list
|
|
772
|
+
|
|
773
|
+
The parameters of `trigger` are as follows
|
|
774
|
+
|
|
775
|
+
```typescript
|
|
776
|
+
interface SelectTriggerSnippetProps {
|
|
777
|
+
value: SelectOptionProps[]; // All currently selected options
|
|
778
|
+
inputValue: string; // The current search keyword
|
|
779
|
+
placeholder?: string; // Select placeholder
|
|
780
|
+
disabled: boolean; // Whether to disable Select
|
|
781
|
+
onSearch: (inputValue: string) => void; // Updates the search keyword. Call it when the value of your custom Input changes, to synchronize the state to the Select internal. filter needs to be set too
|
|
782
|
+
onClear: (event?: MouseEvent) => void; // Clears the selection. When bound to a control inside the trigger, pass the click event so that click does not reopen the dropdown
|
|
783
|
+
onRemove: (option: SelectOptionProps) => void; // Removes a single selected option, which needs at least label and value
|
|
784
|
+
}
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
```svelte
|
|
788
|
+
<script lang="ts">
|
|
789
|
+
import { IconAppCenter, IconChevronDown } from '@fibrae/semi-icons-svelte';
|
|
790
|
+
import { Select, Tag, type SelectValue } from '@fibrae/semi-ui-svelte';
|
|
791
|
+
|
|
792
|
+
let valList = $state<SelectValue>(['video', 'camera']);
|
|
793
|
+
|
|
794
|
+
const list = [
|
|
795
|
+
{ value: 'video', label: '短视频' },
|
|
796
|
+
{ value: 'camera', label: '相机' },
|
|
797
|
+
{ value: 'editing', label: '剪辑' },
|
|
798
|
+
{ value: 'news', label: '资讯' },
|
|
799
|
+
];
|
|
800
|
+
</script>
|
|
801
|
+
|
|
802
|
+
<div>
|
|
803
|
+
<h4>不同背景色的触发器</h4>
|
|
804
|
+
<Select aria-label="不同背景色的触发器" bind:value={valList} filter multiple optionList={list} searchPosition="dropdown" style="width: 240px">
|
|
805
|
+
{#snippet trigger(selectState)}
|
|
806
|
+
<div style="min-width: 112px; background-color: var(--semi-color-primary-light-default); height: 32px; display: flex; align-items: center; padding-left: 12px; border-radius: 3px; color: var(--semi-color-primary)">
|
|
807
|
+
<div style="font-weight: 600; flex-shrink: 0; font-size: 14px">业务线</div>
|
|
808
|
+
<div style="margin: 4px; white-space: nowrap; text-overflow: ellipsis; flex-grow: 1; overflow: hidden">
|
|
809
|
+
{selectState.value.map((item) => item.label).join(' , ')}
|
|
810
|
+
</div>
|
|
811
|
+
<IconAppCenter style="margin-right: 8px; flex-shrink: 0" />
|
|
812
|
+
</div>
|
|
813
|
+
{/snippet}
|
|
814
|
+
</Select>
|
|
815
|
+
<br />
|
|
816
|
+
<br />
|
|
817
|
+
<h4>使用 circle Tag 作为触发器</h4>
|
|
818
|
+
<Select aria-label="circle Tag 触发器" bind:value={valList} filter multiple optionList={list} searchPosition="dropdown" style="width: 240px; margin-top: 20px; outline: 0">
|
|
819
|
+
{#snippet trigger(selectState)}
|
|
820
|
+
<div style="margin: 4px; white-space: nowrap; text-overflow: ellipsis; flex-grow: 1; overflow: hidden; display: flex; align-items: center">
|
|
821
|
+
<Tag color="cyan" shape="circle" size="large">
|
|
822
|
+
{selectState.value.map((item) => item.label).join(' / ')}
|
|
823
|
+
{#snippet suffixIcon()}
|
|
824
|
+
<IconChevronDown />
|
|
825
|
+
{/snippet}
|
|
826
|
+
</Tag>
|
|
827
|
+
</div>
|
|
828
|
+
{/snippet}
|
|
829
|
+
</Select>
|
|
830
|
+
</div>
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
The following is a more complex example: Reusing the drag-and-sort capability of TagInput and adding sorting to Select through a custom trigger.
|
|
834
|
+
|
|
835
|
+
```svelte
|
|
836
|
+
<script lang="ts">
|
|
837
|
+
import { Select, TagInput, type SelectValue } from '@fibrae/semi-ui-svelte';
|
|
838
|
+
|
|
839
|
+
let valList = $state<SelectValue>(['video', 'camera']);
|
|
840
|
+
let inputVal = $state('');
|
|
841
|
+
|
|
842
|
+
const list = [
|
|
843
|
+
{ value: 'video', label: '短视频' },
|
|
844
|
+
{ value: 'camera', label: '相机' },
|
|
845
|
+
{ value: 'editing', label: '剪辑' },
|
|
846
|
+
{ value: 'news', label: '资讯' },
|
|
847
|
+
];
|
|
848
|
+
|
|
849
|
+
const handleSort = (currentLabels: string[]) => {
|
|
850
|
+
valList = currentLabels.flatMap((item) => list.find((i) => i.label === item)?.value ?? []);
|
|
851
|
+
};
|
|
852
|
+
</script>
|
|
853
|
+
|
|
854
|
+
<h4>可对已选项拖拽重新排序的 Select</h4>
|
|
855
|
+
<Select aria-label="可拖拽排序的 Select" bind:value={valList} filter multiple optionList={list} style="width: 240px">
|
|
856
|
+
{#snippet trigger(selectState)}
|
|
857
|
+
<div role="presentation" onkeydown={(event) => event.stopPropagation()}>
|
|
858
|
+
<TagInput
|
|
859
|
+
allowDuplicates={false}
|
|
860
|
+
draggable
|
|
861
|
+
inputValue={inputVal}
|
|
862
|
+
onChange={handleSort}
|
|
863
|
+
onInputChange={(word) => {
|
|
864
|
+
selectState.onSearch(word);
|
|
865
|
+
inputVal = word;
|
|
866
|
+
}}
|
|
867
|
+
showClear
|
|
868
|
+
value={selectState.value.map((item) => String(item.label))}
|
|
869
|
+
/>
|
|
870
|
+
</div>
|
|
871
|
+
{/snippet}
|
|
872
|
+
</Select>
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
### Custom Option Render
|
|
876
|
+
|
|
877
|
+
- Simple customization: Use the `optionLabel` snippet to replace only the text inside an option row; its parameter is `{ option }`. The tick icon, the `role="option"` of the row, its selected and disabled states, and its click and keyboard behavior stay the same, and the content automatically brings styles such as padding, background color, etc. The `label` of the option is still used for search, for the trigger text and for the accessible name; the content of `optionLabel` does not highlight the search keyword
|
|
878
|
+
- Complete customization: Through the `optionItem` snippet, you can completely take over the rendering of the candidates in the list, and get the relevant state values from the snippet parameters. Achieve a higher degree of freedom of structural rendering\
|
|
879
|
+
The parameters are `{ id, value, label, selected, focused, disabled, inputValue, class, style, onclick, onmouseenter }` plus any other fields written on the `optionList` entry. Notice:
|
|
880
|
+
1. The `style` in the parameters needs to be consumed on wrapper dom, otherwise it will not be able to be used normally in virtualization scenarios
|
|
881
|
+
2. The `class` and `onmouseenter` in the parameters need to be bound on the wrapper dom, otherwise the display will be problematic when the upper and lower keyboards are operated
|
|
882
|
+
3. The styles of selected, focused, disabled, etc. state need to be added by yourself, and you can get the relative boolean value from the parameters
|
|
883
|
+
4. Bind the `onclick` in the parameters to the wrapper dom so that a click selects the option
|
|
884
|
+
5. Put the `id` in the parameters on the wrapper dom with `role="option"`, `aria-selected` and `aria-disabled`: the Select points `aria-activedescendant` at that id, so screen readers announce the option reached with the arrow keys; Select also uses this id to scroll the option into view when the dropdown opens or the arrow keys move
|
|
885
|
+
|
|
886
|
+
```svelte
|
|
887
|
+
<script lang="ts">
|
|
888
|
+
import { Checkbox, Highlight, Select, type SelectOptionItemSnippetProps } from '@fibrae/semi-ui-svelte';
|
|
889
|
+
|
|
890
|
+
let inputValue = $state('');
|
|
891
|
+
|
|
892
|
+
const optionList = [
|
|
893
|
+
{ value: 'video', label: '短视频', otherKey: 0 },
|
|
894
|
+
{ value: 'camera', label: '相机', disabled: true, otherKey: 1 },
|
|
895
|
+
{ value: 'editing', label: '剪辑', otherKey: 2 },
|
|
896
|
+
{ value: 'news', label: '资讯', otherKey: 3 },
|
|
897
|
+
];
|
|
898
|
+
</script>
|
|
899
|
+
|
|
900
|
+
<!--
|
|
901
|
+
Put style on the outer DOM or the virtual list breaks; add selected/focused/disabled styles from the snippet
|
|
902
|
+
params; bind onmouseenter and class on the outer DOM or arrow keys display wrongly; put id there so screen
|
|
903
|
+
readers announce the option the arrow keys reach
|
|
904
|
+
-->
|
|
905
|
+
{#snippet optionItem(item: SelectOptionItemSnippetProps)}
|
|
906
|
+
<div
|
|
907
|
+
aria-disabled={item.disabled}
|
|
908
|
+
aria-selected={item.selected}
|
|
909
|
+
class={[
|
|
910
|
+
'custom-option-render',
|
|
911
|
+
{
|
|
912
|
+
'custom-option-render-focused': item.focused,
|
|
913
|
+
'custom-option-render-disabled': item.disabled,
|
|
914
|
+
'custom-option-render-selected': item.selected,
|
|
915
|
+
},
|
|
916
|
+
item.class,
|
|
917
|
+
]}
|
|
918
|
+
id={item.id}
|
|
919
|
+
role="option"
|
|
920
|
+
style={item.style}
|
|
921
|
+
onclick={item.onclick}
|
|
922
|
+
onmouseenter={item.onmouseenter}
|
|
923
|
+
>
|
|
924
|
+
<Checkbox checked={item.selected} />
|
|
925
|
+
<div class="option-right">
|
|
926
|
+
<Highlight searchWords={[inputValue]} sourceString={String(item.label)} />
|
|
927
|
+
</div>
|
|
928
|
+
</div>
|
|
929
|
+
{/snippet}
|
|
930
|
+
|
|
931
|
+
<Select aria-label="单选" classNames={{ dropdown: 'components-select-demo-renderOptionItem' }} filter onSearch={(value) => (inputValue = value)} {optionItem} {optionList} placeholder="单选" style="width: 180px" />
|
|
932
|
+
<br />
|
|
933
|
+
<br />
|
|
934
|
+
<Select aria-label="多选" classNames={{ dropdown: 'components-select-demo-renderOptionItem' }} filter multiple onSearch={(value) => (inputValue = value)} {optionItem} {optionList} placeholder="多选" style="width: 320px" />
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
```scss
|
|
938
|
+
.components-select-demo-renderOptionItem {
|
|
939
|
+
.custom-option-render {
|
|
940
|
+
display: flex;
|
|
941
|
+
font-size: 14px;
|
|
942
|
+
line-height: 20px;
|
|
943
|
+
word-break: break-all;
|
|
944
|
+
padding-left: 12px;
|
|
945
|
+
padding-right: 12px;
|
|
946
|
+
padding-top: 8px;
|
|
947
|
+
padding-bottom: 8px;
|
|
948
|
+
color: var(--semi-color-text-0);
|
|
949
|
+
position: relative;
|
|
950
|
+
display: flex;
|
|
951
|
+
align-items: center;
|
|
952
|
+
cursor: pointer;
|
|
953
|
+
box-sizing: border-box;
|
|
954
|
+
.option-right {
|
|
955
|
+
margin-left: 8px;
|
|
956
|
+
display: inline-flex;
|
|
957
|
+
align-items: center;
|
|
958
|
+
}
|
|
959
|
+
&:active {
|
|
960
|
+
background-color: var(--semi-color-fill-1);
|
|
961
|
+
}
|
|
962
|
+
&-focused {
|
|
963
|
+
background-color: var(--semi-color-fill-0);
|
|
964
|
+
}
|
|
965
|
+
&-selected {
|
|
966
|
+
//font-weight: 700;
|
|
967
|
+
}
|
|
968
|
+
&-disabled {
|
|
969
|
+
color: var(--semi-color-disabled-text);
|
|
970
|
+
cursor: not-allowed;
|
|
971
|
+
}
|
|
972
|
+
&:first-of-type {
|
|
973
|
+
margin-top: 4px;
|
|
974
|
+
}
|
|
975
|
+
&:last-of-type {
|
|
976
|
+
margin-bottom: 4px;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
```
|
|
981
|
+
|
|
982
|
+
## API reference
|
|
983
|
+
|
|
984
|
+
### Select Props
|
|
985
|
+
|
|
986
|
+
**Props**
|
|
987
|
+
|
|
988
|
+
| Property | Description | Type | Default |
|
|
989
|
+
| - | - | - | - |
|
|
990
|
+
| allowCreate | Whether options that are not in the list can be created; use it with `filter`. | `boolean` | `false` |
|
|
991
|
+
| arrowIcon | Custom dropdown arrow, a snippet. | `Snippet` | - |
|
|
992
|
+
| autoAdjustOverflow | Whether the dropdown layer flips automatically when it overflows the viewport. | `boolean` | `true` |
|
|
993
|
+
| autoClearSearchValue | Whether the search keyword is cleared after an option is selected in multiple mode. | `boolean` | `true` |
|
|
994
|
+
| autofocus | Whether to focus on mount. | `boolean` | `false` |
|
|
995
|
+
| borderless | Whether the trigger has no border. | `boolean` | `false` |
|
|
996
|
+
| classNames | Class names of the inner parts, keyed by dropdown (the dropdown layer); values take anything class takes (string, array or object) and merge with the built-in classes. | `Partial<Record<SelectPart, ClassValue>>` | - |
|
|
997
|
+
| clearIcon | Custom clear button icon, a snippet. | `Snippet` | - |
|
|
998
|
+
| clickToHide | Whether the dropdown list closes after an option is clicked in multiple mode. | `boolean` | `false` |
|
|
999
|
+
| createItem | Content of the row that creates an option, a snippet with `{ inputValue, focus, style }`; with virtualization apply `style` to the custom element. | `Snippet<[SelectCreateItemSnippetProps]>` | - |
|
|
1000
|
+
| defaultActiveFirstOption | Whether the first enabled option is highlighted by default. | `boolean` | `true` |
|
|
1001
|
+
| defaultOpen | Whether the dropdown list opens on mount. Select has no controlled open state. | `boolean` | `false` |
|
|
1002
|
+
| disabled | Whether the component is disabled. | `boolean` | - |
|
|
1003
|
+
| dropdownMatchSelectWidth | Whether the minimum width of the dropdown layer follows the trigger width. | `boolean` | `true` |
|
|
1004
|
+
| ellipsisTrigger | Whether overflowing tags adapt: when the width is short the last tag is truncated. It has a performance cost and is not recommended in large forms. | `boolean` | `false` |
|
|
1005
|
+
| emptyContent | Content when there are no options, a snippet; `null` hides the empty state. | `Snippet \| null` | - |
|
|
1006
|
+
| expandRestTagsOnClick | With `maxTagCount`, whether the collapsed tags expand while the dropdown list is open. | `boolean` | `false` |
|
|
1007
|
+
| filter | Whether to enable search. true compares the input case-insensitively with the option label or the group title; a function customizes the match. | `boolean \| ((inputValue: string, option: SelectOptionProps) => boolean)` | `false` |
|
|
1008
|
+
| groupLabel | Replaces the content of a group title, a snippet with `{ group }` (`key` and `label`); without it `group.label` is shown. | `Snippet<[SelectGroupLabelSnippetProps]>` | - |
|
|
1009
|
+
| id | id of the trigger; the option ids derive from it. | `string` | - |
|
|
1010
|
+
| innerBottomSlot | Content inside the bottom of the option list, a snippet; visible when the list is scrolled to the bottom. | `Snippet` | - |
|
|
1011
|
+
| innerTopSlot | Content inside the top of the option list, a snippet; visible when the list is scrolled to the top. | `Snippet` | - |
|
|
1012
|
+
| inputProps | Extra props of the search Input; `class` and `style` land on the Input wrapper. | `SelectInputProps` | - |
|
|
1013
|
+
| insetLabel | Inset label, a snippet. Rendered without a `prefix`, and the name source of the combobox. | `Snippet` | - |
|
|
1014
|
+
| insetLabelId | id of the inset label container, for aria-labelledby; when left out and `insetLabel` is rendered, one is generated. | `string` | - |
|
|
1015
|
+
| loading | Whether the options are loading; the dropdown list shows a spinner instead of the options. | `boolean` | `false` |
|
|
1016
|
+
| max | Maximum number of selected options in multiple mode; `onExceed` fires beyond it. | `number` | - |
|
|
1017
|
+
| maxHeight | Maximum height of the dropdown list. | `string \| number` | `270` |
|
|
1018
|
+
| maxTagCount | Maximum number of tags shown in multiple mode; the rest are shown as +N. | `number` | - |
|
|
1019
|
+
| motion | Whether the dropdown layer animates. | `boolean` | `true` |
|
|
1020
|
+
| multiple | Whether multiple options can be selected. | `boolean` | `false` |
|
|
1021
|
+
| onBlur | Called once when the focus leaves the Select; a press outside the open dropdown passes its mousedown event. | `(event: FocusEvent \| MouseEvent) => void` | - |
|
|
1022
|
+
| onChange | Called when the selection changes, with the new value (option objects with `onChangeWithObject`). | `(value: SelectValue) => void` | - |
|
|
1023
|
+
| onChangeWithObject | Whether `onChange` and `value` carry option objects instead of option values. | `boolean` | `false` |
|
|
1024
|
+
| onClear | Called when the clear button is clicked. | `() => void` | - |
|
|
1025
|
+
| onCreate | Called when an option is created. | `(option: SelectOptionProps) => void` | - |
|
|
1026
|
+
| onDeselect | Called when an option is deselected in multiple mode. | `(value: string \| number \| boolean, option: SelectOptionProps) => void` | - |
|
|
1027
|
+
| onDropdownVisibleChange | Called when the dropdown list opens or closes. | `(visible: boolean) => void` | - |
|
|
1028
|
+
| onExceed | Called when the selection would exceed `max`. | `(option: SelectOptionProps) => void` | - |
|
|
1029
|
+
| onFocus | Called once when the focus enters the Select. | `(event: FocusEvent) => void` | - |
|
|
1030
|
+
| onListScroll | Called when the dropdown list scrolls. | `(event: Event) => void` | - |
|
|
1031
|
+
| onSearch | Called when the search keyword changes; there is no event when it comes from `search()` or the `onSearch` of the `trigger` snippet. | `(value: string, event?: Event) => void` | - |
|
|
1032
|
+
| onSelect | Called when an option is selected. | `(value: string \| number \| boolean, option: SelectOptionProps) => void` | - |
|
|
1033
|
+
| optionItem | Replaces a whole option row, a snippet. Its parameter has `id`, `value`, `label`, `selected`, `focused`, `disabled`, `inputValue`, `class`, `style`, `onclick`, `onmouseenter` and the other fields of the entry. Put `id` on the element with `role="option"`. | `Snippet<[SelectOptionItemSnippetProps]>` | - |
|
|
1034
|
+
| optionLabel | Replaces only the text inside an option row, a snippet with `{ option }`. The tick icon, the `role="option"` of the row, its states and keyboard behavior stay; `label` still serves search and the accessible name, and the search keyword is not highlighted in the content. | `Snippet<[SelectOptionLabelSnippetProps]>` | - |
|
|
1035
|
+
| optionList | The option data. An entry has `value`, `label`, `disabled`, `showTick`, `class`, `style` and an optional `group: { key, label }`; other fields travel with the option record. Entries of one group must be adjacent. | `SelectOptionProps[]` | - |
|
|
1036
|
+
| outerBottomSlot | Content at the bottom of the dropdown layer, level with the option list, a snippet; always visible while the list scrolls. | `Snippet` | - |
|
|
1037
|
+
| outerTopSlot | Content at the top of the dropdown layer, level with the option list, a snippet; always visible while the list scrolls. | `Snippet` | - |
|
|
1038
|
+
| placeholder | Placeholder while nothing is selected. | `string` | - |
|
|
1039
|
+
| position | Placement of the dropdown layer relative to the trigger. | `Position` | - |
|
|
1040
|
+
| prefix | Prefix of the selection box, a snippet. The side padding is added when the content is text or an Icon. | `Snippet` | - |
|
|
1041
|
+
| preventScroll | Whether focusing stops the browser from scrolling the element into view. | `boolean` | - |
|
|
1042
|
+
| remote | Whether the search is remote. When on, the options are not filtered locally and the caller updates `optionList`. | `boolean` | `false` |
|
|
1043
|
+
| restTagsPopoverProps | Popover props of the +N popover. | `PopoverProps` | - |
|
|
1044
|
+
| searchPlaceholder | Placeholder of the search input when it is in the dropdown list (`searchPosition="dropdown"`). | `string` | - |
|
|
1045
|
+
| searchPosition | Where the search input sits: `trigger` or `dropdown`. | `'dropdown' \| 'trigger'` | `"trigger"` |
|
|
1046
|
+
| selectedItem | The selected content, a snippet with `{ option, index, disabled, onClose }`. In single mode it replaces the selection box content, in multiple mode the content of each tag. | `Snippet<[SelectSelectedItemSnippetProps]>` | - |
|
|
1047
|
+
| showArrow | Whether to show the dropdown arrow. | `boolean` | `true` |
|
|
1048
|
+
| showClear | Whether to show the clear button. | `boolean` | `false` |
|
|
1049
|
+
| showRestTagsPopover | Whether hovering +N shows the remaining tags in a Popover once `maxTagCount` is exceeded. | `boolean` | `false` |
|
|
1050
|
+
| size | Size: `small`, `default` or `large`. | `SelectSize` | - |
|
|
1051
|
+
| spacing | Gap between the dropdown layer and the trigger. | `number \| { x: number; y: number }` | - |
|
|
1052
|
+
| stopPropagation | Whether clicks inside the dropdown layer are stopped from bubbling out. | `boolean` | `true` |
|
|
1053
|
+
| styles | Style strings of the inner parts, keyed like classNames. | `Partial<Record<SelectPart, string>>` | - |
|
|
1054
|
+
| suffix | Suffix of the selection box, a snippet. The side padding is added when the content is text or an Icon. | `Snippet` | - |
|
|
1055
|
+
| tag | Replaces each tag in multiple mode, a snippet with the parameters of `selectedItem`; it takes precedence over `selectedItem`. | `Snippet<[SelectSelectedItemSnippetProps]>` | - |
|
|
1056
|
+
| trigger | Replaces the trigger content, a snippet with `{ value, inputValue, placeholder, disabled, onSearch, onClear, onRemove }`. | `Snippet<[SelectTriggerSnippetProps]>` | - |
|
|
1057
|
+
| validateStatus | Validation status: `default`, `warning` or `error`; it only affects styles such as the background color. | `ValidateStatus` | - |
|
|
1058
|
+
| value | The selected value, supports `bind:value`. A single value in single mode, an array in multiple mode, and option objects with `onChangeWithObject`. 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. | `SelectValue` | - |
|
|
1059
|
+
| virtualize | Turns on list virtualization; `itemSize` is required. Group titles and `role="group"` are not rendered with it, and the options are laid out flat in order. | `SelectVirtualize` | - |
|
|
1060
|
+
|
|
1061
|
+
**Methods**
|
|
1062
|
+
|
|
1063
|
+
| Method | Description | Type |
|
|
1064
|
+
| - | - | - |
|
|
1065
|
+
| clearInput | Clears the value of the search input. | `() => void` |
|
|
1066
|
+
| close | Closes the dropdown list. | `() => void` |
|
|
1067
|
+
| deselectAll | Clears all selected options. | `() => void` |
|
|
1068
|
+
| focus | Focuses the trigger, or the search input with the dropdown list opened when searchable. | `() => void` |
|
|
1069
|
+
| open | Opens the dropdown list. | `() => void` |
|
|
1070
|
+
| rePosition | Recomputes the dropdown position from the trigger's current position at once; rarely needed. | `() => void` |
|
|
1071
|
+
| search | Searches as if the keyword were typed into the search input. | `(keyword: string, event?: Event) => void` |
|
|
1072
|
+
| selectAll | Selects every shown, enabled option; multiple mode only. | `() => void` |
|
|
1073
|
+
|
|
1074
|
+
`class`, `style`, `data-*` and native attributes and listeners land on the root element, and `style` does not reach the dropdown popup (use `styles.dropdown`); with `trigger` the root no longer carries the style classes of Select itself. `aria-label`, `aria-labelledby`, `aria-describedby`, `aria-errormessage`, `aria-invalid` and `aria-required` land on the combobox; once the search input is mounted it is the combobox, and these attributes move to it.
|
|
1075
|
+
|
|
1076
|
+
### Option Props
|
|
1077
|
+
|
|
1078
|
+
> **An option is identified by its value, which should not repeat within one Select; labels may repeat**
|
|
1079
|
+
|
|
1080
|
+
The Svelte version has no `Select.Option` child component: an option is an `optionList` entry, with the fields below. `class`, `style` and `data-*` land on the option row; other fields never reach the DOM and travel with the option record to `onSelect`, `onDeselect`, `selectedItem`, `tag`, `optionItem` and `optionLabel`, and to `onChange` once `onChangeWithObject` is on.
|
|
1081
|
+
|
|
1082
|
+
| Field | Instructions | Type | Default |
|
|
1083
|
+
| - | - | - | - |
|
|
1084
|
+
| value | The value of the option, which identifies it | string \| number | - |
|
|
1085
|
+
| label | The text of the option, used for display, search and callbacks | string \| number | - |
|
|
1086
|
+
| disabled | Whether the option is disabled | boolean | false |
|
|
1087
|
+
| showTick | Whether to show the tick icon when selected | boolean | true |
|
|
1088
|
+
| group | The group of the option; entries of one group must be adjacent, and a group without a `label` renders no title | `{ key: string \| number; label?: string \| number }` | - |
|
|
1089
|
+
| class | Class of the option row | ClassValue | - |
|
|
1090
|
+
| style | Style of the option row, a string | string | - |
|
|
1091
|
+
|
|
1092
|
+
### OptGroup Props
|
|
1093
|
+
|
|
1094
|
+
The Svelte version has no `Select.OptGroup`: groups are written on the `group` field of the `optionList` entries (see "With Group" above), and the group title is customized with the `groupLabel` snippet. The title element carries `x-semi-prop="groupLabel"`.
|
|
1095
|
+
|
|
1096
|
+
## Methods
|
|
1097
|
+
|
|
1098
|
+
Get the component instance of Select through `bind:this` and call the methods below:
|
|
1099
|
+
|
|
1100
|
+
| Method | Instructions |
|
|
1101
|
+
| - | - |
|
|
1102
|
+
| open() | Manually open dropdown list |
|
|
1103
|
+
| close() | Manually close dropdown list |
|
|
1104
|
+
| focus() | Manually focus: a searchable Select focuses the search input and opens the dropdown list, otherwise it focuses the trigger without opening |
|
|
1105
|
+
| clearInput() | Manually clear value of the search input |
|
|
1106
|
+
| selectAll() | Select every shown, enabled option; multiple mode only |
|
|
1107
|
+
| deselectAll() | Manually clear selected options |
|
|
1108
|
+
| search(value: string, event?: Event) | Searches as if the value were typed into the search input, and the value is set to the input; without an event, the second parameter of `onSearch` is undefined |
|
|
1109
|
+
| rePosition() | Recomputes the dropdown position from the trigger's current position at once; the dropdown already follows scrolling, window resizing, trigger moves and size changes of the trigger or list, so this is rarely needed; following a trigger move lands a frame late, so call this to align within the same frame |
|
|
1110
|
+
|
|
1111
|
+
```svelte
|
|
1112
|
+
<script lang="ts">
|
|
1113
|
+
import { Select } from '@fibrae/semi-ui-svelte';
|
|
1114
|
+
|
|
1115
|
+
let select = $state<Select>();
|
|
1116
|
+
</script>
|
|
1117
|
+
|
|
1118
|
+
<Select bind:this={select} />
|
|
1119
|
+
<button onclick={() => select?.open()}>Open</button>
|
|
1120
|
+
```
|
|
1121
|
+
|
|
1122
|
+
## Accessibility
|
|
1123
|
+
|
|
1124
|
+
### ARIA
|
|
1125
|
+
|
|
1126
|
+
- Following the ARIA 1.2 combobox pattern, exactly one element is the combobox at any time; the popup layer is a listbox and each option an option:
|
|
1127
|
+
- Without search, or with the search input in the dropdown (`searchPosition="dropdown"`), the Select trigger is a select-only combobox and the selected content is its value
|
|
1128
|
+
- With the search input in the trigger, the input itself is the combobox, with `aria-autocomplete="list"`, and the trigger has no role and no Tab stop. In single mode the input appears only while searching, so the trigger is the combobox otherwise; the input is empty until the user types, so the selected text is linked to it as its description with `aria-describedby`. In multiple mode the input is always there
|
|
1129
|
+
- A search input in the dropdown stays a text box with `aria-controls`, `aria-autocomplete` and `aria-activedescendant`, named like the combobox
|
|
1130
|
+
- The combobox takes its name from, in order: `aria-labelledby`, `aria-label`, the rendered insetLabel (the combobox's `aria-labelledby` points at it, with an id the component generates when `insetLabelId` is not given; with a prefix the insetLabel is not rendered and does not name it), and otherwise "Select" from the locale. Pass a name that matches the form label. The listbox and a search input in the dropdown use the same name source, never the combobox itself. The selected content is the value of the combobox and is not part of the name
|
|
1131
|
+
- The combobox has aria-haspopup, aria-expanded, and aria-controls properties, indicating its relationship with the popup layer
|
|
1132
|
+
- When multiple selections are made, listbox aria-multiselectable is true, indicating that multiple selections are currently available
|
|
1133
|
+
- aria-selected is true when Option is selected; aria-disabled is true when Option is disabled
|
|
1134
|
+
- The options of a group with a label (`Select.OptGroup`, or `group` of `optionList` in Svelte) sit in a `role="group"` named by the group title (`aria-labelledby`), so screen readers announce the group of an option; a virtualized list shows no group titles and has no groups
|
|
1135
|
+
- While the dropdown is open, aria-activedescendant points at the option focused from the keyboard, which ensures that it is recognized when the narration is spoken; with a fully custom option rendering, put the `id` from the parameters on the option element (for more information, please refer to [Managing Focus in Composites Using aria-activedescendant](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_focus_activedescendant))
|
|
1136
|
+
|
|
1137
|
+
### Keyboard and Focus
|
|
1138
|
+
|
|
1139
|
+
**Select without Filter, or with the search box in the dropdown (`searchPosition="dropdown"`):**
|
|
1140
|
+
|
|
1141
|
+
- After Select is focused, keyboard users can open the dropdown menu with `Space`, `Up Arrow`, `Down Arrow` (including `Alt` + `Down Arrow`) or `Enter`. With a selected value the focus goes to the first selected option, so pressing Enter right away keeps the value; without one the current highlight stays, starting on the first enabled option (`defaultActiveFirstOption` defaults to true)
|
|
1142
|
+
- `Home` and `End` open the dropdown menu and move the focus to the first and the last enabled option
|
|
1143
|
+
- Typing a character opens the dropdown menu and moves the focus to the next option that starts with it; characters typed in quick succession match as a whole, and typing the same character again cycles through the options that start with it
|
|
1144
|
+
- When the dropdown menu is open:
|
|
1145
|
+
- Use `Esc` key or `Tab` key to close the menu
|
|
1146
|
+
- Use `Up Arrow` or `Down Arrow` to toggle options, `Home` and `End` to move to either end, and a typed character to move to an option that starts with it
|
|
1147
|
+
- `Enter` or `Space` selects the focused option: a single Select selects it and collapses the panel, a multiple Select toggles it and stays open. While characters are being typed in quick succession, `Space` joins the search string instead of selecting. With the focus in the search box inside the dropdown, `Home`, `End`, `Space` and characters edit the search text without moving the option focus
|
|
1148
|
+
- In a multiple Select with the focus on a selected tag, keys act on the tag only: `Backspace` and `Delete` remove it, and `Enter` and `Space` neither open the dropdown menu nor change the value
|
|
1149
|
+
- When the focus is on the dropdown menu and the user uses an `innerBottomSlot` or `outerBottomSlot` attribute with a custom slot with an interactive element:
|
|
1150
|
+
- You can use the `Tab` key to switch to these interactive elements
|
|
1151
|
+
- When the focus is on the first interactive element of the custom slot, use `Shift` + `Tab` to return the focus to the Select box
|
|
1152
|
+
|
|
1153
|
+
**Select with Filter function:**
|
|
1154
|
+
|
|
1155
|
+
- When Select is focused, keyboard users can open dropdown menus with `Up Arrow` or `Down Arrow` or `Enter` keys. At this point, the focus is still on the Select box, the user can enter content, and can also use the `up arrow` or `down arrow` to switch options
|
|
1156
|
+
- When the dropdown menu is open: `Up Arrow` and `Down Arrow` switch options; `Enter` selects the focused option, collapsing the panel in a single Select and toggling it while staying open in a multiple Select; `Esc` or `Tab` closes the menu. `Home`, `End`, `Space` and characters belong to the input in the Select box and edit the search text without moving the option focus
|
|
1157
|
+
- A single Select shows no input in the Select box once the dropdown menu is closed, so `Space`, `Home`, `End` and characters work as in a Select without filter: they open the dropdown menu and move the option focus
|
|
1158
|
+
- When the focus is on the Select box, and the user uses an `innerBottomSlot` or `outerBottomSlot` property with a custom slot with an interactive element:
|
|
1159
|
+
- You can use the `Tab` key to switch to these interactive elements
|
|
1160
|
+
- When the focus is on the first interactive element of the custom slot, use `Shift` + `Tab` to return the focus to the Select box
|
|
1161
|
+
|
|
1162
|
+
**Clear button:**
|
|
1163
|
+
|
|
1164
|
+
- With `showClear`, a selected value or search text, and no `disabled`, the trigger renders a clear button. It is a native `button` named "Clear selection" from the locale, shown on hover, while the dropdown is open, or while focus is inside the Select
|
|
1165
|
+
- From the Select box, `Tab` moves to the clear button; `Enter` or `Space` clears, as a mouse click does, and the focus goes back to the Select box
|
|
1166
|
+
|
|
1167
|
+
## Content Guidelines
|
|
1168
|
+
|
|
1169
|
+
- Selector trigger
|
|
1170
|
+
- Describe in 1-3 words the input that the user needs to make
|
|
1171
|
+
- Use statement writing conventions (first letter uppercase, rest lowercase)
|
|
1172
|
+
- Avoid punctuation and prepositions ("the", "an", "a")
|
|
1173
|
+
- Labels need to be independent statements. Don't let the label be the first half of the statement and the option the second half of the statement.
|
|
1174
|
+
- Use descriptive sentences, not indicative ones. Help text is available under the select box if the option needs more explanation.
|
|
1175
|
+
- Selector options
|
|
1176
|
+
- If there is no default option, use "Select" as placeholder copy
|
|
1177
|
+
- Options should be in alphabetical order or other logical order to make it easier for users to find options
|
|
1178
|
+
- Use statement writing conventions (first letter uppercase, rest lowercase), avoid commas and semicolons at the end of sentences
|
|
1179
|
+
- Clearly articulate the purpose of the choice indicated by the option
|
|
1180
|
+
|
|
1181
|
+
## Design Tokens
|
|
1182
|
+
|
|
1183
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/input/select/>
|
|
1184
|
+
|
|
1185
|
+
## TypeScript Generic Support
|
|
1186
|
+
|
|
1187
|
+
## FAQ
|
|
1188
|
+
|
|
1189
|
+
- **Searchable Select, using remote data to dynamically update the `optionList`, why sometimes there is no data before the asynchronous request is completed?**\
|
|
1190
|
+
Please check whether `remote` is turned on. If remote is not turned on, the input value of the input box will be compared with the current optionList by default. If there is no match, no data will be displayed.\
|
|
1191
|
+
You can turn off matching filtering on the current local data by turning on remote.
|
|
1192
|
+
|
|
1193
|
+
- **Will Select automatically limit the width of the drop-down menu?**\
|
|
1194
|
+
MinWidth will be given, but width will not be written dead. If necessary, you can add it yourself through styles.dropdown.
|
|
1195
|
+
|
|
1196
|
+
- **Why is the blur event not fired after a radio selection option?**
|
|
1197
|
+
|
|
1198
|
+
Select supports A11y, so it does not trigger Select's blur event after a radio selection. In single-selection selection, the Select floating layer is closed, and the focus is still on the trigger (at this time, the Select floating layer can be opened again by pressing the Enter key) No matter single selection or multiple selection, press Esc, only the Select floating layer is closed, and the trigger keeps the focus (the Select floating layer can be opened again by pressing the Enter key at this time)
|
|
1199
|
+
|
|
1200
|
+
## Changes from Semi Design
|
|
1201
|
+
|
|
1202
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
1203
|
+
|
|
1204
|
+
- 破坏性:OverflowList 删除 `wrapperClassName`、`wrapperStyle`,改用 `classNames.wrapper`、`styles.wrapper`,落在滚动容器上。
|
|
1205
|
+
- 破坏性:Select 删除 `dropdownClassName`、`dropdownStyle`,改用 `classNames.dropdown`、`styles.dropdown`,落在弹出层元素上。
|
|
1206
|
+
- Select 开启 `ellipsisTrigger` 的多选可搜索时,打开后搜索框留在标签所在行、紧跟最后一个标签(原来折叠区占满整行,光标换到下一行),放不下时由标签折叠让出位置。
|
|
1207
|
+
- 行为变化:Select、AutoComplete、Cascader、TreeSelect、DatePicker、TimePicker 的触发器与输入框不再处理带 Ctrl、Meta 的按键,以及 Alt 加 ArrowDown、ArrowUp 以外的按键(原来 Ctrl+ArrowDown 会打开、Ctrl+Enter 会选中),这些组合键交给浏览器与系统;Alt+ArrowDown、Alt+ArrowUp 仍作为开合键,Alt+Tab(Safari 的 Option+Tab)与 Tab 一样处理,可搜索模式下 Ctrl+A、Ctrl+C 等编辑快捷键照常工作。
|
|
1208
|
+
- 行为变化:Select 打开时按 Tab 关闭下拉,焦点移到触发器之后的可聚焦元素,Shift+Tab 反向;下拉里有可聚焦元素时也不再先进入下拉。焦点已在下拉内时,Tab 同样关闭并移到触发器之后,Shift+Tab 关闭并回到触发器。
|
|
1209
|
+
- TreeSelect 关闭时清空搜索值、开启 `insetInput` 的 DatePicker 关闭时恢复触发框可用,改在离场动画结束后执行。
|
|
1210
|
+
- 破坏性:`Select.Option`、`Select.OptGroup` 改用静态 `elementType` 识别,删除 `isSelectOption`、`isSelectOptionGroup`;不再读取未声明的 `open`,改用 `defaultOpen`;删除 `getPopupContainer`、`zIndex`、`dropdownMargin`、`rePosKey`、`selectMethod`。
|
|
1211
|
+
- 破坏性(类型):`SelectProps`、`Select` 的泛型改为 `<V, Multiple, WithObject>`(React、Vue、Solid):`V` 是选项 value 的类型,约束为 `SelectRawValue`(`string | number | boolean`),优先从 `optionList` 推断(内联选项推断为字面量联合),选项写在子元素或插槽里时由 `value` 推断;`Multiple` 跟随 `multiple`,`WithObject` 跟随 `onChangeWithObject`(Vue 为 `changeWithObject`)。`onChange` 收到 `V | undefined`、`V[]`,对象模式下为 `OptionProps<V>`;`onSelect`、`onDeselect` 收到原始值 `V` 与 `OptionProps<V>`;`value`、`defaultValue` 按 `V` 的基础类型检查。原来用 `SelectProps<Item>` 表示对象模式的改为 `SelectProps<string, undefined, true>`,多选显式写 `Select<V, true>`;删除 `BasicSelectValue`,新增导出 `SelectRawValue`、`SelectChangeValue`。`allowCreate` 配内联字面量选项时,新建的值不在 `V` 里,需显式写 `Select<string>`。`onBlur` 参数为 `React.FocusEvent<HTMLElement> | MouseEvent`。
|
|
1212
|
+
- 选项 value 支持布尔值(四个框架),`onChange`、`onSelect` 收到原始的 `true`、`false`。
|
|
1213
|
+
- 破坏性(类型):Select 删除 `mouseEnterDelay`、`mouseLeaveDelay`、`TriggerRenderProps.onChange`(改用 `onSearch`),`searchPosition` 收窄为 `'trigger' | 'dropdown'`,`virtualize.itemSize` 必填;`OverflowListProps` 不再包含 `children`,改为泛型 `<T>`,scroll 模式 `overflowRenderer` 为 `(overflowItems: [T[], T[]]) => [ReactNode, ReactNode]`。
|
|
1214
|
+
- 破坏性(DOM 结构):带 label 的 OptGroup 的选项包在 `div.semi-select-group-wrapper` 内,依赖选项与标题同级的自定义样式(如分隔线选择器)需调整。
|
|
1215
|
+
- 可搜索的 Select、TreeSelect、Cascader 改为 ARIA 1.2 combobox,按 `textbox` 查询触发器内搜索框的测试改为 `combobox`。删除语言包键 `Select.selected`、`Select.createItem`,新增 `Select.clear`;`renderOptionItem` 参数新增 `id`,需写在 `role="option"` 外层元素上。
|
|
1216
|
+
- 行为:`onFocus`、`onBlur` 成对触发,焦点在触发器内部移动不触发;点击外部关闭下拉时焦点留在被点击处;键盘按 APG select-only combobox 处理;已选项按 `value` 而非 `label` 识别;回调收到的选项对象不再带内部字段;`dropdownMatchSelectWidth` 跟随触发器的当前宽度,打开期间触发器变宽下拉也随之变宽。OverflowList 新增 `wrapperProps`。
|
|
1217
|
+
- 破坏性:选项对象上不再挂 `_show`、`_selected`、`_scrollIndex`、`_parentGroup`、`_keyInJsx`、`_inputCreateOnly`、`_notExist`,这些状态由 foundation 内部的选项记录保存。`renderOptionItem`、`renderSelectedItem`、`filter`、`onChange`(`onChangeWithObject`)、`onSelect`、`onDeselect`、`onCreate`、`onExceed` 与 `triggerRender` 的 `value` 收到的都是用户传入的选项对象本身(同一引用,不再是拷贝),Vue、Svelte 的对应插槽与 snippet 相同。破坏性(类型):React 的 `SelectedItemProps` 删除 `_show`、`_selected`、`_scrollIndex`,Solid 的 `SelectedItemProps` 等同于 `OptionProps`。
|
|
1218
|
+
- OverflowList 按项与容器的小数宽度判断溢出:原来按取整后的宽度,Safari 等按小数宽度排版文字时,恰好放得下的项也被折叠,Select `ellipsisTrigger` 少显示标签、`+N` 偏大。
|
|
1219
|
+
- 行为变化:Select、AutoComplete、DatePicker、TimePicker 的触发器只在面板打开时设置 `aria-controls`,关闭时不再指向未渲染的 listbox 或面板(四个框架一致)。
|
|
1220
|
+
- Svelte:OverflowList 的 `item`、`overflow` 是 snippet,参数为 `{ item, index }` 与 `{ items, position }`;`onOverflow`、`onIntersect`、`onVisibleStateChange` 是回调 prop;`styles` 的值是字符串。
|
|
1221
|
+
- Svelte:scroll 模式把每项包在 `display: contents` 的 span 里,在 snippet 渲染出的第一个元素上写 `data-scrollkey` 并观察它,项的 snippet 必须输出元素,否则该项被跳过;collapse 模式只在有溢出项且传了 `overflow` snippet 时渲染 overflow 盒子。
|
|
1222
|
+
- Svelte:Select 的选项只来自 `optionList`,不提供 `Select.Option`、`Select.OptGroup`;`value` 可绑定,配 `onChange`;回调与 React 同名(`onChangeWithObject`、`onDropdownVisibleChange`、`onListScroll`、`onSearch`、`onSelect`、`onDeselect`、`onExceed`、`onCreate`、`onClear`、`onFocus`、`onBlur`);`autoFocus` 写作 `autofocus`;保留 `defaultOpen`、`defaultActiveFirstOption`(没有受控的 `open`)。
|
|
1223
|
+
- Svelte:`optionList` 条目用 `group: { key, label }` 分组,同组条目须相邻;分组渲染为 `role="group"`(`aria-labelledby` 指向组标题),搜索时没有可见选项的分组整组隐藏,搜索词命中组标题时显示整组;`groupLabel` snippet(参数 `{ group }`)定制组标题。`optionLabel` snippet(参数 `{ option }`)只替换选项行内的文字,选中图标、`role="option"` 与键盘行为不变,内容里不高亮搜索关键字。开启 `virtualize` 时不渲染组标题与 `role="group"`,选项平铺(同其他框架)。
|
|
1224
|
+
- Svelte:`prefix`、`suffix`、`insetLabel`、`arrowIcon`、`clearIcon`、`emptyContent`、四个面板插槽,以及 `optionItem`、`createItem`、`selectedItem`、`tag`、`trigger` 都是 snippet;`emptyContent={null}` 隐藏空状态,空 snippet 无法识别,隐藏箭头只能用 `showArrow={false}`;`optionItem` 参数的事件名是 `onclick`、`onmouseenter`,可直接展开到元素上;`trigger` 参数没有 `componentProps`。
|
|
1225
|
+
- Svelte:`styles` 的值与选项的 `style` 是字符串;按键先由 Select 处理再调用根元素上的 `onkeydown`,`onclick`、`onfocusin`、`onfocusout` 同样先处理再调用,鼠标移入移出用根元素原生的 `onmouseenter`、`onmouseleave`;不支持泛型 `V`、`Multiple`、`WithObject`,`onChange` 参数类型是 `SelectValue`;对外方法 `open`、`close`、`focus`、`clearInput`、`selectAll`、`deselectAll`、`search`、`rePosition` 经 `bind:this` 调用。
|
|
1226
|
+
- `ellipsisTrigger` 加 `maxTagCount` 时,新增选项后的 `+N` 计入宽度造成的隐藏项。React:多选 Tag 的根元素不再带 `disabled` 属性。
|
|
1227
|
+
- 多选时焦点从触发器移入 `+N` 浮层不再触发一对 `onBlur`、`onFocus`,焦点离开触发器与浮层后才触发 `onBlur`。`allowCreate` 宽度受限时「创建」提示保持宽度,换行的是输入的文本。
|
|
1228
|
+
- 组件内部的控件不再读对应组件的全局默认值(F7):TreeSelect、Cascader 触发器里的 TagInput 不会被加上清除按钮、前后缀、拖拽或失焦建标签;Pagination 的每页条数 Select 与 ColorPicker 的格式 Select 不会变成可搜索、可创建、多选或以对象回调,也不会被加上清除按钮与前后缀。
|
|
1229
|
+
- Vue、Solid:回调与插槽参数里的选项对象不再带框架层的 `_slot`(Vue 的分组标题不再带 `_labelSlot`)。已选项的插槽内容按 `value` 从当前选项中取,已选项不在当前选项里(远程搜索换了 `optionList`)时显示它的 `label`。
|
|
1230
|
+
- React 破坏性(类型):`select` 深路径导出的 `optionRenderProps` 改名 `OptionRenderProps`、`virtualListProps` 改名 `VirtualizeProps`;包根的 `SelectOptionRenderProps` 不变。
|