@@ -16,6 +16,7 @@ import { groupBy, noop } from './utils';
1616import { createStoredSearches } from './stored-searches' ;
1717import { useSearchClient } from './useSearchClient' ;
1818import { useTrapFocus } from './useTrapFocus' ;
19+ import { useTouchEvents } from './useTouchEvents' ;
1920import { Hit } from './Hit' ;
2021import { SearchBox } from './SearchBox' ;
2122import { ScreenState } from './ScreenState' ;
@@ -66,7 +67,6 @@ export function DocSearch({
6667 : ''
6768 ) . current ;
6869
69- useTrapFocus ( { container : containerRef . current } ) ;
7070 const searchClient = useSearchClient ( appId , apiKey ) ;
7171 const favoriteSearches = React . useRef (
7272 createStoredSearches < StoredDocSearchHit > ( {
@@ -274,6 +274,14 @@ export function DocSearch({
274274
275275 const { getEnvironmentProps, getRootProps, refresh } = autocomplete ;
276276
277+ useTouchEvents ( {
278+ getEnvironmentProps,
279+ dropdownElement : dropdownRef . current ,
280+ searchBoxElement : searchBoxRef . current ,
281+ inputElement : inputRef . current ,
282+ } ) ;
283+ useTrapFocus ( { container : containerRef . current } ) ;
284+
277285 React . useEffect ( ( ) => {
278286 const isMobileMediaQuery = window . matchMedia ( '(max-width: 750px)' ) ;
279287
@@ -299,26 +307,6 @@ export function DocSearch({
299307 }
300308 } , [ initialQuery , refresh ] ) ;
301309
302- React . useEffect ( ( ) => {
303- if ( ! ( searchBoxRef . current && dropdownRef . current && inputRef . current ) ) {
304- return undefined ;
305- }
306-
307- const { onTouchStart, onTouchMove } = getEnvironmentProps ( {
308- searchBoxElement : searchBoxRef . current ,
309- dropdownElement : dropdownRef . current ,
310- inputElement : inputRef . current ,
311- } ) ;
312-
313- window . addEventListener ( 'touchstart' , onTouchStart ) ;
314- window . addEventListener ( 'touchmove' , onTouchMove ) ;
315-
316- return ( ) => {
317- window . removeEventListener ( 'touchstart' , onTouchStart ) ;
318- window . removeEventListener ( 'touchmove' , onTouchMove ) ;
319- } ;
320- } , [ getEnvironmentProps , searchBoxRef , dropdownRef , inputRef ] ) ;
321-
322310 return (
323311 < div
324312 ref = { containerRef }
0 commit comments