Autocomplete (自动完成)
组合框:文本输入 + 过滤建议列表(v-model 字符串);支持 allowCustomValue 与手动过滤。
基础用法
Basic.vue
自定义值
值: —
CustomValue.vue
可清除
Clearable.vue
错误 / 禁用
请选择一个有效城市
ErrorDisabled.vue
颜色
Colors.vue
远程搜索(loading + debounce)
confirmed value: —
RemoteSearch.vue
自定义选项(#option 插槽)
CustomOption.vue
属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| options * | readonly KunAutocompleteOption[] | — | |
| allowCustomValue | boolean | true | Accept a value the user typed that is not in `options` (free text). |
| ariaLabel | string | "" | |
| clearable | boolean | false | |
| color | KunUIColor | "default" | Focus-ring accent (the resting border/text stay neutral). Default 'default'. |
| darkBorder | boolean | true | Legacy dark-mode border toggle. |
| debounce | number | 0 | Debounce the `@search` emit by N ms; the input text still updates instantly (a responsive field). 0 (default) emits on every keystroke — set e.g. 300 for remote sources so you fetch once the user pauses, not per keypress. |
| description | string | "" | Helper text below the field (hidden when `error` is set). |
| disabled | boolean | false | |
| error | string | "" | |
| isInvalid | boolean | false | |
| label | string | "" | |
| loading | boolean | false | Async data source: show a loading spinner in the dropdown (instead of `noResultText`) while a remote `@search` request is in flight. Drive it from your fetch — set true when the request starts, false when the results land. |
| loadingText | string | "加载中…" | Text under the loading spinner. Default '加载中…'. |
| manualFilter | boolean | false | Skip built-in label filtering — you control `options` from `@search` (remote/async suggestions). Default false (client-side filter). |
| modelValue | string | "" | |
| name | string | — | |
| noResultText | string | "无匹配项" | |
| placeholder | string | "" | |
| rounded | KunUIRounded | — | Corner radius. When unset it follows the nearest KunUIConfigProvider's `rounded`. `full` means a pill, which is only defined for the single-line trigger — the floating panel falls back to `lg`, because `9999px` on an n-row panel is clamped by the browser to half its short side. Every other bucket applies to both. |
| size | KunUISize | "md" |
事件
| 事件 | 回调参数 | 说明 |
|---|---|---|
| search | query: string | The field text, debounced by `debounce`. One emit per committed word during IME composition, not one per romaji keystroke. |
| select | option: KunAutocompleteOption | The option the user committed by click or Enter. Free text accepted through `allowCustomValue` does not emit it. |
| update:modelValue | value: string |
插槽
| 插槽 | 作用域 |
|---|---|
| #option | { option: KunAutocompleteOption; index: number; active: boolean; selected: boolean; } |