@@ -8,11 +8,10 @@ import SearchResults from './search-results'
8
8
import useSiteMetadata from '../hooks/use-site-metadata'
9
9
import { HEADER_BAR , HEADER_HEIGHT } from '../constants'
10
10
import { LightTheme } from '../theme'
11
- import useLocationChange from '../hooks/use-location-change'
12
11
13
12
export const Desktop = props => {
14
13
const siteMetadata = useSiteMetadata ( )
15
- const { getInputProps, getMenuProps, isOpen , results, getItemProps, highlightedIndex} = props
14
+ const { getInputProps, getMenuProps, resultsOpen , results, getItemProps, highlightedIndex} = props
16
15
17
16
return (
18
17
< Box sx = { { position : 'relative' } } >
@@ -23,7 +22,7 @@ export const Desktop = props => {
23
22
{ ...getInputProps ( ) }
24
23
/>
25
24
< Box sx = { { position : 'absolute' , left : 0 , right : 0 , pt : 1 } } { ...getMenuProps ( ) } >
26
- { isOpen ? (
25
+ { resultsOpen ? (
27
26
< LightTheme
28
27
sx = { {
29
28
overflow : 'auto' ,
@@ -46,46 +45,35 @@ export const Desktop = props => {
46
45
}
47
46
48
47
export const Mobile = ( {
49
- reset,
50
48
results,
51
- isOpen : resultsOpen ,
49
+ resultsOpen,
52
50
getInputProps,
53
51
getItemProps,
54
52
getMenuProps,
55
53
highlightedIndex,
54
+ isMobileSearchOpen,
55
+ setMobileSearchOpen,
56
+ resetAndClose,
56
57
} ) => {
57
- const [ open , setOpen ] = React . useState ( false )
58
58
const siteMetadata = useSiteMetadata ( )
59
- const locationChange = useLocationChange ( )
60
-
61
- React . useEffect ( ( ) => {
62
- if ( locationChange . change ) {
63
- setOpen ( false )
64
- }
65
- } , [ locationChange ] )
66
59
67
60
// Fixes focus behavior on iOS where the input gets focus styles but not the
68
61
// actual focus after animating open.
69
62
const ref = React . useRef ( )
70
63
React . useEffect ( ( ) => {
71
- if ( open ) {
64
+ if ( isMobileSearchOpen ) {
72
65
ref . current . focus ( )
73
66
}
74
- } , [ ref , open ] )
75
-
76
- const handleDismiss = ( ) => {
77
- reset ( )
78
- setOpen ( false )
79
- }
67
+ } , [ ref , isMobileSearchOpen ] )
80
68
81
69
return (
82
70
< >
83
- < Button aria-label = "Search" aria-expanded = { open } onClick = { ( ) => setOpen ( true ) } >
71
+ < Button aria-label = "Search" aria-expanded = { isMobileSearchOpen } onClick = { ( ) => setMobileSearchOpen ( true ) } >
84
72
< SearchIcon />
85
73
</ Button >
86
74
< AnimatePresence >
87
- { open ? (
88
- < FocusOn returnFocus = { true } onEscapeKey = { handleDismiss } >
75
+ { isMobileSearchOpen ? (
76
+ < FocusOn returnFocus = { true } onEscapeKey = { resetAndClose } >
89
77
< Box
90
78
sx = { {
91
79
position : 'fixed' ,
@@ -112,7 +100,7 @@ export const Mobile = ({
112
100
animate = { { opacity : 1 } }
113
101
exit = { { opacity : 0 } }
114
102
transition = { { type : 'tween' } }
115
- onClick = { handleDismiss }
103
+ onClick = { resetAndClose }
116
104
/>
117
105
< Box sx = { { display : 'flex' , flexDirection : 'column' , height : resultsOpen ? '100%' : 'auto' } } >
118
106
< Box
@@ -183,7 +171,7 @@ export const Mobile = ({
183
171
exit = { { opacity : 0 } }
184
172
transition = { { type : 'tween' , ease : 'easeOut' , duration : 0.2 } }
185
173
>
186
- < Button sx = { { ml : 3 } } aria-label = "Cancel" onClick = { handleDismiss } >
174
+ < Button sx = { { ml : 3 } } aria-label = "Cancel" onClick = { resetAndClose } >
187
175
< XIcon />
188
176
</ Button >
189
177
</ Box >
0 commit comments