diff --git a/src/components/input/input.vue b/src/components/input/input.vue index 7cf98a2c..ea87d7a8 100644 --- a/src/components/input/input.vue +++ b/src/components/input/input.vue @@ -7,6 +7,10 @@ {{ textLength }}/{{ upperLimit }} + + + + @@ -15,7 +19,7 @@ :autocomplete="autocomplete" :spellcheck="spellcheck" ref="input" - :type="type" + :type="currentType" :class="inputClasses" :placeholder="placeholder" :disabled="disabled" @@ -180,6 +184,11 @@ showWordLimit: { type: Boolean, default: false + }, + // 4.0.0 + password: { + type: Boolean, + default: false } }, data () { @@ -188,10 +197,16 @@ prefixCls: prefixCls, slotReady: false, textareaStyles: {}, - isOnComposition: false + isOnComposition: false, + showPassword: false }; }, computed: { + currentType () { + let type = this.type; + if (type === 'password' && this.password && this.showPassword) type = 'text'; + return type; + }, prepend () { let state = false; if (this.type !== 'textarea') state = this.$slots.prepend !== undefined; @@ -350,6 +365,15 @@ if (this.disabled) return false; this.$refs.input.focus(); this.$emit('on-search', this.currentValue); + }, + handleToggleShowPassword () { + if (this.disabled) return false; + this.showPassword = !this.showPassword; + this.focus(); + const len = this.currentValue.length; + setTimeout(() => { + this.$refs.input.setSelectionRange(len, len); + }, 0); } }, watch: {