@@ -116,7 +116,7 @@ export function FilterBar({
116116 setIsSearchManuallyExpanded ( true ) ;
117117 setDropdownAnchor ( searchContainerRef . current ) ;
118118 setTimeout ( ( ) => inputRef . current ?. focus ( ) , 0 ) ;
119- } , [ ] ) ;
119+ } , [ inputRef ] ) ;
120120
121121 // Collapse when empty and loses focus (only if there are filters)
122122 const handleSearchBlur = useCallback ( ( ) => {
@@ -133,15 +133,17 @@ export function FilterBar({
133133 setDropdownAnchor ( null ) ;
134134 setSelectedCategory ( null ) ;
135135 setSearchQuery ( '' ) ;
136+ setHighlightedIndex ( - 1 ) ;
136137 setIsSearchManuallyExpanded ( false ) ;
137138 } , [ ] ) ;
138139
139140 // Select category from dropdown
140141 const handleCategorySelect = useCallback ( ( category : FilterCategory ) => {
141142 setSelectedCategory ( category ) ;
142143 setSearchQuery ( '' ) ;
144+ setHighlightedIndex ( - 1 ) ;
143145 setTimeout ( ( ) => inputRef . current ?. focus ( ) , 50 ) ;
144- } , [ ] ) ;
146+ } , [ inputRef ] ) ;
145147
146148 // Select value (add new filter group)
147149 const handleValueSelect = useCallback (
@@ -153,14 +155,15 @@ export function FilterBar({
153155 }
154156 setSelectedCategory ( null ) ;
155157 setSearchQuery ( '' ) ;
158+ setHighlightedIndex ( - 1 ) ;
156159 // Keep expanded and focused for next filter
157160 setIsSearchManuallyExpanded ( true ) ;
158161 setTimeout ( ( ) => {
159162 setDropdownAnchor ( searchContainerRef . current ) ;
160163 inputRef . current ?. focus ( ) ;
161164 } , 50 ) ;
162165 } ,
163- [ onAddFilter , onTrackEvent , searchQuery ]
166+ [ onAddFilter , onTrackEvent , searchQuery , inputRef ]
164167 ) ;
165168
166169 // Chip click - open chip menu
@@ -265,11 +268,6 @@ export function FilterBar({
265268
266269 const dropdownItems = getDropdownItems ( ) ;
267270
268- // Reset highlight when dropdown content changes
269- useEffect ( ( ) => {
270- setHighlightedIndex ( - 1 ) ;
271- } , [ searchQuery , selectedCategory , dropdownAnchor ] ) ;
272-
273271 // Handle keyboard navigation
274272 const handleKeyDown = useCallback (
275273 ( event : React . KeyboardEvent ) => {
@@ -295,7 +293,7 @@ export function FilterBar({
295293 inputRef . current ?. blur ( ) ;
296294 }
297295 } ,
298- [ dropdownItems , highlightedIndex , handleCategorySelect , handleValueSelect , handleDropdownClose ]
296+ [ dropdownItems , highlightedIndex , handleCategorySelect , handleValueSelect , handleDropdownClose , inputRef ]
299297 ) ;
300298
301299 // Get active group for chip menu
@@ -471,6 +469,7 @@ export function FilterBar({
471469 value = { searchQuery }
472470 onChange = { ( e ) => {
473471 setSearchQuery ( e . target . value ) ;
472+ setHighlightedIndex ( - 1 ) ;
474473 if ( ! dropdownAnchor ) {
475474 setDropdownAnchor ( searchContainerRef . current ) ;
476475 }
@@ -480,6 +479,7 @@ export function FilterBar({
480479 setIsSearchManuallyExpanded ( true ) ;
481480 }
482481 setDropdownAnchor ( searchContainerRef . current ) ;
482+ setHighlightedIndex ( - 1 ) ;
483483 } }
484484 onBlur = { handleSearchBlur }
485485 onKeyDown = { handleKeyDown }
0 commit comments