Skip to content

Commit 7e5e2e5

Browse files
committed
fix: autocomplete demo on Android 7.1 shows list 2 times quasarframework#320
1 parent 4c0a21d commit 7e5e2e5

File tree

2 files changed

+29
-40
lines changed

2 files changed

+29
-40
lines changed

dev/components/form/autocomplete.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default {
8888
search (terms, done) {
8989
setTimeout(() => {
9090
done(Utils.filter(terms, {field: 'value', list: parseCountries()}))
91-
}, 1000)
91+
}, 500)
9292
},
9393
selected (item) {
9494
Toast.create(`Selected suggestion "${item.label}"`)

src/vue-components/autocomplete/Autocomplete.vue

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
/>
88
</slot>
99
<q-popover ref="popover" :anchor-click="false">
10-
<div v-if="searching" class="row justify-center" :style="{minWidth: width, padding: '3px 10px'}">
11-
<spinner name="dots" :size="40"></spinner>
12-
</div>
13-
<div v-else class="list no-border" :class="{'item-delimiter': delimiter}" :style="computedWidth">
10+
<div class="list no-border" :class="{'item-delimiter': delimiter}" :style="computedWidth">
1411
<q-list-item
1512
v-for="(result, index) in computedResults"
1613
:item="result"
@@ -87,47 +84,39 @@ export default {
8784
methods: {
8885
trigger () {
8986
this.width = Utils.dom.width(this.inputEl) + 'px'
90-
this.$nextTick(() => {
91-
const searchId = Utils.uid()
92-
this.searchId = searchId
87+
const searchId = Utils.uid()
88+
this.searchId = searchId
9389
94-
if (this.model.length < this.minCharacters) {
95-
this.searchId = ''
96-
this.close()
97-
return
98-
}
90+
if (this.model.length < this.minCharacters) {
91+
this.searchId = ''
92+
this.close()
93+
return
94+
}
95+
96+
if (this.staticData) {
97+
this.searchId = ''
98+
this.results = Utils.filter(this.model, this.staticData)
99+
this.$refs.popover.open()
100+
return
101+
}
99102
100-
this.$refs.popover.close()
101-
setTimeout(() => {
102-
if (this.staticData) {
103-
this.searchId = ''
104-
this.results = Utils.filter(this.model, this.staticData)
105-
this.$refs.popover.open()
103+
this.$emit('search', this.model, results => {
104+
if (results && this.searchId === searchId) {
105+
this.searchId = ''
106+
if (this.results === results) {
106107
return
107108
}
108109
109-
this.$refs.popover.open()
110-
this.$emit('search', this.model, results => {
111-
if (results && this.searchId === searchId) {
112-
this.searchId = ''
113-
114-
if (Array.isArray(results) && results.length > 0) {
115-
this.$refs.popover.close()
116-
this.$nextTick(() => {
117-
this.results = results
118-
setTimeout(() => {
119-
if (this.$refs && this.$refs.popover) {
120-
this.$refs.popover.open()
121-
}
122-
}, 10)
123-
})
124-
return
125-
}
126-
127-
this.close()
110+
if (Array.isArray(results) && results.length > 0) {
111+
this.results = results
112+
if (this.$refs && this.$refs.popover) {
113+
this.$refs.popover.open()
128114
}
129-
})
130-
}, 10)
115+
return
116+
}
117+
118+
this.close()
119+
}
131120
})
132121
},
133122
close () {

0 commit comments

Comments
 (0)