input: fix focus

pull/8283/head
wacky6.AriesMBP 2017-11-15 14:12:41 +11:00 committed by 杨奕
parent 2884984097
commit c7d3de95b0
2 changed files with 23 additions and 6 deletions

View File

@ -77,7 +77,6 @@
</template>
<script>
import emitter from 'element-ui/src/mixins/emitter';
import Focus from 'element-ui/src/mixins/focus';
import Migrating from 'element-ui/src/mixins/migrating';
import calcTextareaHeight from './calcTextareaHeight';
import merge from 'element-ui/src/utils/merge';
@ -87,7 +86,7 @@
componentName: 'ElInput',
mixins: [emitter, Focus('input'), Migrating],
mixins: [emitter, Migrating],
inject: {
elForm: {
@ -183,6 +182,9 @@
},
methods: {
focus() {
(this.$refs.input || this.$refs.textarea).focus();
},
getMigratingConfig() {
return {
props: {
@ -201,7 +203,7 @@
}
},
inputSelect() {
this.$refs.input.select();
(this.$refs.input || this.$refs.textarea).select();
},
resizeTextarea() {
if (this.$isServer) return;

View File

@ -99,15 +99,30 @@ describe('MessageBox', () => {
inputErrorMessage: 'validation failed'
});
setTimeout(() => {
expect(document.querySelector('.el-message-box__input')).to.exist;
const messageBox = document.querySelector('.el-message-box__wrapper').__vue__.$parent;
expect(messageBox.$el.querySelector('.el-message-box__input')).to.exist;
const haveFocus = messageBox.$el.querySelector('input').isSameNode(document.activeElement);
expect(haveFocus).to.true;
messageBox.inputValue = 'no';
setTimeout(() => {
expect(document.querySelector('.el-message-box__errormsg')
expect(messageBox.$el.querySelector('.el-message-box__errormsg')
.textContent).to.equal('validation failed');
done();
}, 100);
}, 200);
}, 700);
});
it('prompt: focus on textarea', done => {
MessageBox.prompt('这是一段内容', {
inputType: 'textarea',
title: '标题名称'
});
setTimeout(() => {
const messageBox = document.querySelector('.el-message-box__wrapper').__vue__.$parent;
const haveFocus = messageBox.$el.querySelector('textarea').isSameNode(document.activeElement);
expect(haveFocus).to.true;
done();
}, 700);
});
describe('custom validator', () => {