Input: update DOM dependent values on type change (#14889)

fix #14857
pull/14939/head
Jiewei Qian 2019-04-02 12:19:32 +08:00 committed by hetech
parent 6298958c19
commit d38ab315fa
2 changed files with 32 additions and 0 deletions

View File

@ -233,6 +233,16 @@
// see: https://github.com/ElemeFE/element/issues/14521 // see: https://github.com/ElemeFE/element/issues/14521
nativeInputValue() { nativeInputValue() {
this.setNativeInputValue(); this.setNativeInputValue();
},
// when change between <input> and <textarea>,
// update DOM dependent value and styles
// https://github.com/ElemeFE/element/issues/14857
type() {
this.$nextTick(() => {
this.setNativeInputValue();
this.resizeTextarea();
this.updateIconOffset();
});
} }
}, },

View File

@ -394,4 +394,26 @@ describe('Input', () => {
expect(vm.$refs.inputComp.$refs.input.selectionEnd).to.equal(testContent.length); expect(vm.$refs.inputComp.$refs.input.selectionEnd).to.equal(testContent.length);
}); });
}); });
it('sets value on textarea / input type change', async() => {
vm = createVue({
template: `
<el-input :type="type" v-model="val" />
`,
data() {
return {
type: 'text',
val: '123'
};
}
}, true);
expect(vm.$el.querySelector('input').value).to.equal('123');
vm.type = 'textarea';
await waitImmediate();
expect(vm.$el.querySelector('textarea').value).to.equal('123');
vm.type = 'password';
await waitImmediate();
expect(vm.$el.querySelector('input').value).to.equal('123');
});
}); });