autocomplete-suggestions.vue
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
<transition name="el-zoom-in-top" @after-leave="doDestroy">
<div
v-show="showPopper"
class="el-autocomplete-suggestion el-popper"
:class="{ 'is-loading': !parent.hideLoading && parent.loading }"
:style="{ width: dropdownWidth }"
role="region">
<el-scrollbar
tag="ul"
wrap-class="el-autocomplete-suggestion__wrap"
view-class="el-autocomplete-suggestion__list">
<li v-if="!parent.hideLoading && parent.loading"><i class="el-icon-loading"></i></li>
<slot v-else>
</slot>
</el-scrollbar>
</div>
</transition>
</template>
<script>
import Popper from 'element-ui/src/utils/vue-popper';
import Emitter from 'element-ui/src/mixins/emitter';
import ElScrollbar from 'element-ui/packages/scrollbar';
export default {
components: { ElScrollbar },
mixins: [Popper, Emitter],
componentName: 'ElAutocompleteSuggestions',
data() {
return {
parent: this.$parent,
dropdownWidth: ''
};
},
props: {
options: {
default() {
return {
gpuAcceleration: false
};
}
},
id: String
},
methods: {
select(item) {
this.dispatch('ElAutocomplete', 'item-click', item);
}
},
updated() {
this.$nextTick(_ => {
this.popperJS && this.updatePopper();
});
},
mounted() {
this.$parent.popperElm = this.popperElm = this.$el;
this.referenceElm = this.$parent.$refs.input.$refs.input;
this.referenceList = this.$el.querySelector('.el-autocomplete-suggestion__list');
this.referenceList.setAttribute('role', 'listbox');
this.referenceList.setAttribute('id', this.id);
},
created() {
this.$on('visible', (val, inputWidth) => {
this.dropdownWidth = inputWidth + 'px';
this.showPopper = val;
});
}
};
</script>