22import { ref , onMounted , onUnmounted } from " vue" ;
33import { easySearch , isCommandPaletteOpen } from " $stores" ;
44import { debounce } from " $utils/debounce" ;
5+ import Input from " $lib/components/forms/Input.vue" ;
56
67interface Props {
78 onSearch? : () => void ;
@@ -10,7 +11,7 @@ interface Props {
1011const props = defineProps <Props >();
1112
1213const error = ref (" " );
13- const inputEl = ref <HTMLInputElement | null >(null );
14+ const inputEl = ref <InstanceType < typeof Input > | null >(null );
1415
1516const search = debounce (() => props .onSearch ?.(), 100 );
1617
@@ -37,10 +38,15 @@ function trySearch() {
3738 search ();
3839}
3940
41+ function getInputElement() {
42+ return inputEl .value ?.$el ?.querySelector (" input" ) as HTMLInputElement | null ;
43+ }
44+
4045function handleKeyDown(e : KeyboardEvent ) {
4146 if (isCommandPaletteOpen .value ) return ;
4247
43- const inputIsFocused = document .activeElement === inputEl .value ;
48+ const input = getInputElement ();
49+ const inputIsFocused = document .activeElement === input ;
4450 if (inputIsFocused ) return ;
4551
4652 if (e .key .length > 1 || / \p {C}/ u .test (e .key )) return ;
@@ -51,7 +57,7 @@ function handleKeyDown(e: KeyboardEvent) {
5157 return ;
5258 }
5359
54- inputEl . value ?.focus ();
60+ input ?.focus ();
5561}
5662
5763onMounted (() => {
@@ -76,39 +82,20 @@ function handleSubmit(e: Event) {
7682
7783<template >
7884 <form @submit =" handleSubmit" >
79- <input
85+ <Input
8086 ref =" inputEl"
8187 type =" text"
8288 placeholder =" Search..."
83- :value =" easySearch"
89+ :model-value =" easySearch"
90+ :error =" error"
91+ full-width
8492 @input =" handleInput"
8593 />
86-
87- <template v-if =" error " >
88- <br />
89- <span style =" color : red " >{{ error }}</span >
90- </template >
9194 </form >
9295</template >
9396
9497<style scoped>
95- input {
96- width : 90% ;
97- margin : 0 auto ;
98- border : 1px solid transparent ;
99- box-shadow : -3px 4px 2px #0000000f ;
100- }
101- :root [data-theme = " dark" ] input {
102- background-color : #151515 ;
103- color : white ;
104- border : 1px solid #6b6b6b ;
105- box-shadow : 1px 1px 1px 2px #0000006e ;
106- }
107- input ::-webkit-input-placeholder {
108- opacity : 0.5 ;
109- }
110- input :focus {
111- outline : 1px solid #a5b5ff ;
112- box-shadow : -3px 4px 2px #894aff0f ;
98+ form {
99+ width : 100% ;
113100}
114101 </style >
0 commit comments