mirror of
https://github.com/tuna/mirror-web.git
synced 2025-12-25 20:32:46 +00:00
add back hotkey for searchbox
This commit is contained in:
parent
c10467b093
commit
95c919773e
|
|
@ -1,9 +1,27 @@
|
|||
<script setup>
|
||||
import { defineModel } from "vue";
|
||||
import { defineModel, ref, onMounted, onBeforeUnmount } from "vue";
|
||||
const model = defineModel({type: String, default: ""});
|
||||
|
||||
const inputRef = ref(null);
|
||||
|
||||
const onGlobalKeyPress = (e) => {
|
||||
if (e.key === "/" && document.activeElement !== inputRef.value) {
|
||||
e.preventDefault();
|
||||
inputRef.value.focus();
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener("keypress", onGlobalKeyPress);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("keypress", onGlobalKeyPress);
|
||||
});
|
||||
|
||||
</script>
|
||||
<template>
|
||||
<input type="search" v-model="model" placeholder="按 / 搜索" autocomplete="off" class="ms-auto d-inline-flex align-self-center">
|
||||
<input type="search" v-model="model" ref="inputRef" placeholder="按 / 搜索" autocomplete="off" class="ms-auto d-inline-flex align-self-center">
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
|||
Loading…
Reference in New Issue