aboutsummaryrefslogtreecommitdiff
path: root/src/components/SearchBar.vue
diff options
context:
space:
mode:
authorGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-07-23 18:49:10 +0200
committerGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-07-23 18:49:10 +0200
commitab53048d5f6fdca7d00edbb79dee1a5409e6b11e (patch)
tree30b20235f48c689ad5f79058d2f9963b7e5d2b63 /src/components/SearchBar.vue
parentc3a302bc389a0e13aef4b14d5a9d3ec3a0d32729 (diff)
downloadit-tools-ab53048d5f6fdca7d00edbb79dee1a5409e6b11e.tar.gz
it-tools-ab53048d5f6fdca7d00edbb79dee1a5409e6b11e.tar.zst
it-tools-ab53048d5f6fdca7d00edbb79dee1a5409e6b11e.zip
feat(search): focus the search bar using Ctrl+K
Diffstat (limited to 'src/components/SearchBar.vue')
-rw-r--r--src/components/SearchBar.vue23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/components/SearchBar.vue b/src/components/SearchBar.vue
index da5bede..7305239 100644
--- a/src/components/SearchBar.vue
+++ b/src/components/SearchBar.vue
@@ -1,8 +1,9 @@
<script lang="ts" setup>
+import { tools } from '@/tools';
import { SearchRound } from '@vicons/material';
-import { computed, ref } from 'vue';
+import { useMagicKeys, whenever } from '@vueuse/core';
import { deburr } from 'lodash';
-import { tools } from '@/tools';
+import { computed, ref } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
@@ -28,6 +29,21 @@ function onSelect(path: string) {
router.push(path);
queryString.value = '';
}
+
+const focusTarget = ref();
+
+const keys = useMagicKeys({
+ passive: false,
+ onEventFired(e) {
+ if (e.ctrlKey && e.key === 'k' && e.type === 'keydown') {
+ e.preventDefault();
+ }
+ },
+});
+
+whenever(keys.ctrl_k, () => {
+ focusTarget.value.focus();
+});
</script>
<template>
@@ -40,9 +56,10 @@ function onSelect(path: string) {
>
<template #default="{ handleInput, handleBlur, handleFocus, value: slotValue }">
<n-input
+ ref="focusTarget"
round
clearable
- placeholder="Search a tool..."
+ placeholder="Search a tool... [Ctrl + K]"
:value="slotValue"
@input="handleInput"
@focus="handleFocus"