-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathNotFoundPageForm.tsx
48 lines (45 loc) · 1.65 KB
/
NotFoundPageForm.tsx
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
import { useState, useRef, useEffect } from "react"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faSearch, faCircleXmark } from "@fortawesome/free-solid-svg-icons"
export default function NotFoundPageForm() {
const [searchQuery, setSearchQuery] = useState("")
const inputRef = useRef<HTMLInputElement>(null)
useEffect(() => {
// Browser keeps the DOM input value on page refresh.
const domValue = inputRef.current?.value
if (domValue) setSearchQuery(domValue)
}, [])
return (
<form className="NotFoundPageForm" action="/search" method="GET">
<input
id="search_q"
className="NotFoundPageForm__input"
ref={inputRef}
type="search"
placeholder="Search..."
name="q"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
required
autoFocus
/>
{searchQuery && (
<button
className="NotFoundPageForm__button NotFoundPageForm__reset-button"
type="reset"
title="Clear search"
onClick={() => setSearchQuery("")}
>
<FontAwesomeIcon icon={faCircleXmark} />
</button>
)}
<button
className="NotFoundPageForm__button NotFoundPageForm__submit-button"
type="submit"
title="Search"
>
<FontAwesomeIcon icon={faSearch} />
</button>
</form>
)
}