From 026558682c284f63452748805ab6b389866be3e4 Mon Sep 17 00:00:00 2001 From: Arthur Denner Date: Tue, 13 Nov 2018 08:33:33 -0200 Subject: [PATCH] Autocomplete: add clearable prop (#12171) * Autocomplete: add clearable prop * Input: remove focus after clearing the value * Autocomplete: hide options after clearing the value --- examples/docs/en-US/input.md | 1 + packages/autocomplete/src/autocomplete.vue | 5 +++++ packages/input/src/input.vue | 1 - types/autocomplete.d.ts | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/docs/en-US/input.md b/examples/docs/en-US/input.md index c44fba1e..19ee9532 100644 --- a/examples/docs/en-US/input.md +++ b/examples/docs/en-US/input.md @@ -699,6 +699,7 @@ Search data from server-side. Attribute | Description | Type | Options | Default |----| ----| ----| ---- | -----| |placeholder| the placeholder of Autocomplete| string | — | — | +| clearable | whether to show clear button | boolean | — | false | |disabled | whether Autocomplete is disabled | boolean | — | false| | value-key | key name of the input suggestion object for display | string | — | value | |icon | icon name | string | — | — | diff --git a/packages/autocomplete/src/autocomplete.vue b/packages/autocomplete/src/autocomplete.vue index b5a5889a..4fa3e450 100644 --- a/packages/autocomplete/src/autocomplete.vue +++ b/packages/autocomplete/src/autocomplete.vue @@ -90,6 +90,10 @@ popperClass: String, popperOptions: Object, placeholder: String, + clearable: { + type: Boolean, + default: false + }, disabled: Boolean, name: String, size: String, @@ -195,6 +199,7 @@ this.$emit('blur', event); }, handleClear() { + this.activated = false; this.$emit('clear'); }, close(e) { diff --git a/packages/input/src/input.vue b/packages/input/src/input.vue index 78b8e80e..5c3254ba 100644 --- a/packages/input/src/input.vue +++ b/packages/input/src/input.vue @@ -330,7 +330,6 @@ this.$emit('change', ''); this.$emit('clear'); this.setCurrentValue(''); - this.focus(); } }, diff --git a/types/autocomplete.d.ts b/types/autocomplete.d.ts index 5d8589ba..a56e8f33 100644 --- a/types/autocomplete.d.ts +++ b/types/autocomplete.d.ts @@ -26,6 +26,9 @@ export declare class ElAutocomplete extends ElementUIComponent { /** The placeholder of Autocomplete */ placeholder: string + /** Whether to show clear button */ + clearable: boolean + /** Whether Autocomplete is disabled */ disabled: boolean