-
Notifications
You must be signed in to change notification settings - Fork 21
/
search-form.js
52 lines (48 loc) · 1.35 KB
/
search-form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react';
import { useStaticQuery, graphql } from 'gatsby';
import search from 'uswds/img/usa-icons-bg/search--white.svg';
const SearchForm = ({ navigation, secondaryLinks }) => {
const { site } = useStaticQuery(
graphql`
query {
site {
pathPrefix
siteMetadata {
searchgov {
affiliate
endpoint
}
}
}
}
`
);
const { affiliate, endpoint } = site.siteMetadata.searchgov;
const handleSubmit = (e) => {
e.preventDefault();
const query = e.currentTarget.query.value;
window.location.replace(
`${endpoint}/search?utf8=✓&affiliate=${affiliate}&query=${query}`
);
};
return (
<form className="usa-search usa-search--small" onSubmit={handleSubmit}>
<div role="search">
<label className="usa-sr-only" htmlFor="extended-search-field-small">
Search small
</label>
<input
className="usa-input usagov-search-autocomplete"
id="extended-search-field-small"
type="search"
name="query"
autoComplete="off"
/>
<button className="usa-button" type="submit">
<img src={search} className="usa-search__submit-icon" alt="Search" />
</button>
</div>
</form>
);
};
export default SearchForm;