mirror of https://github.com/ElemeFE/element
input: fix focus
parent
2884984097
commit
c7d3de95b0
|
@ -77,7 +77,6 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import emitter from 'element-ui/src/mixins/emitter';
|
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 Migrating from 'element-ui/src/mixins/migrating';
|
||||||
import calcTextareaHeight from './calcTextareaHeight';
|
import calcTextareaHeight from './calcTextareaHeight';
|
||||||
import merge from 'element-ui/src/utils/merge';
|
import merge from 'element-ui/src/utils/merge';
|
||||||
|
@ -87,7 +86,7 @@
|
||||||
|
|
||||||
componentName: 'ElInput',
|
componentName: 'ElInput',
|
||||||
|
|
||||||
mixins: [emitter, Focus('input'), Migrating],
|
mixins: [emitter, Migrating],
|
||||||
|
|
||||||
inject: {
|
inject: {
|
||||||
elForm: {
|
elForm: {
|
||||||
|
@ -183,6 +182,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
focus() {
|
||||||
|
(this.$refs.input || this.$refs.textarea).focus();
|
||||||
|
},
|
||||||
getMigratingConfig() {
|
getMigratingConfig() {
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
@ -201,7 +203,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
inputSelect() {
|
inputSelect() {
|
||||||
this.$refs.input.select();
|
(this.$refs.input || this.$refs.textarea).select();
|
||||||
},
|
},
|
||||||
resizeTextarea() {
|
resizeTextarea() {
|
||||||
if (this.$isServer) return;
|
if (this.$isServer) return;
|
||||||
|
|
|
@ -99,15 +99,30 @@ describe('MessageBox', () => {
|
||||||
inputErrorMessage: 'validation failed'
|
inputErrorMessage: 'validation failed'
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(document.querySelector('.el-message-box__input')).to.exist;
|
|
||||||
const messageBox = document.querySelector('.el-message-box__wrapper').__vue__.$parent;
|
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';
|
messageBox.inputValue = 'no';
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(document.querySelector('.el-message-box__errormsg')
|
expect(messageBox.$el.querySelector('.el-message-box__errormsg')
|
||||||
.textContent).to.equal('validation failed');
|
.textContent).to.equal('validation failed');
|
||||||
done();
|
done();
|
||||||
}, 100);
|
}, 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', () => {
|
describe('custom validator', () => {
|
||||||
|
|
Loading…
Reference in New Issue