Skip to content

Commit dbe7fe7

Browse files
committed
feat: autocomplete add status
1 parent 6e1f306 commit dbe7fe7

File tree

5 files changed

+95
-1
lines changed

5 files changed

+95
-1
lines changed

components/auto-complete/demo/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<non-case-sensitive />
77
<certain-category />
88
<uncertain-category />
9+
<statusVue />
910
</demo-sort>
1011
</template>
1112

@@ -16,6 +17,7 @@ import Custom from './custom.vue';
1617
import NonCaseSensitive from './non-case-sensitive.vue';
1718
import CertainCategory from './certain-category.vue';
1819
import UncertainCategory from './uncertain-category.vue';
20+
import statusVue from './status.vue';
1921
2022
import CN from '../index.zh-CN.md';
2123
import US from '../index.en-US.md';
@@ -25,6 +27,7 @@ export default defineComponent({
2527
CN,
2628
US,
2729
components: {
30+
statusVue,
2831
Basic,
2932
Options,
3033
Custom,
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<docs>
2+
---
3+
order: 19
4+
version: 3.3.0
5+
title:
6+
zh-CN: 自定义状态
7+
en-US: Status
8+
---
9+
10+
## zh-CN
11+
12+
使用 `status` 为 AutoComplete 添加状态,可选 `error` 或者 `warning`。
13+
14+
## en-US
15+
16+
Add status to AutoComplete with `status`, which could be `error` or `warning`.
17+
18+
</docs>
19+
20+
<template>
21+
<a-space direction="vertical" style="width: 100%">
22+
<a-auto-complete
23+
v-model:value="value"
24+
:options="options"
25+
style="width: 200px"
26+
placeholder="input here"
27+
status="error"
28+
@select="onSelect"
29+
@search="onSearch"
30+
/>
31+
<a-auto-complete
32+
v-model:value="value1"
33+
:options="options"
34+
style="width: 200px"
35+
placeholder="input here"
36+
status="warning"
37+
allow-clear
38+
@select="onSelect"
39+
@search="onSearch"
40+
@clear="onClear"
41+
/>
42+
</a-space>
43+
</template>
44+
45+
<script lang="ts">
46+
import { defineComponent, ref, watch } from 'vue';
47+
48+
interface MockVal {
49+
value: string;
50+
}
51+
const mockVal = (str: string, repeat = 1): MockVal => {
52+
return {
53+
value: str.repeat(repeat),
54+
};
55+
};
56+
export default defineComponent({
57+
setup() {
58+
const value = ref('');
59+
const value1 = ref('');
60+
const options = ref<MockVal[]>([]);
61+
const onSearch = (searchText: string) => {
62+
console.log('searchText');
63+
options.value = !searchText
64+
? []
65+
: [mockVal(searchText), mockVal(searchText, 2), mockVal(searchText, 3)];
66+
};
67+
const onSelect = (value: string) => {
68+
console.log('onSelect', value);
69+
};
70+
watch(value, () => {
71+
console.log('value', value.value);
72+
});
73+
return {
74+
value,
75+
value1,
76+
options,
77+
onSearch,
78+
onSelect,
79+
onClear: () => {
80+
console.log('onClear');
81+
},
82+
};
83+
},
84+
});
85+
</script>

components/auto-complete/index.en-US.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The differences with Select are:
4040
| option | custom render option by slot | v-slot:option="{value, label, [disabled, key, title]}" | - | 3.0 |
4141
| options | Data source for autocomplete | [DataSourceItemType](https://github.com/vueComponent/ant-design-vue/blob/724d53b907e577cf5880c1e6742d4c3f924f8f49/components/auto-complete/index.vue#L9)\[] | | |
4242
| placeholder | placeholder of input | string | - | |
43+
| status | Set validation status | 'error' \| 'warning' | - | 3.3.0 |
4344
| v-model:value | selected option | string\|string\[]\|{ key: string, label: string\|vNodes }\|Array&lt;{ key: string, label: string\|vNodes }> | - | |
4445

4546
### events
@@ -52,6 +53,7 @@ The differences with Select are:
5253
| focus | Called when entering the component | function() | | |
5354
| search | Called when searching items. | function(value) | - | |
5455
| select | Called when a option is selected. param is option's value and option instance. | function(value, option) | | |
56+
| clear | Called when clear | function | - | 3.3.0 |
5557

5658
## Methods
5759

components/auto-complete/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Option from './Option';
77
import OptGroup from './OptGroup';
88
import omit from '../_util/omit';
99
import useConfigInject from '../_util/hooks/useConfigInject';
10+
import type { InputStatus } from '../_util/statusUtils';
1011

1112
function isSelectOptionOrSelectOptGroup(child: any): boolean {
1213
return child?.type?.isSelectOption || child?.type?.isSelectOptGroup;
@@ -30,6 +31,7 @@ export const autoCompleteProps = () => ({
3031
// optionLabelProp: PropTypes.string.def('children'),
3132
filterOption: { type: [Boolean, Function], default: false },
3233
defaultActiveFirstOption: { type: Boolean, default: true },
34+
status: String as PropType<InputStatus>,
3335
});
3436

3537
export type AutoCompleteProps = Partial<ExtractPropTypes<ReturnType<typeof autoCompleteProps>>>;

components/auto-complete/index.zh-CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,20 @@ cover: https://gw.alipayobjects.com/zos/alicdn/qtJm4yt45/AutoComplete.svg
4141
| option | 通过 option 插槽,自定义节点 | v-slot:option="{value, label, [disabled, key, title]}" | - | 3.0 |
4242
| options | 自动完成的数据源 | [DataSourceItemType](https://github.com/vueComponent/ant-design-vue/blob/724d53b907e577cf5880c1e6742d4c3f924f8f49/components/auto-complete/index.vue#L9)\[] | | |
4343
| placeholder | 输入框提示 | string \| slot | - | |
44+
| status | 设置校验状态 | 'error' \| 'warning' | - | 3.3.0 |
4445
| v-model:value | 指定当前选中的条目 | string\|string\[]\|{ key: string, label: string\|vNodes }\|Array&lt;{ key: string, label: string\|vNodes }> || |
4546

4647
### 事件
4748

4849
| 事件名称 | 说明 | 回调参数 | 版本 |
49-
| --- | --- | --- | --- |
50+
| --- | --- | --- | --- | --- |
5051
| blur | 失去焦点时的回调 | function() | |
5152
| change | 选中 option,或 input 的 value 变化时,调用此函数 | function(value) | |
5253
| dropdownVisibleChange | 展开下拉菜单的回调 | function(open) | |
5354
| focus | 获得焦点时的回调 | function() | |
5455
| search | 搜索补全项的时候调用 | function(value) | |
5556
| select | 被选中时调用,参数为选中项的 value 值 | function(value, option) | |
57+
| clear | 清除内容时回调 | function | - | 3.3.0 |
5658

5759
## 方法
5860

0 commit comments

Comments
 (0)