feat: disable autocomplete on inputs + keyboard navigation focus

This commit is contained in:
liyasthomas
2021-08-29 16:44:18 +05:30
parent ebd8f43219
commit 04f9428267
33 changed files with 66 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
<AppSearchEntry
v-for="(shortcut, shortcutIndex) in theOutput"
:key="`shortcut-${shortcutIndex}`"
:ref="`item-${shortcutIndex}`"
:shortcut="shortcut"
@action="$emit('action', shortcut.action)"
/>
@@ -62,6 +63,7 @@ export default {
outputHash: "",
theOutput: [],
cache: {},
currentItem: -1,
}
},
computed: {
@@ -119,6 +121,12 @@ export default {
immediate: true,
},
},
mounted() {
document.addEventListener("keydown", this.nextItem)
},
destroyed() {
document.removeEventListener("keydown", this.nextItem)
},
methods: {
async output(search) {
const that = this
@@ -196,6 +204,24 @@ export default {
const hex = val.toString(16).toUpperCase()
return `00000000${hex}`.slice(-8)
},
nextItem(e) {
if (e.keyCode === 38 && this.currentItem > 0) {
e.preventDefault()
this.currentItem--
this.$nextTick().then(() => {
this.$refs[`item-${this.currentItem}`][0].$el.focus()
})
} else if (
e.keyCode === 40 &&
this.currentItem < this.theOutput.length - 1
) {
e.preventDefault()
this.currentItem++
this.$nextTick().then(() => {
this.$refs[`item-${this.currentItem}`][0].$el.focus()
})
}
},
},
}
</script>

View File

@@ -6,6 +6,7 @@
v-model="search"
v-focus
type="text"
autocomplete="off"
name="command"
:placeholder="$t('app.type_a_command_search')"
class="

View File

@@ -23,7 +23,7 @@
<div class="flex flex-col my-4 mx-6">
<input
v-model="filterText"
type="search"
type="search" autocomplete="off"
class="
bg-primaryLight
border border-dividerLight