mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-21 07:16:15 -04:00
feat(search): focus the search bar using Ctrl+K
This commit is contained in:
parent
c3a302bc38
commit
ab53048d5f
1 changed files with 21 additions and 4 deletions
|
@ -1,8 +1,9 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { SearchRound } from '@vicons/material';
|
|
||||||
import { computed, ref } from 'vue';
|
|
||||||
import { deburr } from 'lodash';
|
|
||||||
import { tools } from '@/tools';
|
import { tools } from '@/tools';
|
||||||
|
import { SearchRound } from '@vicons/material';
|
||||||
|
import { useMagicKeys, whenever } from '@vueuse/core';
|
||||||
|
import { deburr } from 'lodash';
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
@ -28,6 +29,21 @@ function onSelect(path: string) {
|
||||||
router.push(path);
|
router.push(path);
|
||||||
queryString.value = '';
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -40,9 +56,10 @@ function onSelect(path: string) {
|
||||||
>
|
>
|
||||||
<template #default="{ handleInput, handleBlur, handleFocus, value: slotValue }">
|
<template #default="{ handleInput, handleBlur, handleFocus, value: slotValue }">
|
||||||
<n-input
|
<n-input
|
||||||
|
ref="focusTarget"
|
||||||
round
|
round
|
||||||
clearable
|
clearable
|
||||||
placeholder="Search a tool..."
|
placeholder="Search a tool... [Ctrl + K]"
|
||||||
:value="slotValue"
|
:value="slotValue"
|
||||||
@input="handleInput"
|
@input="handleInput"
|
||||||
@focus="handleFocus"
|
@focus="handleFocus"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue