Skip to content

Commit 4c9d939

Browse files
committed
Search string validation on pages other than HOME
- Discards search query submission when empty strings are provided - Extra leading & trailing spaces are ignored
1 parent 65e8759 commit 4c9d939

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

components/Search.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export default function Search({ searchBarWrapperStyles }: SearchProps) {
1919
});
2020

2121
const onSubmit: SubmitHandler<FormValues> = ({ searchQuery }) => {
22-
router.push({ query: { ...router.query, q: searchQuery } });
22+
let trimmedQuery = searchQuery.trim();
23+
if(trimmedQuery !== ''){ //Performs search only with non-empty strings
24+
router.push({ query: { ...router.query, q: trimmedQuery } });
25+
}
2326
};
2427

2528
return (

0 commit comments

Comments
 (0)