Commit 33c826ec166c2efbb40aef493f4810baf2214eb2
1 parent
de361437
fix #5150
Showing
2 changed files
with
49 additions
and
37 deletions
Show diff stats
examples/routers/auto-complete.vue
| 1 | <template> | 1 | <template> |
| 2 | - <div style="margin: 100px;width: 200px;"> | ||
| 3 | - <AutoComplete placement="top" transfer v-model="value" icon="ios-search" :data="data" @on-search="handleSearch" @on-change="hc" :filter-method="fm"> | ||
| 4 | - <!--<Option v-for="item in data" :value="item" :label="item" :key="item">--> | ||
| 5 | - <!--<span style="color: red">{{ item }}</span>--> | ||
| 6 | - <!--</Option>--> | ||
| 7 | - </AutoComplete> | ||
| 8 | - </div> | 2 | + <div style="margin: 100px;width: 200px;"> |
| 3 | + <auto-complete v-model="value" :data="data" :disabled="disabled"></auto-complete> | ||
| 4 | + </div> | ||
| 9 | </template> | 5 | </template> |
| 10 | <script> | 6 | <script> |
| 11 | - | ||
| 12 | - export default { | ||
| 13 | - props: { | ||
| 14 | - | ||
| 15 | - }, | ||
| 16 | - data () { | ||
| 17 | - return { | ||
| 18 | - value: '', | ||
| 19 | - data: [], | ||
| 20 | -// data: ['Burns Bay Road', 'Downing Street', 'Wall Street'] | ||
| 21 | - }; | ||
| 22 | - }, | ||
| 23 | - computed: {}, | ||
| 24 | - methods: { | ||
| 25 | - handleSearch (value) { | ||
| 26 | - this.data = !value ? [] : [ | ||
| 27 | - value + '@qq.com', | ||
| 28 | - value + '@sina.com', | ||
| 29 | - value + '@163.com' | ||
| 30 | - ] | ||
| 31 | - }, | ||
| 32 | - hc (v) { | ||
| 33 | -// console.log(v) | ||
| 34 | - }, | ||
| 35 | - fm (value, item) { | ||
| 36 | - return item.toUpperCase().indexOf(value.toUpperCase()) !== -1; | ||
| 37 | - } | ||
| 38 | - } | 7 | +export default { |
| 8 | + data() { | ||
| 9 | + return { | ||
| 10 | + value: "", | ||
| 11 | + disabled: false, | ||
| 12 | + data: [] | ||
| 39 | }; | 13 | }; |
| 40 | -</script> | ||
| 41 | \ No newline at end of file | 14 | \ No newline at end of file |
| 15 | + }, | ||
| 16 | + methods: {}, | ||
| 17 | + created() { | ||
| 18 | + setTimeout(() => { | ||
| 19 | + this.value = "1.0.0.5"; | ||
| 20 | + this.data = [ | ||
| 21 | + "12412515", | ||
| 22 | + "123444", | ||
| 23 | + "12355", | ||
| 24 | + "12345", | ||
| 25 | + "12312", | ||
| 26 | + "1234", | ||
| 27 | + "123", | ||
| 28 | + "111", | ||
| 29 | + "5.2.3.4", | ||
| 30 | + "1.2.3.4", | ||
| 31 | + "1.2.3.4.5", | ||
| 32 | + "1.2.3.4.5.6", | ||
| 33 | + "1.2.3.4.5.6.7", | ||
| 34 | + "1.0.0.8", | ||
| 35 | + "1.0.0.5", | ||
| 36 | + "whb-03" | ||
| 37 | + ]; | ||
| 38 | + // this.disabled = true; | ||
| 39 | + }, 1000); | ||
| 40 | + } | ||
| 41 | +}; | ||
| 42 | +</script> |
src/components/select/select.vue
| @@ -635,7 +635,18 @@ | @@ -635,7 +635,18 @@ | ||
| 635 | }, ANIMATION_TIMEOUT); | 635 | }, ANIMATION_TIMEOUT); |
| 636 | }, | 636 | }, |
| 637 | onQueryChange(query) { | 637 | onQueryChange(query) { |
| 638 | - if (query.length > 0 && query !== this.query) this.visible = true; | 638 | + if (query.length > 0 && query !== this.query) { |
| 639 | + // in 'AutoComplete', when set an initial value asynchronously, | ||
| 640 | + // the 'dropdown list' should be stay hidden. | ||
| 641 | + // [issue #5150] | ||
| 642 | + let isInputFocused = | ||
| 643 | + document.hasFocus && | ||
| 644 | + document.hasFocus() && | ||
| 645 | + document.activeElement === this.$el.querySelector('input'); | ||
| 646 | + | ||
| 647 | + this.visible = isInputFocused; | ||
| 648 | + } | ||
| 649 | + | ||
| 639 | this.query = query; | 650 | this.query = query; |
| 640 | this.unchangedQuery = this.visible; | 651 | this.unchangedQuery = this.visible; |
| 641 | this.filterQueryChange = true; | 652 | this.filterQueryChange = true; |