@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,465 @@
|
|
|
1
|
+
# TagInput
|
|
2
|
+
|
|
3
|
+
> Taginput is a input component that can add content as a tag.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/tag-input/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Avatar, Button, TagInput, Toast } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic Usage
|
|
18
|
+
|
|
19
|
+
After pressing the Enter key, the input will add value as a tag. If the tag content is an empty string or pure space, it will be filtered.
|
|
20
|
+
|
|
21
|
+
```svelte
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
24
|
+
|
|
25
|
+
let value = $state(['短视频', '直播', '长视频']);
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<TagInput bind:value onChange={(v) => console.log(v)} placeholder="请输入..." />
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Batch Add
|
|
32
|
+
|
|
33
|
+
You can use `separator` to set the separator to achieve batch input, and its default value is a comma. Multiple separators are supported in string\[] format.
|
|
34
|
+
|
|
35
|
+
```svelte
|
|
36
|
+
<script lang="ts">
|
|
37
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
38
|
+
|
|
39
|
+
const separators = ['-', '/', '|', '++'];
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<TagInput onChange={(v) => console.log(v)} placeholder="使用 - 进行批量输入" separator="-" />
|
|
43
|
+
<br />
|
|
44
|
+
<br />
|
|
45
|
+
<TagInput onChange={(v) => console.log(v)} placeholder="支持多个分隔符进行批量输入" separator={separators} />
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Batch Remove
|
|
49
|
+
|
|
50
|
+
You can also use `showClear` to set whether to support one-click deletion of all tags and input.
|
|
51
|
+
|
|
52
|
+
```svelte
|
|
53
|
+
<script lang="ts">
|
|
54
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
55
|
+
|
|
56
|
+
let value = $state(['短视频', '直播']);
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<TagInput bind:value onChange={(v) => console.log(v)} placeholder="请输入..." showClear />
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Disabled
|
|
63
|
+
|
|
64
|
+
```svelte
|
|
65
|
+
<script lang="ts">
|
|
66
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
67
|
+
|
|
68
|
+
let value = $state(['短视频', '直播', '长视频']);
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<TagInput bind:value disabled placeholder="请输入..." showClear />
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Size
|
|
75
|
+
|
|
76
|
+
Use `size` to set the size of the TagInput, optional: `small`, `default`, `large`.
|
|
77
|
+
|
|
78
|
+
```svelte
|
|
79
|
+
<script lang="ts">
|
|
80
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<TagInput placeholder="small" size="small" />
|
|
84
|
+
<br />
|
|
85
|
+
<br />
|
|
86
|
+
<TagInput placeholder="default" />
|
|
87
|
+
<br />
|
|
88
|
+
<br />
|
|
89
|
+
<TagInput placeholder="large" size="large" />
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Different validate status
|
|
93
|
+
|
|
94
|
+
validateStatus: `default`, `warning`, `error`.
|
|
95
|
+
|
|
96
|
+
```svelte
|
|
97
|
+
<script lang="ts">
|
|
98
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<TagInput placeholder="default" />
|
|
102
|
+
<br />
|
|
103
|
+
<br />
|
|
104
|
+
<TagInput placeholder="warning" validateStatus="warning" />
|
|
105
|
+
<br />
|
|
106
|
+
<br />
|
|
107
|
+
<TagInput placeholder="error" validateStatus="error" />
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Prefix / Suffix
|
|
111
|
+
|
|
112
|
+
You can pass the input box prefix through the `prefix` snippet and the suffix through the `suffix` snippet, as text or nodes such as icons.\
|
|
113
|
+
The left and right padding is added automatically when the snippet content is plain text or an Icon. For custom nodes the padding is 0; set it on the nodes you pass in if needed.
|
|
114
|
+
|
|
115
|
+
```svelte
|
|
116
|
+
<script lang="ts">
|
|
117
|
+
import { IconGift, IconVigoLogo } from '@fibrae/semi-icons-svelte';
|
|
118
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<TagInput>
|
|
122
|
+
{#snippet prefix()}
|
|
123
|
+
<IconVigoLogo />
|
|
124
|
+
{/snippet}
|
|
125
|
+
</TagInput>
|
|
126
|
+
<br />
|
|
127
|
+
<br />
|
|
128
|
+
<TagInput>
|
|
129
|
+
{#snippet prefix()}Prefix{/snippet}
|
|
130
|
+
</TagInput>
|
|
131
|
+
<br />
|
|
132
|
+
<br />
|
|
133
|
+
<TagInput>
|
|
134
|
+
{#snippet suffix()}
|
|
135
|
+
<IconGift />
|
|
136
|
+
{/snippet}
|
|
137
|
+
</TagInput>
|
|
138
|
+
<br />
|
|
139
|
+
<br />
|
|
140
|
+
<TagInput>
|
|
141
|
+
{#snippet suffix()}Suffix{/snippet}
|
|
142
|
+
</TagInput>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Autocomplete
|
|
146
|
+
|
|
147
|
+
You can use `addOnBlur` to set whether the current input value is automatically created as a tag when the blur event is triggered.
|
|
148
|
+
|
|
149
|
+
```svelte
|
|
150
|
+
<script lang="ts">
|
|
151
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
152
|
+
|
|
153
|
+
let value = $state(['短视频', '直播', '长视频']);
|
|
154
|
+
</script>
|
|
155
|
+
|
|
156
|
+
<TagInput addOnBlur bind:value onChange={(v) => console.log(v)} placeholder="请输入..." />
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Allow Duplicates
|
|
160
|
+
|
|
161
|
+
You can use `allowDuplicates` to set whether to allow the creation of the same tag.
|
|
162
|
+
|
|
163
|
+
```svelte
|
|
164
|
+
<script lang="ts">
|
|
165
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
166
|
+
|
|
167
|
+
let value = $state(['短视频', '直播', '长视频']);
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
<TagInput allowDuplicates={false} bind:value onChange={(v) => console.log(v)} placeholder="请输入..." />
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Limits
|
|
174
|
+
|
|
175
|
+
You can use `max` to limit the number of tags. Tags added past the limit are dropped, and the `onExceed()` callback is invoked.
|
|
176
|
+
|
|
177
|
+
You can use `maxLength` to limit the maximum length of a single tag, and the `onInputExceed()` callback will be invoked when this value is exceeded.
|
|
178
|
+
|
|
179
|
+
```svelte
|
|
180
|
+
<script lang="ts">
|
|
181
|
+
import { TagInput, Toast } from '@fibrae/semi-ui-svelte';
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<TagInput
|
|
185
|
+
max={3}
|
|
186
|
+
onChange={(v) => console.log(v)}
|
|
187
|
+
onExceed={(v) => {
|
|
188
|
+
Toast.warning('超过 max');
|
|
189
|
+
console.log(v);
|
|
190
|
+
}}
|
|
191
|
+
placeholder="最多输入3条标签.."
|
|
192
|
+
/>
|
|
193
|
+
<TagInput
|
|
194
|
+
maxLength={5}
|
|
195
|
+
onChange={(v) => console.log(v)}
|
|
196
|
+
onInputExceed={(v) => {
|
|
197
|
+
Toast.warning('超过 maxLength');
|
|
198
|
+
console.log(v);
|
|
199
|
+
}}
|
|
200
|
+
placeholder="单个标签长度不超过5..."
|
|
201
|
+
style="margin-block-start: 12px"
|
|
202
|
+
/>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Limit the number of tags displayed
|
|
206
|
+
|
|
207
|
+
You can use `maxTagCount` to limit the number of tags displayed, and the excess will be displayed as +N. You can use `showRestTagsPopover` to set whether hover +N displays Popover after `maxTagCount` is exceeded, and you can configure Popover in the `restTagsPopoverProps` property.
|
|
208
|
+
|
|
209
|
+
```svelte
|
|
210
|
+
<script lang="ts">
|
|
211
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
212
|
+
|
|
213
|
+
let value = $state(['短视频', '直播', '长视频']);
|
|
214
|
+
</script>
|
|
215
|
+
|
|
216
|
+
<TagInput bind:value maxTagCount={2} onChange={(v) => console.log(v)} restTagsPopoverProps={{ position: 'top' }} showRestTagsPopover />
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Controlled Tag
|
|
220
|
+
|
|
221
|
+
Bind the tags with `bind:value` to control them. There is no `defaultValue`: a one-way `value={x}` only seeds the tags, and `bind:value={get, set}` makes the input fully controlled. Binding `value` to `undefined` clears the tags.
|
|
222
|
+
|
|
223
|
+
```svelte
|
|
224
|
+
<script lang="ts">
|
|
225
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
226
|
+
|
|
227
|
+
let value = $state(['短视频']);
|
|
228
|
+
</script>
|
|
229
|
+
|
|
230
|
+
<TagInput bind:value />
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Controlled Input
|
|
234
|
+
|
|
235
|
+
Bind the input text with `bind:inputValue` to control it; `bind:inputValue={get, set}` makes it fully controlled.
|
|
236
|
+
|
|
237
|
+
```svelte
|
|
238
|
+
<script lang="ts">
|
|
239
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
240
|
+
|
|
241
|
+
let inputValue = $state('abc');
|
|
242
|
+
</script>
|
|
243
|
+
|
|
244
|
+
<TagInput bind:inputValue />
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Callback
|
|
248
|
+
|
|
249
|
+
```svelte
|
|
250
|
+
<script lang="ts">
|
|
251
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
252
|
+
|
|
253
|
+
let value = $state(['短视频']);
|
|
254
|
+
</script>
|
|
255
|
+
|
|
256
|
+
<TagInput
|
|
257
|
+
bind:value
|
|
258
|
+
onAdd={(tag) => {
|
|
259
|
+
console.log(`onAdd,新增:${tag}`);
|
|
260
|
+
}}
|
|
261
|
+
onBlur={() => {
|
|
262
|
+
console.log(`onBlur`);
|
|
263
|
+
}}
|
|
264
|
+
onChange={(tag) => {
|
|
265
|
+
console.log(`onChange,当前标签数组:${tag}`);
|
|
266
|
+
}}
|
|
267
|
+
onFocus={() => {
|
|
268
|
+
console.log(`onFocus`);
|
|
269
|
+
}}
|
|
270
|
+
onInputChange={(input) => {
|
|
271
|
+
console.log(`onInputChange,当前输入内容:${input}`);
|
|
272
|
+
}}
|
|
273
|
+
onRemove={(v, i) => {
|
|
274
|
+
console.log(`onRemove,移除:${v}, 序号:${i}`);
|
|
275
|
+
}}
|
|
276
|
+
placeholder="请输入..."
|
|
277
|
+
showClear
|
|
278
|
+
/>
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Focus Management
|
|
282
|
+
|
|
283
|
+
Bind the component with `bind:this` and call its `focus()` and `blur()` methods to manage the focus. `focus()` focuses the input and activates the component; `blur()` removes the focus from whichever element inside the component holds it.
|
|
284
|
+
|
|
285
|
+
```svelte
|
|
286
|
+
<script lang="ts">
|
|
287
|
+
import { Button, TagInput } from '@fibrae/semi-ui-svelte';
|
|
288
|
+
|
|
289
|
+
let value = $state(['短视频', '直播']);
|
|
290
|
+
let tagInput = $state<ReturnType<typeof TagInput>>();
|
|
291
|
+
</script>
|
|
292
|
+
|
|
293
|
+
<TagInput bind:this={tagInput} bind:value />
|
|
294
|
+
<Button style="margin-block-start: 10px" onclick={() => tagInput?.focus()}>点击按钮聚焦</Button>
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Custom TagInput rendering
|
|
298
|
+
|
|
299
|
+
You can use the `tag` snippet to replace each tag as a whole; it receives `{ value, index, onClose }`. Empty content renders no tag and does not fall back to the default tag. `onClose` calls `preventDefault` on the event it receives, so you can pass it straight to a button's `onclick`.
|
|
300
|
+
|
|
301
|
+
```svelte
|
|
302
|
+
<script lang="ts">
|
|
303
|
+
import { IconClose } from '@fibrae/semi-icons-svelte';
|
|
304
|
+
import { Avatar, Button, TagInput } from '@fibrae/semi-ui-svelte';
|
|
305
|
+
|
|
306
|
+
const list = [
|
|
307
|
+
{
|
|
308
|
+
name: '夏可漫',
|
|
309
|
+
avatar: '/assets/root-web-sites/avatar-demo.jpeg',
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
name: '申悦',
|
|
313
|
+
avatar: '/assets/root-web-sites/bf8647bffab13c38772c9ff94bf91a9d.jpg',
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
name: '曲晨一',
|
|
317
|
+
avatar: '/assets/root-web-sites/bf8647bffab13c38772c9ff94bf91a9d.jpg',
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: '文嘉茂',
|
|
321
|
+
avatar: '/assets/root-web-sites/avatar-demo.jpeg',
|
|
322
|
+
},
|
|
323
|
+
];
|
|
324
|
+
const mapList = new Map(list.map((item) => [item.name, item]));
|
|
325
|
+
const fallbackAvatar = '/assets/placeholder/avatar-a.svg';
|
|
326
|
+
|
|
327
|
+
let value = $state(['夏可漫']);
|
|
328
|
+
</script>
|
|
329
|
+
|
|
330
|
+
<TagInput bind:value>
|
|
331
|
+
{#snippet tag(tagItem)}
|
|
332
|
+
<div style="background-color: var(--semi-color-info-light-default); padding: 4px 8px; border-radius: 12px; display: flex; align-items: center; font-size: 14px; margin-inline-end: 10px">
|
|
333
|
+
<Avatar alt="avatar" size="extra-small" src={mapList.get(tagItem.value)?.avatar ?? fallbackAvatar} />
|
|
334
|
+
<span style="margin-inline-start: 8px">{`${tagItem.value}@semi.com`}</span>
|
|
335
|
+
<Button aria-label={`移除 ${tagItem.value}`} size="small" theme="borderless" type="tertiary" onclick={tagItem.onClose}>
|
|
336
|
+
{#snippet icon()}
|
|
337
|
+
<IconClose size="small" />
|
|
338
|
+
{/snippet}
|
|
339
|
+
</Button>
|
|
340
|
+
</div>
|
|
341
|
+
{/snippet}
|
|
342
|
+
</TagInput>
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Drag to sort
|
|
346
|
+
|
|
347
|
+
Set `draggable` to true to enable drag and drop sorting. After the drag function is enabled, once TagInput is focused (by click or Tab) the tags can be dragged; after the focus leaves TagInput they cannot. The drag handle sits beside its tag and works from the keyboard, see "Keyboard and focus" below. Tags with the same value can be sorted separately.
|
|
348
|
+
|
|
349
|
+
```svelte
|
|
350
|
+
<script lang="ts">
|
|
351
|
+
import { TagInput } from '@fibrae/semi-ui-svelte';
|
|
352
|
+
|
|
353
|
+
let value = $state(['短视频', '直播', '长视频']);
|
|
354
|
+
</script>
|
|
355
|
+
|
|
356
|
+
<TagInput allowDuplicates={false} bind:value draggable onChange={(v) => console.log(v)} placeholder="请输入..." />
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## API Reference
|
|
360
|
+
|
|
361
|
+
**Props**
|
|
362
|
+
|
|
363
|
+
| Property | Description | Type | Default |
|
|
364
|
+
| - | - | - | - |
|
|
365
|
+
| addOnBlur | Whether the input text becomes a tag when the focus leaves the component. | `boolean` | `false` |
|
|
366
|
+
| allowDuplicates | Whether the same tag can be added more than once. | `boolean` | `true` |
|
|
367
|
+
| autofocus | Whether the input is focused and the component activated on mount; ignored when disabled. | `boolean` | `false` |
|
|
368
|
+
| clearIcon | Snippet that replaces the icon in the clear button; empty content keeps the default icon. | `Snippet` | - |
|
|
369
|
+
| disabled | Whether the component is disabled. | `boolean` | - |
|
|
370
|
+
| draggable | Whether tags can be reordered by dragging. | `boolean` | `false` |
|
|
371
|
+
| expandRestTagsOnClick | When not draggable, whether the collapsed tags expand once focus enters the component (click, Tab or the focus method). | `boolean` | `true` |
|
|
372
|
+
| inputValue | Current input text, supports `bind:inputValue`. Left out, the component manages it; for a fully controlled text use the function binding `bind:inputValue={get, set}`. Binding it to `undefined` clears the text. | `string` | - |
|
|
373
|
+
| insetLabel | Snippet for the inset label shown before the input; when prefix is also given, only prefix is shown. When shown, it names an input that has no aria-label or aria-labelledby. | `Snippet` | - |
|
|
374
|
+
| insetLabelId | id of the inset label container, for aria-labelledby. | `string` | - |
|
|
375
|
+
| max | Maximum number of tags. | `number` | - |
|
|
376
|
+
| maxLength | Maximum length of one tag. | `number` | - |
|
|
377
|
+
| maxTagCount | Maximum number of tags shown; the rest are shown as +N. | `number` | - |
|
|
378
|
+
| onAdd | Called when tags are added, with the added tags. | `(addedValue: string[]) => void` | - |
|
|
379
|
+
| onBlur | Called once when the focus leaves the whole component; moving inside it does not call it. | `(event: FocusEvent) => void` | - |
|
|
380
|
+
| onChange | Called when the tags change. | `(value: string[]) => void` | - |
|
|
381
|
+
| onclick | Called on a click on the root element, after the component's own activation handling. | `MouseEventHandler<T> \| null` | - |
|
|
382
|
+
| onExceed | Called when adding would exceed max, with the whole list before it is cut. | `(value: string[]) => void` | - |
|
|
383
|
+
| onFocus | Called once when the focus enters from outside; moving between the input, tags and clear button does not call it. | `(event: FocusEvent) => void` | - |
|
|
384
|
+
| onInputChange | Called when the input text changes. The event may be an input, keydown, focusout, click or composition event; narrow it by event.type before reading its own fields. | `(value: string, event: Event) => void` | - |
|
|
385
|
+
| onInputExceed | Called when the input text exceeds maxLength, with the rejected input text. | `(value: string) => void` | - |
|
|
386
|
+
| onKeyDown | Called on keydown in the input after the component handled it; calling preventDefault there does not stop Enter from adding a tag. | `(event: KeyboardEvent) => void` | - |
|
|
387
|
+
| onRemove | Called when a tag is removed, with the removed tag and its index. | `(removedValue: string, index: number) => void` | - |
|
|
388
|
+
| placeholder | Placeholder of the input while there are no tags. | `string` | - |
|
|
389
|
+
| prefix | Snippet for the prefix of the input; text or an icon gets side spacing automatically. | `Snippet` | - |
|
|
390
|
+
| preventScroll | Whether the focus calls inside the component stop the browser from scrolling the focused element into view. | `boolean` | - |
|
|
391
|
+
| restTagsPopoverProps | Popover props of the +N popover, without content, child and children. | `RestTagsPopoverProps` | - |
|
|
392
|
+
| separator | Separator(s) for adding several tags at once; null disables splitting. | `string \| string[] \| null` | `","` |
|
|
393
|
+
| showClear | Whether to show the button that clears all tags and the input text. | `boolean` | `false` |
|
|
394
|
+
| showContentTooltip | Whether hovering a truncated tag shows its full text in an overlay; an object picks the overlay type and the props passed to it. | `boolean \| ShowTooltip` | `true` |
|
|
395
|
+
| showRestTagsPopover | Whether hovering +N shows the remaining tags in a Popover once maxTagCount is exceeded. | `boolean` | `true` |
|
|
396
|
+
| size | Size: small, default or large. | `TagInputSize` | - |
|
|
397
|
+
| split | Custom split function that returns the split strings. | `(originString: string, separators: string \| string[] \| null) => string[]` | - |
|
|
398
|
+
| suffix | Snippet for the suffix of the input; text or an icon gets side spacing automatically. | `Snippet` | - |
|
|
399
|
+
| tag | Snippet that replaces each tag as a whole, receiving `{ value, index, onClose }`; empty content renders no tag and does not fall back to the default tag. | `Snippet<[TagInputTagSnippetProps]>` | - |
|
|
400
|
+
| validateStatus | Validation status, which only affects styling; error also sets aria-invalid on the input. | `TagInputValidateStatus` | `"default"` |
|
|
401
|
+
| value | Current tags, supports `bind:value`. Left out, the component manages them; `null` means controlled with no tags; a one-way `value={x}` only seeds them, and for a fully controlled input use the function binding `bind:value={get, set}`. Binding it to `undefined` clears the tags. There is no defaultValue. | `string[] \| null` | - |
|
|
402
|
+
|
|
403
|
+
**Methods**
|
|
404
|
+
|
|
405
|
+
| Method | Description | Type |
|
|
406
|
+
| - | - | - |
|
|
407
|
+
| blur | Removes focus from whichever element inside the component holds it (input, tag or clear button). | `() => void` |
|
|
408
|
+
| focus | Focuses the input and activates the component. | `() => void` |
|
|
409
|
+
|
|
410
|
+
`class` (a string, array or object), `style` (a string) and native attributes and event handlers land on the root element, except `id`, `name`, `role`, `tabindex` and the `aria-*` attributes that describe the input (`aria-label`, `aria-labelledby`, `aria-describedby`, `aria-invalid`, `aria-required`, `aria-controls`, `aria-expanded`, `aria-haspopup`, `aria-autocomplete`, `aria-activedescendant`, `aria-errormessage`), which land on the inner input. The lowercase listeners `onchange`, `onfocus`, `onblur` and `onkeydown` are not native passthroughs; use the callbacks `onChange`, `onFocus`, `onBlur` and `onKeyDown` above. `onclick` and `onmousedown` run in addition to the component's own handling.
|
|
411
|
+
|
|
412
|
+
## Accessibility
|
|
413
|
+
|
|
414
|
+
### ARIA
|
|
415
|
+
|
|
416
|
+
- TagInput supports the input of `aria-label` to indicate the function of the TagInput; it lands on the input box, not on the root node;
|
|
417
|
+
- The root node has the `group` role, which holds the input, the tags and the clear button as one control; when disabled it carries `aria-disabled="true"`, otherwise it has no `aria-disabled`;
|
|
418
|
+
- When disabled, the input is natively `disabled` and the tags are static text without an `aria-label`; with `validateStatus` set to `error` the input carries `aria-invalid`, and an explicit `aria-invalid` wins;
|
|
419
|
+
- With `showClear`, tags or input text, and no `disabled`, a clear button is rendered. It is a native `button` named "Clear TagInput value" from the locale, shown on hover or while focus is inside the TagInput. From the input, `Tab` moves to the clear button; `Enter` or `Space` clears, as a mouse click does, and the focus goes back to the input. `Backspace` in the empty input also removes the last tag.
|
|
420
|
+
|
|
421
|
+
### Keyboard and focus
|
|
422
|
+
|
|
423
|
+
- `Enter` in the input adds the input text as a tag; with empty input it does nothing. `Enter` always has its default action prevented, so a TagInput inside a form never submits it.
|
|
424
|
+
- `Backspace` in the empty input removes the last tag.
|
|
425
|
+
- A closable tag is a `role="button"` Tab stop placed before the input; with a tag focused, `Backspace` or `Delete` closes it and the focus goes back to the input. When disabled, tags are static text and not focusable.
|
|
426
|
+
- With `showClear` and some content, the clear button follows the input: `Tab` reaches it, `Enter` or `Space` clears, and the focus goes back to the input.
|
|
427
|
+
- The active state follows the focus: it starts when the focus comes in from outside (click, `Tab` or `focus()`) and ends when it leaves the whole component. Moving the focus between the input, the tags and the clear button is not leaving, so it does not fire `focus` or `blur` and does not trigger `addOnBlur`. While active, tags folded by `maxTagCount` expand (unless `expandRestTagsOnClick` is `false`).
|
|
428
|
+
- With `draggable` and the component active, each tag gets a drag handle that is its own Tab stop, placed before the tag it belongs to. Focus a handle, press `Space` to pick up, the arrow keys to move and `Space` to drop; screen readers announce the pick up, moves and drop.
|
|
429
|
+
|
|
430
|
+
## Design Tokens
|
|
431
|
+
|
|
432
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/input/tag-input/>
|
|
433
|
+
|
|
434
|
+
## Changes from Semi Design
|
|
435
|
+
|
|
436
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
437
|
+
|
|
438
|
+
- 破坏性:AutoComplete 删除 `dropdownClassName`、`dropdownStyle`,改用 `classNames.dropdown`、`styles.dropdown`,落在 `role="listbox"` 元素上,样式与 `maxHeight` 合并且 `styles.dropdown` 优先。
|
|
439
|
+
- PinCode:格子间距改为逻辑属性;ConfigProvider 的 `direction` 为 `rtl` 时左右方向键反向(ArrowLeft 移到下一格)。
|
|
440
|
+
- 破坏性:AutoComplete 删除 `getPopupContainer`、`zIndex`、`AutoComplete.Option` 与 `children`(改用 `Select.Option`),删除深路径 `@fibrae/semi-ui-react/auto-complete/option`、`@fibrae/semi-foundation/auto-complete/optionFoundation`;`style.width` 不再复制为下拉最小宽度。
|
|
441
|
+
- 破坏性(类型):AutoComplete 的 `defaultValue` 收窄为 `string | number`,`onKeyDown` 参数改为 `KeyboardEvent<HTMLDivElement>`,删除 `mouseEnterDelay`、`mouseLeaveDelay`、`tabIndex`;输入框角色改为 combobox(按 textbox 查询的测试需改为 combobox),`id` 落在输入框上。
|
|
442
|
+
- 破坏性(类型):TagInput 的 `onFocus`、`onBlur` 参数改为 `React.FocusEvent<HTMLDivElement>`,`onInputChange` 第二个参数改为 `React.SyntheticEvent`,`value` 为 `string[] | null`,ref 为 `TagInputHandle { focus, blur }`;`AvatarState.hoverContent` 改为 `hovered: boolean`。
|
|
443
|
+
- 破坏性(类型):`@fibrae/semi-foundation/components/tag-input/foundation` 删除 `any` 别名 `TagInputCursorEvent`、`TagInputKeyboardEvent`、`TagInputMouseEvent`,改为 `TagInputKeyEvent`、`TagInputFocusEvent`、`TagInputClearEvent`;`TagInputFoundation`、`TagInputAdapter` 新增按键与焦点事件的类型参数 `KE`、`FE`,`notifyKeyDown`、`notifyFocus`、`notifyBlur` 的参数随之收窄。
|
|
444
|
+
- TagInput:`+N` 浮层、`suffix` 中的 Popover 等内部弹层里的按下、焦点与点击不结束也不进入激活状态,`+N` 浮层里的标签可以直接关闭(四个框架一致)。
|
|
445
|
+
- AutoComplete:对象数据项缺 `label` 时候选行显示 `value`(四个框架一致);数据项带 `show: false` 时,高亮项与 Enter 选中项是同一个可见项。`defaultActiveFirstOption` 高亮第一个可用项,首项禁用时不再停在禁用项上(与 Select 一致,四个框架一致)。
|
|
446
|
+
- 破坏性(样式钩子):TagInput 悬停改由 CSS `:hover` 提供,不再加 `semi-tagInput-hover` 类;删除 `semi-tagInput-clearBtn-invisible` 与 `semi-avatar-focus`。TagInput 清除按钮与拖拽句柄改为带名称(`TagInput.clear`、`TagInput.dragSort`)的原生 button,`onFocus`、`onBlur` 以整个组件为界。
|
|
447
|
+
- Avatar:可点击头像的焦点目标为 `role="button"`(按 `img` 查询的测试需改为 button),不再加语言包 `Avatar.clickable` 前缀(键已删除);AvatarGroup 未声明属性落在根 div,`size`、`shape` 经 context 下发到被 Tooltip、Popover 包住的头像。PinCode:`autoFocus` 默认值由 `true` 改为 `false`,需要时显式传 `autoFocus` 或用 `PinCodeHandle.focus(0)`;`onFocus`、`onBlur` 按整组计,焦点从外部进入整个 PinCode 时触发一次 `onFocus`,格子之间移动不触发。
|
|
448
|
+
- Avatar:`bottomSlot` 方形标签不换行,比头像宽时向两侧超出。
|
|
449
|
+
- Avatar:`border.motion` 的外圈动画只放大并淡出,边框粗细不再随动画变细到 0(原来每帧触发布局与重绘);删除 Sass 变量 `$animation_width-additionalBorder-end`。
|
|
450
|
+
- React、Vue、Solid:服务端渲染的 Avatar 图片在 hydration 前已加载失败时,hydration 后调用 `onError` 并显示文字(原来保留破图)。
|
|
451
|
+
- AutoComplete:受控值回显但没有匹配项时保留已输入的文本(四个框架一致)。
|
|
452
|
+
- AutoComplete:下拉中有可聚焦元素(`renderItem`、`emptyContent` 里的按钮或链接)时,方向键只移动高亮,焦点不再移入下拉。
|
|
453
|
+
- Solid 破坏性:AvatarGroup 的 `renderMore` 签名为 `(restNumber: number, restAvatars: ((props?: AvatarProps) => JSX.Element)[]) => JSX.Element`。超出 `maxCount` 的头像在组内不创建,`restAvatars` 的每一项是渲染函数,在调用处才创建该头像(独立头像,不是列表项,不取组的 `size`、`shape`),传入的属性覆盖头像自身的属性(如 `avatar({ size: 'extra-small' })`,对应 React 的 `cloneElement`);`maxCount` 与 React 一样按子节点计数,包装元素(如 Tooltip)里的头像随包装元素整体隐藏,不单独隐藏,`maxCount` 变化或增删子节点时由后面的子节点补位。默认 `+N` 头像的名称只列被隐藏头像的 `alt`。
|
|
454
|
+
- Solid 破坏性(类型):Avatar 的 `topSlot.text`、`bottomSlot.text` 改为 `AvatarSlotText`(`string | number | (() => JSX.Element)`,从包入口导出),自定义内容写成函数 `text: () => <IconPlus />`,只在标记实际显示时(预设尺寸,topSlot 另需圆形)调用;`render` 仍完全替换标记。
|
|
455
|
+
- Svelte:Avatar 的 `class`、`style`、`id` 等属性落在头像 span,存在包装层时 `style` 落在包装层;传了 `onclick` 才成为可聚焦的 button;`hoverMask`、`topSlotText`、`bottomSlotText` 是 snippet,整块替换写 `topSlot.render`、`bottomSlot.render`,`topSlot.style`、`bottomSlot.style` 是字符串;内容是文字还是元素在挂载后判定,服务端首帧一律按文字结构输出。
|
|
456
|
+
- Svelte 破坏性:AvatarGroup 不接受 Avatar 子节点,改用 `items`(每项是 Avatar 的属性,类型 `AvatarGroupItem`)加 `item` snippet(参数 `{ item, index }`,提供头像内的文字),组的 `size`、`shape` 覆盖数据项自己的值;`maxCount` 截断、`+N` 与其可访问名称在服务端首帧同步算出,默认 `+N` 的名称只列被隐藏项的 `alt`。`more` snippet 参数为 `{ restNumber, restAvatars }`,`restAvatars` 是被隐藏的完整数据项。不能再用 Tooltip 等包裹组内的单个头像,需要时在 `item` snippet 里包裹内容。
|
|
457
|
+
- Svelte:PinCode 的 `value` 可绑定,没有 `defaultValue`;回调为 `onChange`、`onComplete`、`onFocus`、`onBlur`;`autofocus` 默认 `false`;实例方法为 `focus(index)`、`blur(index)`;`id` 落在第一格,`name`、`insetLabel`、`insetLabelId` 被丢弃。
|
|
458
|
+
- Svelte:头像内容里弹层中的 Avatar 不继承 AvatarGroup 的 `size`、`shape`,也不是列表项。
|
|
459
|
+
- Svelte:TagInput 的 `value`、`inputValue` 可绑定,没有 `defaultValue`,把它们绑成 `undefined` 会清空内部状态(表单重置);回调是 `onChange`、`onInputChange(value, event)`、`onAdd`、`onRemove(value, index)`、`onExceed`、`onInputExceed`、`onFocus`、`onBlur`、`onKeyDown`。
|
|
460
|
+
- Svelte:snippet 有 `prefix`、`suffix`、`insetLabel`、`clearIcon`、`tag({ value, index, onClose })`,`tag` 返回空内容就不渲染该标签,不回落默认标签;`focus()`、`blur()` 经 `bind:this` 调用,没有 `TagInputHandle` 类型;`restTagsPopoverProps` 的类型去掉了 `content`、`child`、`children`。
|
|
461
|
+
- Svelte:`id`、`name`、`role`、`tabindex` 与全部 `aria-*` 落在内部 `<input>`(根元素是 `role="group"`),根元素上的 `onclick` 与组件自己的点击处理组合调用。
|
|
462
|
+
- Svelte:AutoComplete 的 `value` 可绑定,没有 `defaultValue`;`renderItem`、`triggerRender` 改为 `item`、`trigger` snippet(`trigger` 参数不含 `componentProps`),`prefix`、`suffix`、`insetLabel`、`clearIcon`、`emptyContent` 为 snippet,`insetLabel` 只要传了 snippet 就当作有内容。
|
|
463
|
+
- Svelte:回调为 `onChange`、`onSearch`、`onSelect`、`onClear`、`onFocus`、`onBlur`、`onDropdownVisibleChange`;`focus()`、`blur()`、`getNativeElement()` 经 `bind:this` 调用;数据项的 `class` 接受 clsx 值,`style` 与 `styles` 的值只接受字符串;`id`、`name`、`aria-*` 落在输入框,用 `trigger` 时 `id` 落在根元素。
|
|
464
|
+
- Avatar:`size`、`gap` 变化后重算文字缩放。
|
|
465
|
+
- 破坏性(类型):Avatar 图片加载失败时 `onError` 收到 error 事件,返回 `false` 保留破图:React 为 `(event: SyntheticEvent<HTMLImageElement>) => boolean | void`,Vue、Svelte 为 `(event: Event) => boolean | void`,Solid 的事件带 `currentTarget: HTMLImageElement`。
|