mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-06 02:26:49 +00:00
39 lines
1 KiB
Vue
39 lines
1 KiB
Vue
<template>
|
|
<label
|
|
class="input input-bordered input-primary flex items-center gap-2 container mx-auto px-4 lg:px-8 my-4"
|
|
>
|
|
<input
|
|
v-model="model"
|
|
type="text"
|
|
class="grow"
|
|
placeholder="Search recipes..."
|
|
@focus="isFocused = true"
|
|
@blur="isFocused = false"
|
|
@keydown.enter="$emit('search')"
|
|
>
|
|
<kbd class="kbd kbd-sm" :class="{ 'opacity-50': !isFocused }">⌘</kbd>
|
|
<kbd class="kbd kbd-sm" :class="{ 'opacity-50': !isFocused }">K</kbd>
|
|
</label>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
defineEmits(["search"]);
|
|
const model = defineModel<string>();
|
|
|
|
const isFocused = ref(false);
|
|
|
|
onMounted(() => {
|
|
const handleKeydown = (e: KeyboardEvent) => {
|
|
if ((e.metaKey || e.ctrlKey) && e.key === "k") {
|
|
e.preventDefault();
|
|
const inputEl = document.querySelector("input");
|
|
inputEl?.focus();
|
|
}
|
|
};
|
|
|
|
window.addEventListener("keydown", handleKeydown);
|
|
onUnmounted(() => {
|
|
window.removeEventListener("keydown", handleKeydown);
|
|
});
|
|
});
|
|
</script>
|