Skip to content

Commit 9b677fe

Browse files
authored
Prevents default form submit. (#658)
1 parent 8453416 commit 9b677fe

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

components/site/algolia/search.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const Search = (props: SearchProps): JSX.Element => {
3636
onSearchStateChange={({ query }) => setQuery(query)}
3737
>
3838
<SearchBox onFocus={() => setHasFocus(true)} hasFocus={hasFocus} />
39-
<SearchResults ref={menu} show={query.length > 0 && hasFocus} />
39+
<SearchResults ref={menu} show={query?.length > 0 && hasFocus} />
4040
</InstantSearch>
4141
</Box>
4242
);

components/site/algolia/searchBox.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { SearchBoxProvided } from 'react-instantsearch-core';
22
import { connectSearchBox } from 'react-instantsearch-dom';
33
import { TextField, useWindowEvent } from '@sparkpost/matchbox';
44
import { Search as SearchIcon } from '@sparkpost/matchbox-icons';
5+
import { FormEvent } from 'react';
56

67
type InputProps = SearchBoxProvided & {
78
hasFocus?: boolean;
@@ -15,8 +16,12 @@ const Input = ({ currentRefinement, onFocus, hasFocus, refine }: InputProps) =>
1516
}
1617
});
1718

19+
const onSubmit = (e: FormEvent) => {
20+
e.preventDefault();
21+
};
22+
1823
return (
19-
<form noValidate action="" autoComplete="off" role="search">
24+
<form noValidate action="" autoComplete="off" role="search" onSubmit={onSubmit}>
2025
<TextField
2126
id="algolia-search"
2227
label="Search"

next-env.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference types="next" />
2-
/// <reference types="next/types/global" />
32
/// <reference types="next/image-types/global" />
43

54
// NOTE: This file should not be edited

0 commit comments

Comments
 (0)