Input: fix invalid resize prop (#2838)

pull/2864/head
kingwl 2017-02-16 02:53:33 -06:00 committed by baiyaaaaa
parent 00fcf06e94
commit 8e34408d6e
3 changed files with 30 additions and 10 deletions

View File

@ -1,5 +1,3 @@
import merge from 'element-ui/src/utils/merge';
let hiddenTextarea; let hiddenTextarea;
const HIDDEN_STYLE = ` const HIDDEN_STYLE = `
@ -55,8 +53,7 @@ function calculateNodeStyling(node) {
export default function calcTextareaHeight( export default function calcTextareaHeight(
targetNode, targetNode,
minRows = null, minRows = null,
maxRows = null, maxRows = null
options = null
) { ) {
if (!hiddenTextarea) { if (!hiddenTextarea) {
hiddenTextarea = document.createElement('textarea'); hiddenTextarea = document.createElement('textarea');
@ -99,5 +96,5 @@ export default function calcTextareaHeight(
height = Math.min(maxHeight, height); height = Math.min(maxHeight, height);
} }
return merge({ height: height + 'px'}, options); return { height: height + 'px'};
}; };

View File

@ -76,6 +76,7 @@
<script> <script>
import emitter from 'element-ui/src/mixins/emitter'; import emitter from 'element-ui/src/mixins/emitter';
import calcTextareaHeight from './calcTextareaHeight'; import calcTextareaHeight from './calcTextareaHeight';
import merge from 'element-ui/src/utils/merge';
export default { export default {
name: 'ElInput', name: 'ElInput',
@ -87,7 +88,7 @@
data() { data() {
return { return {
currentValue: this.value, currentValue: this.value,
textareaStyle: {} textareaCalcStyle: {}
}; };
}, },
@ -132,6 +133,9 @@
computed: { computed: {
validating() { validating() {
return this.$parent.validateState === 'validating'; return this.$parent.validateState === 'validating';
},
textareaStyle() {
return merge({}, this.textareaCalcStyle, { resize: this.resize });
} }
}, },
@ -158,10 +162,7 @@
const minRows = autosize.minRows; const minRows = autosize.minRows;
const maxRows = autosize.maxRows; const maxRows = autosize.maxRows;
const options = { this.textareaCalcStyle = calcTextareaHeight(this.$refs.textarea, minRows, maxRows);
resize: this.resize
};
this.textareaStyle = calcTextareaHeight(this.$refs.textarea, minRows, maxRows, options);
}, },
handleFocus(event) { handleFocus(event) {
this.$emit('focus', event); this.$emit('focus', event);

View File

@ -105,6 +105,28 @@ describe('Input', () => {
expect(vm.$el.querySelector('.el-textarea__inner').getAttribute('rows')).to.be.equal('3'); expect(vm.$el.querySelector('.el-textarea__inner').getAttribute('rows')).to.be.equal('3');
}); });
// Github issue #2836
it('resize', done => {
vm = createVue({
template: `
<div>
<el-input type="textarea" :resize="resize"></el-input>
</div>
`,
data: {
resize: 'none'
}
}, true);
vm.$nextTick(() => {
expect(vm.$el.querySelector('.el-textarea__inner').style.resize).to.be.equal(vm.resize);
vm.resize = 'horizontal';
vm.$nextTick(() => {
expect(vm.$el.querySelector('.el-textarea__inner').style.resize).to.be.equal(vm.resize);
done();
});
});
});
it('autosize', done => { it('autosize', done => {
vm = createVue({ vm = createVue({
template: ` template: `