forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dsl101/patch-4
Create KeyboardAcceleration.vue
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |