@@ -8,11 +8,10 @@ import SearchResults from './search-results'
88import useSiteMetadata from '../hooks/use-site-metadata'
99import { HEADER_BAR , HEADER_HEIGHT } from '../constants'
1010import { LightTheme } from '../theme'
11- import useLocationChange from '../hooks/use-location-change'
1211
1312export const Desktop = props => {
1413 const siteMetadata = useSiteMetadata ( )
15- const { getInputProps, getMenuProps, isOpen , results, getItemProps, highlightedIndex} = props
14+ const { getInputProps, getMenuProps, resultsOpen , results, getItemProps, highlightedIndex} = props
1615
1716 return (
1817 < Box sx = { { position : 'relative' } } >
@@ -23,7 +22,7 @@ export const Desktop = props => {
2322 { ...getInputProps ( ) }
2423 />
2524 < Box sx = { { position : 'absolute' , left : 0 , right : 0 , pt : 1 } } { ...getMenuProps ( ) } >
26- { isOpen ? (
25+ { resultsOpen ? (
2726 < LightTheme
2827 sx = { {
2928 overflow : 'auto' ,
@@ -46,46 +45,35 @@ export const Desktop = props => {
4645}
4746
4847export const Mobile = ( {
49- reset,
5048 results,
51- isOpen : resultsOpen ,
49+ resultsOpen,
5250 getInputProps,
5351 getItemProps,
5452 getMenuProps,
5553 highlightedIndex,
54+ isMobileSearchOpen,
55+ setMobileSearchOpen,
56+ resetAndClose,
5657} ) => {
57- const [ open , setOpen ] = React . useState ( false )
5858 const siteMetadata = useSiteMetadata ( )
59- const locationChange = useLocationChange ( )
60-
61- React . useEffect ( ( ) => {
62- if ( locationChange . change ) {
63- setOpen ( false )
64- }
65- } , [ locationChange ] )
6659
6760 // Fixes focus behavior on iOS where the input gets focus styles but not the
6861 // actual focus after animating open.
6962 const ref = React . useRef ( )
7063 React . useEffect ( ( ) => {
71- if ( open ) {
64+ if ( isMobileSearchOpen ) {
7265 ref . current . focus ( )
7366 }
74- } , [ ref , open ] )
75-
76- const handleDismiss = ( ) => {
77- reset ( )
78- setOpen ( false )
79- }
67+ } , [ ref , isMobileSearchOpen ] )
8068
8169 return (
8270 < >
83- < Button aria-label = "Search" aria-expanded = { open } onClick = { ( ) => setOpen ( true ) } >
71+ < Button aria-label = "Search" aria-expanded = { isMobileSearchOpen } onClick = { ( ) => setMobileSearchOpen ( true ) } >
8472 < SearchIcon />
8573 </ Button >
8674 < AnimatePresence >
87- { open ? (
88- < FocusOn returnFocus = { true } onEscapeKey = { handleDismiss } >
75+ { isMobileSearchOpen ? (
76+ < FocusOn returnFocus = { true } onEscapeKey = { resetAndClose } >
8977 < Box
9078 sx = { {
9179 position : 'fixed' ,
@@ -112,7 +100,7 @@ export const Mobile = ({
112100 animate = { { opacity : 1 } }
113101 exit = { { opacity : 0 } }
114102 transition = { { type : 'tween' } }
115- onClick = { handleDismiss }
103+ onClick = { resetAndClose }
116104 />
117105 < Box sx = { { display : 'flex' , flexDirection : 'column' , height : resultsOpen ? '100%' : 'auto' } } >
118106 < Box
@@ -183,7 +171,7 @@ export const Mobile = ({
183171 exit = { { opacity : 0 } }
184172 transition = { { type : 'tween' , ease : 'easeOut' , duration : 0.2 } }
185173 >
186- < Button sx = { { ml : 3 } } aria-label = "Cancel" onClick = { handleDismiss } >
174+ < Button sx = { { ml : 3 } } aria-label = "Cancel" onClick = { resetAndClose } >
187175 < XIcon />
188176 </ Button >
189177 </ Box >
0 commit comments