Skip to content

Commit

Permalink
Merge pull request #1 from dsl101/patch-4
Browse files Browse the repository at this point in the history
Create KeyboardAcceleration.vue
  • Loading branch information
dsl101 authored Jun 6, 2019
2 parents 1d040de + 6824734 commit 1cf8ef1
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions docs/src/examples/QSelect/KeyboardAcceleration.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<div class="q-pa-md">
<q-select
ref="qsel"
filled
v-model="model"
use-input
hide-selected
fill-input
input-debounce="0"
style="width: 250px"
:options="filterOptions"
@filter="filterFn"
@new-value="acceptOption"
@keydown.native.tab="acceptPartial"
/>
</div>
</template>

<script>
const stringOptions = [
'Google', 'Facebook', 'Twitter', 'Apple', 'Oracle'
]
export default {
data () {
return {
model: null,
partial: null,
filterOptions: stringOptions
}
},
methods: {
filterFn (val, update, abort) {
this.partial = val
update(() => {
const needle = val.toLowerCase()
this.options = stringOptions.filter(v => v.toLowerCase().indexOf(needle) > -1)
})
},
// On 'new-value' triggered by hitting Enter, if there is a single
// option in the filtered list, set the model to this value
acceptOption () {
if (this.$refs.qsel.options.length === 1) {
this.model = this.$refs.qsel.options[0]
this.partial = ''
}
},
// Any text entered so far is copied to the model when
// the user 'tabs' away from the control
acceptPartial () {
if (this.partial) {
this.model = this.partial
}
}
}
}
</script>

0 comments on commit 1cf8ef1

Please sign in to comment.