@fibrae/semi-ui-svelte 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/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/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/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/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,399 @@
|
|
|
1
|
+
# AutoComplete
|
|
2
|
+
|
|
3
|
+
> The input box is automatically filled.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/auto-complete/
|
|
6
|
+
|
|
7
|
+
## When to use
|
|
8
|
+
|
|
9
|
+
Used to provide input suggestions to the input box and perform automatic completion operations
|
|
10
|
+
|
|
11
|
+
The difference with the searchable Select component:
|
|
12
|
+
|
|
13
|
+
- AutoComplete is essentially an enhanced Input component that provides input suggestions, while Select is a selector
|
|
14
|
+
- When you click to expand, Select will clear all the values in the input box, and AutoComplete will keep the last selected value
|
|
15
|
+
|
|
16
|
+
* Select's selected item rendering can be any snippet content, while the `renderSelectedItem` of AutoComplete may only return a string
|
|
17
|
+
|
|
18
|
+
## Demos
|
|
19
|
+
|
|
20
|
+
### How to import
|
|
21
|
+
|
|
22
|
+
```svelte
|
|
23
|
+
<script lang="ts">
|
|
24
|
+
import { AutoComplete } from '@fibrae/semi-ui-svelte';
|
|
25
|
+
</script>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Basic usage
|
|
29
|
+
|
|
30
|
+
Monitor user input through `onSearch`, pass input suggestions through `data`, and keep the value with `bind:value`, which updates when the input box changes or an input item is selected. There is no `defaultValue`: a one-way `value={x}` only seeds the input, and `bind:value={get, set}` makes it fully controlled
|
|
31
|
+
|
|
32
|
+
```svelte
|
|
33
|
+
<script lang="ts">
|
|
34
|
+
import { IconSearch } from '@fibrae/semi-icons-svelte';
|
|
35
|
+
import { AutoComplete } from '@fibrae/semi-ui-svelte';
|
|
36
|
+
|
|
37
|
+
const domains = ['gmail.com', '163.com', 'qq.com'];
|
|
38
|
+
|
|
39
|
+
let stringData = $state<string[]>([]);
|
|
40
|
+
let value = $state<string | number>('');
|
|
41
|
+
|
|
42
|
+
const handleStringSearch = (input: string) => {
|
|
43
|
+
stringData = input ? domains.map((domain) => `${input}@${domain}`) : [];
|
|
44
|
+
};
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<AutoComplete bind:value data={stringData} onChange={(next) => console.log('onChange', next)} onSearch={handleStringSearch} placeholder="搜索... " showClear style="width: 200px">
|
|
48
|
+
{#snippet prefix()}
|
|
49
|
+
<IconSearch />
|
|
50
|
+
{/snippet}
|
|
51
|
+
</AutoComplete>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Custom option rendering
|
|
55
|
+
|
|
56
|
+
When you need to customize the rendering of candidates, data can be passed in an array of objects (each Object contains two keys, label and value; value is the value selected by the candidate, and label is the text displayed by the candidate, which falls back to value when missing)\
|
|
57
|
+
The content of a candidate can be customized through the `item` snippet, which receives `{ item, index }`: `item` is the data item as given, so keep only data in the items and write the markup in the snippet
|
|
58
|
+
|
|
59
|
+
```svelte
|
|
60
|
+
<script lang="ts">
|
|
61
|
+
import { IconSearch } from '@fibrae/semi-icons-svelte';
|
|
62
|
+
import { AutoComplete, Avatar } from '@fibrae/semi-ui-svelte';
|
|
63
|
+
|
|
64
|
+
interface ListItem {
|
|
65
|
+
name: string;
|
|
66
|
+
email: string;
|
|
67
|
+
abbr: string;
|
|
68
|
+
color: 'amber' | 'indigo' | 'blue' | 'cyan';
|
|
69
|
+
value?: string;
|
|
70
|
+
label?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const list: ListItem[] = [
|
|
74
|
+
{ name: '夏可漫', email: 'xiakeman@example.com', abbr: 'XK', color: 'amber' },
|
|
75
|
+
{ name: '申悦', email: 'shenyue@example.com', abbr: 'SY', color: 'indigo' },
|
|
76
|
+
{ name: '曲晨一', email: 'quchenyi@example.com', abbr: 'CY', color: 'blue' },
|
|
77
|
+
{ name: '文嘉茂', email: 'wenjiamao@example.com', abbr: 'JM', color: 'cyan' },
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
let data = $state<ListItem[]>([]);
|
|
81
|
+
|
|
82
|
+
const handleStringSearch = (value: string) => {
|
|
83
|
+
data = value ? list.map((item) => ({ ...item, value: item.name, label: item.email })) : [];
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const renderSelectedItem = (option: ListItem) => option.email;
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<AutoComplete aria-label="搜索邮箱" {data} onSearch={handleStringSearch} {renderSelectedItem} showClear style="width: 280px">
|
|
90
|
+
{#snippet prefix()}
|
|
91
|
+
<IconSearch />
|
|
92
|
+
{/snippet}
|
|
93
|
+
{#snippet item(entry)}
|
|
94
|
+
<Avatar color={entry.item.color} size="small">{entry.item.abbr}</Avatar>
|
|
95
|
+
<div style="margin-inline-start: 4px">
|
|
96
|
+
<div style="font-size: 14px; margin-inline-start: 4px">{entry.item.name}</div>
|
|
97
|
+
<div style="margin-inline-start: 4px">{entry.item.email}</div>
|
|
98
|
+
</div>
|
|
99
|
+
{/snippet}
|
|
100
|
+
</AutoComplete>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Remote search
|
|
104
|
+
|
|
105
|
+
Get user input value from `onSearch`, update `data` dynamically, update `loading`
|
|
106
|
+
|
|
107
|
+
```svelte
|
|
108
|
+
<script lang="ts">
|
|
109
|
+
import { debounce } from 'es-toolkit';
|
|
110
|
+
import { IconSearch } from '@fibrae/semi-icons-svelte';
|
|
111
|
+
import { IconButton, IconForm, IconInput, IconSelect, IconTable } from '@fibrae/semi-icons-svelte/lab';
|
|
112
|
+
import { AutoComplete, type AutoCompleteDataItem } from '@fibrae/semi-ui-svelte';
|
|
113
|
+
|
|
114
|
+
const initList = [
|
|
115
|
+
{ value: 'select', label: '选择器', icon: IconSelect },
|
|
116
|
+
{ value: 'input', label: '输入框', icon: IconInput },
|
|
117
|
+
{ value: 'form', label: '表单', icon: IconForm },
|
|
118
|
+
{ value: 'button', label: '按钮', icon: IconButton },
|
|
119
|
+
{ value: 'table', label: '表格', icon: IconTable },
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
type ListItem = (typeof initList)[number];
|
|
123
|
+
|
|
124
|
+
let loading = $state(false);
|
|
125
|
+
let list = $state.raw<ListItem[]>(initList);
|
|
126
|
+
|
|
127
|
+
const handleSearch = (inputValue: string) => {
|
|
128
|
+
loading = true;
|
|
129
|
+
const newList = inputValue ? initList.filter((item) => item.value.includes(inputValue)) : initList;
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
list = newList;
|
|
132
|
+
loading = false;
|
|
133
|
+
}, 1000);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const search = debounce(handleSearch, 200);
|
|
137
|
+
|
|
138
|
+
const handleSelect = (value: string | number | AutoCompleteDataItem) => {
|
|
139
|
+
console.log(value);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Unlike Select, this can return only a string, not a node
|
|
143
|
+
const renderSelectedItem = (item: ListItem) => item.value;
|
|
144
|
+
</script>
|
|
145
|
+
|
|
146
|
+
<AutoComplete aria-label="搜索" data={list} {loading} onSearch={search} onSelect={handleSelect} {renderSelectedItem} style="width: 250px">
|
|
147
|
+
{#snippet prefix()}
|
|
148
|
+
<IconSearch />
|
|
149
|
+
{/snippet}
|
|
150
|
+
{#snippet item(entry)}
|
|
151
|
+
{@const Icon = entry.item.icon}
|
|
152
|
+
<div style="display: flex; align-items: center">
|
|
153
|
+
<div style="font-size: 32px">
|
|
154
|
+
<Icon />
|
|
155
|
+
</div>
|
|
156
|
+
<div style="margin-inline-start: 12px">
|
|
157
|
+
<p>{entry.item.value}</p>
|
|
158
|
+
<p>{entry.item.label}</p>
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
{/snippet}
|
|
162
|
+
</AutoComplete>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Size
|
|
166
|
+
|
|
167
|
+
The size of the input box can be set by setting size, optional `small`, `default` (default), `large`
|
|
168
|
+
|
|
169
|
+
```svelte
|
|
170
|
+
<script lang="ts">
|
|
171
|
+
import { AutoComplete } from '@fibrae/semi-ui-svelte';
|
|
172
|
+
|
|
173
|
+
const data = [1, 2, 3, 4];
|
|
174
|
+
</script>
|
|
175
|
+
|
|
176
|
+
<div>
|
|
177
|
+
<AutoComplete {data} placeholder="small" size="small" style="width: 200px" />
|
|
178
|
+
<br />
|
|
179
|
+
<br />
|
|
180
|
+
<AutoComplete {data} placeholder="default" size="default" style="width: 200px" />
|
|
181
|
+
<br />
|
|
182
|
+
<br />
|
|
183
|
+
<AutoComplete {data} placeholder="large" size="large" style="width: 200px" />
|
|
184
|
+
</div>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### The position of the drop-down menu
|
|
188
|
+
|
|
189
|
+
The position of the drop-down menu can be set by setting position, and the optional values refer to Tooltip position
|
|
190
|
+
|
|
191
|
+
```svelte
|
|
192
|
+
<script lang="ts">
|
|
193
|
+
import { AutoComplete } from '@fibrae/semi-ui-svelte';
|
|
194
|
+
|
|
195
|
+
const domains = ['gmail.com', '163.com', 'qq.com'];
|
|
196
|
+
|
|
197
|
+
let data = $state<string[]>([]);
|
|
198
|
+
|
|
199
|
+
const change = (input: string) => {
|
|
200
|
+
data = input ? domains.map((domain) => `${input}@${domain}`) : [];
|
|
201
|
+
};
|
|
202
|
+
</script>
|
|
203
|
+
|
|
204
|
+
<div>
|
|
205
|
+
<AutoComplete {data} onSearch={change} placeholder="选项菜单在上方显示" position="top" style="width: 200px; margin: 10px" />
|
|
206
|
+
<AutoComplete {data} onSearch={change} placeholder="选项菜单在右侧显示" position="rightTop" style="width: 200px; margin: 10px" />
|
|
207
|
+
</div>
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Disabled
|
|
211
|
+
|
|
212
|
+
```svelte
|
|
213
|
+
<script lang="ts">
|
|
214
|
+
import { AutoComplete } from '@fibrae/semi-ui-svelte';
|
|
215
|
+
|
|
216
|
+
const data = [1, 2, 3, 4];
|
|
217
|
+
</script>
|
|
218
|
+
|
|
219
|
+
<AutoComplete {data} disabled placeholder="禁用下拉菜单" style="width: 200px" />
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Validate status
|
|
223
|
+
|
|
224
|
+
Different verification states can be set to show different styles
|
|
225
|
+
|
|
226
|
+
```svelte
|
|
227
|
+
<script lang="ts">
|
|
228
|
+
import { AutoComplete } from '@fibrae/semi-ui-svelte';
|
|
229
|
+
|
|
230
|
+
let warning = $state('ies');
|
|
231
|
+
let error = $state('ies');
|
|
232
|
+
let normal = $state('ies');
|
|
233
|
+
</script>
|
|
234
|
+
|
|
235
|
+
<AutoComplete aria-label="Warning status" bind:value={warning} validateStatus="warning" />
|
|
236
|
+
<br />
|
|
237
|
+
<br />
|
|
238
|
+
<AutoComplete aria-label="Error status" bind:value={error} validateStatus="error" />
|
|
239
|
+
<br />
|
|
240
|
+
<br />
|
|
241
|
+
<AutoComplete aria-label="Default status" bind:value={normal} />
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Custom empty content
|
|
245
|
+
|
|
246
|
+
Can set up custom display empty content
|
|
247
|
+
|
|
248
|
+
```svelte
|
|
249
|
+
<script lang="ts">
|
|
250
|
+
import { IllustrationNoContent } from '@fibrae/semi-icons-svelte/illustrations';
|
|
251
|
+
import { AutoComplete, Empty } from '@fibrae/semi-ui-svelte';
|
|
252
|
+
|
|
253
|
+
let data = $state<number[]>([]);
|
|
254
|
+
let loading = $state(false);
|
|
255
|
+
|
|
256
|
+
const fetchData = (input: string) => {
|
|
257
|
+
loading = true;
|
|
258
|
+
setTimeout(() => {
|
|
259
|
+
data = input ? Array.from({ length: 5 }, () => Math.random()) : [];
|
|
260
|
+
loading = false;
|
|
261
|
+
}, 1000);
|
|
262
|
+
};
|
|
263
|
+
</script>
|
|
264
|
+
|
|
265
|
+
<AutoComplete aria-label="搜索" {data} {loading} onSearch={fetchData}>
|
|
266
|
+
{#snippet emptyContent()}
|
|
267
|
+
<Empty style="padding: 12px; width: 300px">
|
|
268
|
+
{#snippet image()}
|
|
269
|
+
<IllustrationNoContent style="width: 150px; height: 150px" />
|
|
270
|
+
{/snippet}
|
|
271
|
+
{#snippet description()}暂无内容{/snippet}
|
|
272
|
+
</Empty>
|
|
273
|
+
{/snippet}
|
|
274
|
+
</AutoComplete>
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## API reference
|
|
278
|
+
|
|
279
|
+
**Props**
|
|
280
|
+
|
|
281
|
+
| Property | Description | Type | Default |
|
|
282
|
+
| - | - | - | - |
|
|
283
|
+
| autoAdjustOverflow | Whether the dropdown flips automatically when it would be clipped. | `boolean` | - |
|
|
284
|
+
| autofocus | Whether to focus the input after mount. | `boolean` | `false` |
|
|
285
|
+
| classNames | Class names of the inner parts, keyed by dropdown (the dropdown list, the role="listbox" element); values take anything class takes (string, array or object) and merge with the built-in classes. | `Partial<Record<AutoCompletePart, ClassValue>>` | - |
|
|
286
|
+
| clearIcon | Snippet for the custom clear icon, effective when showClear is true. | `Snippet` | - |
|
|
287
|
+
| data | Data source of the candidates: an array of strings, numbers or objects. An object item uses value as the picked value and label as its text (value when label is missing); its disabled, class, style and data-\* fields go to the matching row, where class takes a string, array or object and style is a string. Use the item snippet for markup. | `T[]` | `[]` |
|
|
288
|
+
| defaultActiveFirstOption | Whether the first candidate is highlighted when the panel opens, so that Enter picks it directly. | `boolean` | `false` |
|
|
289
|
+
| defaultOpen | Whether the dropdown panel is open on mount; AutoComplete has no controlled open state. | `boolean` | - |
|
|
290
|
+
| disabled | Whether the component is disabled. | `boolean` | - |
|
|
291
|
+
| dropdownMatchSelectWidth | Whether the minimum width of the dropdown equals the width of the input. | `boolean` | `true` |
|
|
292
|
+
| emptyContent | Snippet for the content shown in the dropdown when data is empty. | `Snippet` | - |
|
|
293
|
+
| insetLabel | Snippet for the inset label of the input; passing it counts as having content. It is not rendered, and does not name the component, when prefix or trigger is used. | `Snippet` | - |
|
|
294
|
+
| insetLabelId | The id of the insetLabel element, which names the combobox and the listbox. When omitted, the component generates one while an insetLabel is rendered. | `string` | - |
|
|
295
|
+
| item | Snippet for the content of a candidate row, receiving `{ item, index }`: item is the data item as given and index is its position among the rendered items; without it the row shows the label. | `Snippet<[AutoCompleteItemSnippetProps<T>]>` | - |
|
|
296
|
+
| loading | Whether the dropdown shows a loading spinner in place of the candidates and the empty content. | `boolean` | `false` |
|
|
297
|
+
| maxHeight | Maximum height of the dropdown list; a number is in px. | `string \| number` | `300` |
|
|
298
|
+
| motion | Whether the dropdown animates when it shows and hides. | `boolean` | `true` |
|
|
299
|
+
| onBlur | Called once when the focus leaves the input. | `(event: FocusEvent) => void` | - |
|
|
300
|
+
| onChange | Called when the input text changes or a candidate is picked. | `(value: string \| number) => void` | - |
|
|
301
|
+
| onClear | Called after the clear button is used. | `() => void` | - |
|
|
302
|
+
| onDropdownVisibleChange | Called when the dropdown shows or hides, with its visibility. | `(visible: boolean) => void` | - |
|
|
303
|
+
| onFocus | Called once when the focus enters the input. | `(event: FocusEvent) => void` | - |
|
|
304
|
+
| onSearch | Called as the user types, with the typed text. | `(inputValue: string) => void` | - |
|
|
305
|
+
| onSelect | Called when a candidate is picked, with its value, or with the item without internal fields when onSelectWithObject is set. | `(value: string \| number \| AutoCompleteDataItem) => void` | - |
|
|
306
|
+
| onSelectWithObject | A boolean attribute, not a callback: when true, onSelect receives the data item without internal fields instead of its value. | `boolean` | `false` |
|
|
307
|
+
| placeholder | Placeholder of the input. | `string` | - |
|
|
308
|
+
| position | Position of the dropdown; the values are those of the Tooltip position. Unset, it is bottomLeft, or bottomRight when the ConfigProvider direction is rtl. | `Position` | - |
|
|
309
|
+
| prefix | Snippet for the prefix of the input. | `Snippet` | - |
|
|
310
|
+
| renderSelectedItem | The text the input shows for a picked item; it must return a string. A string or number item receives `{ value, label }`, an object item the item itself. | `(option: AutoCompleteSelectedItem<T>) => string` | - |
|
|
311
|
+
| showClear | Whether to show the clear button when there is content. | `boolean` | `false` |
|
|
312
|
+
| size | Size of the input. | `Size` | - |
|
|
313
|
+
| stopPropagation | Whether click, mousedown and focus in/out events on the dropdown stop propagating. | `boolean \| string` | `true` |
|
|
314
|
+
| styles | Style strings of the inner parts, keyed like classNames; dropdown is merged with maxHeight and applied to the role="listbox" element. | `Partial<Record<AutoCompletePart, string>>` | - |
|
|
315
|
+
| suffix | Snippet for the suffix of the input. | `Snippet` | - |
|
|
316
|
+
| trigger | Snippet that replaces the input. Its parameters are value, inputValue, placeholder, disabled, autofocus, size, validateStatus, showClear, insetLabelId, onChange (updates the input text, calls onSearch and onChange and opens the list), onClear, onFocus, onBlur and controlAttrs (the aria-\* attributes given to the component, for the focusable element of the custom trigger). With it, id lands on the root element. | `Snippet<[AutoCompleteTriggerSnippetProps]>` | - |
|
|
317
|
+
| validateStatus | Validation status; it only affects the style. | `ValidateStatus` | `"default"` |
|
|
318
|
+
| value | Current value of the input, supports `bind:value`. Left out, the component manages it; a one-way `value={x}` only seeds it, and for a fully controlled input use the function binding `bind:value={get, set}`. There is no defaultValue. | `string \| number` | - |
|
|
319
|
+
|
|
320
|
+
**Methods**
|
|
321
|
+
|
|
322
|
+
| Method | Description | Type |
|
|
323
|
+
| - | - | - |
|
|
324
|
+
| blur | Removes focus from the input. | `() => void` |
|
|
325
|
+
| focus | Focuses the input. | `(options?: FocusOptions) => void` |
|
|
326
|
+
| getNativeElement | Returns the root div that wraps the input or the custom trigger. | `() => HTMLDivElement \| undefined` |
|
|
327
|
+
|
|
328
|
+
`id`, `name`, and `aria-describedby`, `aria-errormessage`, `aria-invalid`, `aria-label`, `aria-labelledby`, `aria-required` land on the input (`role="combobox"`), so a `<label for>` finds it. `class` (a string, array or object), `style` (a string), `data-*` and other undeclared attributes and event handlers (for example `onclick`) land on the root div, whose `tabindex` is fixed to `-1`; `onkeydown` runs after the component has handled the key. The lowercase `onfocus`, `onblur`, `onchange` and `onselect` are not native passthroughs; use the callbacks `onFocus`, `onBlur`, `onChange` and `onSelect`. With the `trigger` snippet there is no input: `id` lands on the root div, `name` lands nowhere, and the `aria-*` attributes reach the focusable element of the custom trigger through the `controlAttrs` parameter.
|
|
329
|
+
|
|
330
|
+
Object items of `data`:
|
|
331
|
+
|
|
332
|
+
| Field | Description | Type |
|
|
333
|
+
| - | - | - |
|
|
334
|
+
| value | The value after picking | `string \| number` |
|
|
335
|
+
| label | The text of the candidate, falling back to value; use the `item` snippet for markup | `string \| number` |
|
|
336
|
+
| disabled | Whether the candidate is disabled | `boolean` |
|
|
337
|
+
| class | Class of the candidate row | `string \| object \| array` |
|
|
338
|
+
| style | Style of the candidate row | `string` |
|
|
339
|
+
|
|
340
|
+
Other fields are kept as they are and show up in `item` of the `item` snippet and in the payload of `onSelect` (when `onSelectWithObject` is set). Fields starting with `data-` land on the candidate row. A string or number item reaches `renderSelectedItem` as `{ value, label }`.
|
|
341
|
+
|
|
342
|
+
## Accessibility
|
|
343
|
+
|
|
344
|
+
### Keyboard and Focus
|
|
345
|
+
|
|
346
|
+
- AutoComplete's input box has `role="combobox"` and is linked to the options panel through `aria-expanded`, `aria-controls`, `aria-autocomplete="list"` and `aria-activedescendant`
|
|
347
|
+
- 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). The listbox uses the same name source. AutoComplete has no default name: with none of these, name the input with `aria-label` or `aria-labelledby`; a `<label for>` names only the input and leaves the listbox unnamed
|
|
348
|
+
- AutoComplete's input box can be focused, and once focused, keyboard users can use `Up Arrow` or `Down Arrow` to open the options panel; when data is empty the panel shows emptyContent (nothing when it is not provided), and a loading spinner while loading
|
|
349
|
+
- AutoComplete also supports opening and closing panels via `Enter` key
|
|
350
|
+
- If the user sets the defaultActiveFirstOption property to true, the first option is highlighted by default when the options panel is opened
|
|
351
|
+
- If the drop-down menu is open:
|
|
352
|
+
- Use `Esc` to close the menu
|
|
353
|
+
- Use `Tab` to close the menu; the focus moves on to the next focusable element as usual
|
|
354
|
+
- Use `Up Arrow` or `Down Arrow` to toggle options; the highlighted option (the one `aria-activedescendant` points at) has `aria-selected="true"`
|
|
355
|
+
- The focused option can be selected with the `Enter` key and the panel will be collapsed
|
|
356
|
+
- After picking an option with the mouse, the focus stays in the input
|
|
357
|
+
- With `showClear` and a value, the clear button is the same as Input's: a native `button` named "Clear input" from the locale; from the input, `Tab` moves to it, and `Enter` or `Space` clears and puts the focus back in the input
|
|
358
|
+
|
|
359
|
+
## Content Guidelines
|
|
360
|
+
|
|
361
|
+
- Content needs to be presented clearly so that users can clearly perceive the options available
|
|
362
|
+
- Limit the number of options displayed at one time
|
|
363
|
+
|
|
364
|
+
## Design Token
|
|
365
|
+
|
|
366
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/input/auto-complete/>
|
|
367
|
+
|
|
368
|
+
## Changes from Semi Design
|
|
369
|
+
|
|
370
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
371
|
+
|
|
372
|
+
- 破坏性:AutoComplete 删除 `dropdownClassName`、`dropdownStyle`,改用 `classNames.dropdown`、`styles.dropdown`,落在 `role="listbox"` 元素上,样式与 `maxHeight` 合并且 `styles.dropdown` 优先。
|
|
373
|
+
- PinCode:格子间距改为逻辑属性;ConfigProvider 的 `direction` 为 `rtl` 时左右方向键反向(ArrowLeft 移到下一格)。
|
|
374
|
+
- 破坏性:AutoComplete 删除 `getPopupContainer`、`zIndex`、`AutoComplete.Option` 与 `children`(改用 `Select.Option`),删除深路径 `@fibrae/semi-ui-react/auto-complete/option`、`@fibrae/semi-foundation/auto-complete/optionFoundation`;`style.width` 不再复制为下拉最小宽度。
|
|
375
|
+
- 破坏性(类型):AutoComplete 的 `defaultValue` 收窄为 `string | number`,`onKeyDown` 参数改为 `KeyboardEvent<HTMLDivElement>`,删除 `mouseEnterDelay`、`mouseLeaveDelay`、`tabIndex`;输入框角色改为 combobox(按 textbox 查询的测试需改为 combobox),`id` 落在输入框上。
|
|
376
|
+
- 破坏性(类型):TagInput 的 `onFocus`、`onBlur` 参数改为 `React.FocusEvent<HTMLDivElement>`,`onInputChange` 第二个参数改为 `React.SyntheticEvent`,`value` 为 `string[] | null`,ref 为 `TagInputHandle { focus, blur }`;`AvatarState.hoverContent` 改为 `hovered: boolean`。
|
|
377
|
+
- 破坏性(类型):`@fibrae/semi-foundation/components/tag-input/foundation` 删除 `any` 别名 `TagInputCursorEvent`、`TagInputKeyboardEvent`、`TagInputMouseEvent`,改为 `TagInputKeyEvent`、`TagInputFocusEvent`、`TagInputClearEvent`;`TagInputFoundation`、`TagInputAdapter` 新增按键与焦点事件的类型参数 `KE`、`FE`,`notifyKeyDown`、`notifyFocus`、`notifyBlur` 的参数随之收窄。
|
|
378
|
+
- TagInput:`+N` 浮层、`suffix` 中的 Popover 等内部弹层里的按下、焦点与点击不结束也不进入激活状态,`+N` 浮层里的标签可以直接关闭(四个框架一致)。
|
|
379
|
+
- AutoComplete:对象数据项缺 `label` 时候选行显示 `value`(四个框架一致);数据项带 `show: false` 时,高亮项与 Enter 选中项是同一个可见项。`defaultActiveFirstOption` 高亮第一个可用项,首项禁用时不再停在禁用项上(与 Select 一致,四个框架一致)。
|
|
380
|
+
- 破坏性(样式钩子):TagInput 悬停改由 CSS `:hover` 提供,不再加 `semi-tagInput-hover` 类;删除 `semi-tagInput-clearBtn-invisible` 与 `semi-avatar-focus`。TagInput 清除按钮与拖拽句柄改为带名称(`TagInput.clear`、`TagInput.dragSort`)的原生 button,`onFocus`、`onBlur` 以整个组件为界。
|
|
381
|
+
- 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`,格子之间移动不触发。
|
|
382
|
+
- Avatar:`bottomSlot` 方形标签不换行,比头像宽时向两侧超出。
|
|
383
|
+
- Avatar:`border.motion` 的外圈动画只放大并淡出,边框粗细不再随动画变细到 0(原来每帧触发布局与重绘);删除 Sass 变量 `$animation_width-additionalBorder-end`。
|
|
384
|
+
- React、Vue、Solid:服务端渲染的 Avatar 图片在 hydration 前已加载失败时,hydration 后调用 `onError` 并显示文字(原来保留破图)。
|
|
385
|
+
- AutoComplete:受控值回显但没有匹配项时保留已输入的文本(四个框架一致)。
|
|
386
|
+
- AutoComplete:下拉中有可聚焦元素(`renderItem`、`emptyContent` 里的按钮或链接)时,方向键只移动高亮,焦点不再移入下拉。
|
|
387
|
+
- 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`。
|
|
388
|
+
- Solid 破坏性(类型):Avatar 的 `topSlot.text`、`bottomSlot.text` 改为 `AvatarSlotText`(`string | number | (() => JSX.Element)`,从包入口导出),自定义内容写成函数 `text: () => <IconPlus />`,只在标记实际显示时(预设尺寸,topSlot 另需圆形)调用;`render` 仍完全替换标记。
|
|
389
|
+
- Svelte:Avatar 的 `class`、`style`、`id` 等属性落在头像 span,存在包装层时 `style` 落在包装层;传了 `onclick` 才成为可聚焦的 button;`hoverMask`、`topSlotText`、`bottomSlotText` 是 snippet,整块替换写 `topSlot.render`、`bottomSlot.render`,`topSlot.style`、`bottomSlot.style` 是字符串;内容是文字还是元素在挂载后判定,服务端首帧一律按文字结构输出。
|
|
390
|
+
- Svelte 破坏性:AvatarGroup 不接受 Avatar 子节点,改用 `items`(每项是 Avatar 的属性,类型 `AvatarGroupItem`)加 `item` snippet(参数 `{ item, index }`,提供头像内的文字),组的 `size`、`shape` 覆盖数据项自己的值;`maxCount` 截断、`+N` 与其可访问名称在服务端首帧同步算出,默认 `+N` 的名称只列被隐藏项的 `alt`。`more` snippet 参数为 `{ restNumber, restAvatars }`,`restAvatars` 是被隐藏的完整数据项。不能再用 Tooltip 等包裹组内的单个头像,需要时在 `item` snippet 里包裹内容。
|
|
391
|
+
- Svelte:PinCode 的 `value` 可绑定,没有 `defaultValue`;回调为 `onChange`、`onComplete`、`onFocus`、`onBlur`;`autofocus` 默认 `false`;实例方法为 `focus(index)`、`blur(index)`;`id` 落在第一格,`name`、`insetLabel`、`insetLabelId` 被丢弃。
|
|
392
|
+
- Svelte:头像内容里弹层中的 Avatar 不继承 AvatarGroup 的 `size`、`shape`,也不是列表项。
|
|
393
|
+
- Svelte:TagInput 的 `value`、`inputValue` 可绑定,没有 `defaultValue`,把它们绑成 `undefined` 会清空内部状态(表单重置);回调是 `onChange`、`onInputChange(value, event)`、`onAdd`、`onRemove(value, index)`、`onExceed`、`onInputExceed`、`onFocus`、`onBlur`、`onKeyDown`。
|
|
394
|
+
- Svelte:snippet 有 `prefix`、`suffix`、`insetLabel`、`clearIcon`、`tag({ value, index, onClose })`,`tag` 返回空内容就不渲染该标签,不回落默认标签;`focus()`、`blur()` 经 `bind:this` 调用,没有 `TagInputHandle` 类型;`restTagsPopoverProps` 的类型去掉了 `content`、`child`、`children`。
|
|
395
|
+
- Svelte:`id`、`name`、`role`、`tabindex` 与全部 `aria-*` 落在内部 `<input>`(根元素是 `role="group"`),根元素上的 `onclick` 与组件自己的点击处理组合调用。
|
|
396
|
+
- Svelte:AutoComplete 的 `value` 可绑定,没有 `defaultValue`;`renderItem`、`triggerRender` 改为 `item`、`trigger` snippet(`trigger` 参数不含 `componentProps`),`prefix`、`suffix`、`insetLabel`、`clearIcon`、`emptyContent` 为 snippet,`insetLabel` 只要传了 snippet 就当作有内容。
|
|
397
|
+
- Svelte:回调为 `onChange`、`onSearch`、`onSelect`、`onClear`、`onFocus`、`onBlur`、`onDropdownVisibleChange`;`focus()`、`blur()`、`getNativeElement()` 经 `bind:this` 调用;数据项的 `class` 接受 clsx 值,`style` 与 `styles` 的值只接受字符串;`id`、`name`、`aria-*` 落在输入框,用 `trigger` 时 `id` 落在根元素。
|
|
398
|
+
- Avatar:`size`、`gap` 变化后重算文字缩放。
|
|
399
|
+
- 破坏性(类型):Avatar 图片加载失败时 `onError` 收到 error 事件,返回 `false` 保留破图:React 为 `(event: SyntheticEvent<HTMLImageElement>) => boolean | void`,Vue、Svelte 为 `(event: Event) => boolean | void`,Solid 的事件带 `currentTarget: HTMLImageElement`。
|