Skip to content

Commit 0eeae41

Browse files
pdanpdanrstoenescu
authored andcommitted
QAutocomplete and QSelect - start with keyboard cursor at -1 (fixes disabled first element in list) (quasarframework#1585)
1 parent a8c507f commit 0eeae41

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/components/autocomplete/QAutocomplete.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default {
9898
this.results = this.filter(terms, this.staticData)
9999
const popover = this.$refs.popover
100100
if (this.results.length) {
101-
this.__keyboardShow(this.$q.platform.is.desktop ? 0 : -1)
101+
this.__keyboardShow(-1)
102102
if (popover.showing) {
103103
popover.reposition()
104104
}
@@ -122,7 +122,7 @@ export default {
122122

123123
if (Array.isArray(results) && results.length > 0) {
124124
this.results = results
125-
this.__keyboardShow(this.$q.platform.is.desktop ? 0 : -1)
125+
this.__keyboardShow(-1)
126126
this.$refs.popover.show()
127127
return
128128
}
@@ -153,6 +153,9 @@ export default {
153153
__keyboardShowTrigger () {
154154
this.trigger()
155155
},
156+
__keyboardIsSelectableIndex (index) {
157+
return index > -1 && index < this.computedResults.length && !this.computedResults[index].disable
158+
},
156159
setValue (result) {
157160
const value = this.staticData ? result[this.staticData.field] : result.value
158161
const suffix = this.__inputDebounce ? 'Debounce' : ''
@@ -232,7 +235,8 @@ export default {
232235
key: result.id || JSON.stringify(result),
233236
'class': {
234237
active: this.keyboardIndex === index,
235-
'cursor-pointer': !result.disable
238+
'cursor-pointer': !result.disable,
239+
'text-faded': result.disable
236240
},
237241
props: { cfg: result },
238242
nativeOn: {

src/components/select/QSelect.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,16 @@ export default {
330330
},
331331
332332
__keyboardCalcIndex () {
333-
this.keyboardMoveDirection = true
334333
this.keyboardIndex = -1
335334
const sel = this.multiple ? this.selectedOptions.map(o => o.value) : [this.model]
336-
this.$nextTick(() => this.__keyboardShow(sel === void 0 ? 0 : Math.max(0, this.visibleOptions.findIndex(opt => sel.includes(opt.value)))))
335+
this.$nextTick(() => {
336+
const index = sel === void 0 ? -1 : Math.max(-1, this.visibleOptions.findIndex(opt => sel.includes(opt.value)))
337+
if (index > -1) {
338+
this.keyboardMoveDirection = true
339+
setTimeout(() => { this.keyboardMoveDirection = false }, 500)
340+
this.__keyboardShow(index)
341+
}
342+
})
337343
},
338344
__keyboardCustomKeyHandle (key, e) {
339345
switch (key) {

0 commit comments

Comments
 (0)