Fix Search Cancel button does not delete query text#1077
Fix Search Cancel button does not delete query text#1077Pratik5252 wants to merge 1 commit intoprocessing:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #949 where the search cancel button only cleared the visual input field without resetting the parent component's search state, causing stale results to reappear.
Key Changes:
- Added
onSearchChange("")call in theclearInput()function to properly synchronize the parent component's search state when the clear button is clicked
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (inputRef.current) { | ||
| inputRef.current.value = ""; | ||
| } | ||
| onSearchChange("") |
There was a problem hiding this comment.
Missing semicolon at the end of the statement. This file consistently uses semicolons throughout, as seen in lines 99, 105, and other statements in the codebase.
| onSearchChange("") | |
| onSearchChange(""); |
| if (inputRef.current) { | ||
| inputRef.current.value = ""; | ||
| } | ||
| onSearchChange("") |
There was a problem hiding this comment.
Consider adding a test for this bug fix to prevent regression. The test should verify that clicking the clear button resets both the input field and calls onSearchChange with an empty string. The repository has an established testing setup with vitest and testing-library (see test/components/CodeEmbed.test.tsx for reference), and this would be a good candidate for test coverage given it fixes a reported bug.
Fixes #949
Previous Behavior
When users clicked the X to clear the search input, the visual field was cleared but the search state in the parent component remained unchanged. This caused old search results to reappear when typing again.
Solution
Updated
clearInput()to callonSearchChange("")so the parent component's search state is properly reset along with the input field.