1- import { useTaskStore } from "@features/tasks/stores/taskStore" ;
21import { Cross2Icon , MagnifyingGlassIcon } from "@radix-ui/react-icons" ;
32import { IconButton , Kbd , TextField } from "@radix-ui/themes" ;
43import { useEffect , useRef } from "react" ;
@@ -9,26 +8,14 @@ interface TaskSearchProps {
98}
109
1110export function TaskSearch ( { value, onChange } : TaskSearchProps ) {
12- const isExpanded = useTaskStore ( ( state ) => state . isSearchExpanded ) ;
13- const setIsExpanded = useTaskStore ( ( state ) => state . setIsSearchExpanded ) ;
1411 const inputRef = useRef < HTMLInputElement > ( null ) ;
15- const shouldBeExpanded = isExpanded || value . length > 0 ;
16-
17- const handleExpand = ( ) => {
18- setIsExpanded ( true ) ;
19- setTimeout ( ( ) => inputRef . current ?. focus ( ) , 100 ) ;
20- } ;
2112
2213 const handleClear = ( ) => {
2314 onChange ( "" ) ;
2415 setTimeout ( ( ) => inputRef . current ?. focus ( ) , 0 ) ;
2516 } ;
2617
27- const handleBlur = ( ) => {
28- if ( value . length === 0 ) {
29- setIsExpanded ( false ) ;
30- }
31- } ;
18+
3219
3320 useEffect ( ( ) => {
3421 const handleKeyDown = ( e : KeyboardEvent ) => {
@@ -43,39 +30,25 @@ export function TaskSearch({ value, onChange }: TaskSearchProps) {
4330 return ;
4431 }
4532 e . preventDefault ( ) ;
46- setIsExpanded ( true ) ;
4733 setTimeout ( ( ) => inputRef . current ?. focus ( ) , 100 ) ;
4834 }
4935 } ;
5036
5137 window . addEventListener ( "keydown" , handleKeyDown ) ;
5238 return ( ) => window . removeEventListener ( "keydown" , handleKeyDown ) ;
53- } , [ setIsExpanded ] ) ;
39+ } , [ ] ) ;
5440
5541 return (
5642 < div
5743 className = "transition-all duration-200"
5844 style = { {
59- width : shouldBeExpanded ? "250px" : "32px ",
45+ width : "250px" ,
6046 } }
6147 >
62- { ! shouldBeExpanded ? (
63- < IconButton
64- size = "1"
65- variant = "outline"
66- color = "gray"
67- onClick = { handleExpand }
68- type = "button"
69- title = "Search tasks (⌘F)"
70- >
71- < MagnifyingGlassIcon />
72- </ IconButton >
73- ) : (
7448 < TextField . Root
7549 ref = { inputRef }
7650 value = { value }
7751 onChange = { ( e ) => onChange ( e . target . value ) }
78- onBlur = { handleBlur }
7952 placeholder = "Search tasks..."
8053 size = "1"
8154 >
@@ -100,7 +73,6 @@ export function TaskSearch({ value, onChange }: TaskSearchProps) {
10073 </ TextField . Slot >
10174 ) }
10275 </ TextField . Root >
103- ) }
10476 </ div >
10577 ) ;
10678}
0 commit comments