Skip to content

Commit f987f44

Browse files
pdanpdanrstoenescu
authored andcommitted
Qautocomplete tweaks - numeric parent, mouse focus, enterKey (quasarframework#1308)
* Tweak QAutocomplete to check for number in search and navigate from mouse position * Tweak QAutocomplete for number type parents and fix enterKey - don't set enterKey when the typed text is the same with the selected text
1 parent 40bb8a9 commit f987f44

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/components/autocomplete/QAutocomplete.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default {
7878
return
7979
}
8080

81-
const terms = this.__input.val
81+
const terms = [null, void 0].includes(this.__input.val) ? '' : String(this.__input.val)
8282
const searchId = uid()
8383
this.searchId = searchId
8484

@@ -144,8 +144,15 @@ export default {
144144
this.searchId = ''
145145
},
146146
setValue (result) {
147+
const value = this.staticData ? result[this.staticData.field] : result.value
147148
const suffix = this.__inputDebounce ? 'Debounce' : ''
148-
this[`__input${suffix}`].set(this.staticData ? result[this.staticData.field] : result.value)
149+
150+
if (this.inputEl && this.__input && !this.__input.hasFocus()) {
151+
this.inputEl.focus()
152+
}
153+
154+
this.enterKey = this.__input && value !== this.__input.val
155+
this[`__input${suffix}`].set(value)
149156

150157
this.$emit('selected', result)
151158
this.__clearSearch()
@@ -159,7 +166,6 @@ export default {
159166
)
160167
},
161168
setCurrentSelection () {
162-
this.enterKey = true
163169
if (this.selectedIndex >= 0 && this.selectedIndex < this.results.length) {
164170
this.setValue(this.results[this.selectedIndex])
165171
}
@@ -242,17 +248,20 @@ export default {
242248
h(QList, {
243249
props: {
244250
noBorder: true,
245-
link: true,
246251
separator: this.separator
247252
},
248253
style: this.computedWidth
249254
},
250255
this.computedResults.map((result, index) => h(QItemWrapper, {
251256
key: result.id || JSON.stringify(result),
252-
'class': { active: this.selectedIndex === index },
257+
'class': {
258+
active: this.selectedIndex === index,
259+
'cursor-pointer': !result.disable
260+
},
253261
props: { cfg: result },
254262
on: {
255-
click: () => { this.setValue(result) }
263+
mouseenter: () => { !result.disable && (this.selectedIndex = index) },
264+
click: () => { !result.disable && this.setValue(result) }
256265
}
257266
})))
258267
])

0 commit comments

Comments
 (0)