Skip to content

Commit

Permalink
fix(#1309791): [Example App] Reset SearchBar when I navigate on the d…
Browse files Browse the repository at this point in the history
…ifferent links
  • Loading branch information
matthias-goupil committed Sep 4, 2024
1 parent 868472d commit 17c0b5f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion front/example-app/src/components/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
AUTOCOMPLETE_FACET_TYPE,
AUTOCOMPLETE_PRODUCT_TYPE,
} from '../../constants'
import { useNavigate } from 'react-router-dom'
import { useLocation, useNavigate } from 'react-router-dom'

const MIN_AUTOCOMPLETE_CHAR = 3

Expand Down Expand Up @@ -110,6 +110,7 @@ function SearchBar(props: IProps): JSX.Element {
const navigate = useNavigate()

const [search, setSearch] = useState('')
const location = useLocation();
const [documents, setDocuments, _load, debouncedLoad] = useGraphqlApi<
IGraphqlSearchProducts & IGraphqlSearchCategories
>()
Expand Down Expand Up @@ -202,6 +203,12 @@ function SearchBar(props: IProps): JSX.Element {
loadDocuments(search)
}, [loadDocuments, search])

useEffect(() => {
if(location.pathname !== "/search"){
setSearch("")
}
}, [location]);

function handleSearchChange(
_event: ChangeEvent<HTMLInputElement>,
value: IProductAutoComplete | ICategoryAutoComplete | IFacetAutocomplete
Expand Down

0 comments on commit 17c0b5f

Please sign in to comment.