mirror of https://github.com/ElemeFE/element
parent
84c81ff9f9
commit
ed72c389fc
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="el-autocomplete">
|
<div class="el-autocomplete" v-clickoutside="close">
|
||||||
<el-input
|
<el-input
|
||||||
ref="input"
|
ref="input"
|
||||||
:value="value"
|
:value="value"
|
||||||
|
@ -14,7 +14,6 @@
|
||||||
@compositionend.native="handleComposition"
|
@compositionend.native="handleComposition"
|
||||||
@change="handleChange"
|
@change="handleChange"
|
||||||
@focus="handleFocus"
|
@focus="handleFocus"
|
||||||
@blur="handleBlur"
|
|
||||||
@keydown.up.native.prevent="highlight(highlightedIndex - 1)"
|
@keydown.up.native.prevent="highlight(highlightedIndex - 1)"
|
||||||
@keydown.down.native.prevent="highlight(highlightedIndex + 1)"
|
@keydown.down.native.prevent="highlight(highlightedIndex + 1)"
|
||||||
@keydown.enter.native.prevent="handleKeyEnter"
|
@keydown.enter.native.prevent="handleKeyEnter"
|
||||||
|
@ -37,6 +36,7 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import ElInput from 'element-ui/packages/input';
|
import ElInput from 'element-ui/packages/input';
|
||||||
|
import Clickoutside from 'element-ui/src/utils/clickoutside';
|
||||||
import ElAutocompleteSuggestions from './autocomplete-suggestions.vue';
|
import ElAutocompleteSuggestions from './autocomplete-suggestions.vue';
|
||||||
import Emitter from 'element-ui/src/mixins/emitter';
|
import Emitter from 'element-ui/src/mixins/emitter';
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@
|
||||||
ElAutocompleteSuggestions
|
ElAutocompleteSuggestions
|
||||||
},
|
},
|
||||||
|
|
||||||
|
directives: { Clickoutside },
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
props: {
|
props: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
@ -133,11 +135,8 @@
|
||||||
this.getData(this.value);
|
this.getData(this.value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleBlur() {
|
close() {
|
||||||
// 因为 blur 事件处理优先于 select 事件执行
|
|
||||||
setTimeout(_ => {
|
|
||||||
this.isFocus = false;
|
this.isFocus = false;
|
||||||
}, 100);
|
|
||||||
},
|
},
|
||||||
handleKeyEnter() {
|
handleKeyEnter() {
|
||||||
if (this.suggestionVisible && this.highlightedIndex >= 0 && this.highlightedIndex < this.suggestions.length) {
|
if (this.suggestionVisible && this.highlightedIndex >= 0 && this.highlightedIndex < this.suggestions.length) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { createVue, destroyVM } from '../util';
|
import { createVue, triggerClick, destroyVM } from '../util';
|
||||||
|
|
||||||
describe('Autocomplete', () => {
|
describe('Autocomplete', () => {
|
||||||
let vm;
|
let vm;
|
||||||
|
@ -59,11 +59,11 @@ describe('Autocomplete', () => {
|
||||||
expect(suggestions.style.display).to.not.equal('none');
|
expect(suggestions.style.display).to.not.equal('none');
|
||||||
expect(suggestions.querySelectorAll('.el-autocomplete-suggestion__list li').length).to.be.equal(4);
|
expect(suggestions.querySelectorAll('.el-autocomplete-suggestion__list li').length).to.be.equal(4);
|
||||||
|
|
||||||
inputElm.blur();
|
triggerClick(document);
|
||||||
setTimeout(_ => {
|
setTimeout(_ => {
|
||||||
expect(suggestions.style.display).to.be.equal('none');
|
expect(suggestions.style.display).to.be.equal('none');
|
||||||
done();
|
done();
|
||||||
}, 600);
|
}, 500);
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
it('select', done => {
|
it('select', done => {
|
||||||
|
|
Loading…
Reference in New Issue