11import {
22 AutocompleteState ,
33 createAutocomplete ,
4- } from '@francoischalifour /autocomplete-core' ;
5- import { getAlgoliaResults } from '@francoischalifour /autocomplete-preset-algolia' ;
4+ } from '@algolia /autocomplete-core' ;
5+ import { getAlgoliaResults } from '@algolia /autocomplete-preset-algolia' ;
66import React from 'react' ;
77
88import { MAX_QUERY_SIZE } from './constants' ;
@@ -47,8 +47,13 @@ export function DocSearchModal({
4747 AutocompleteState < InternalDocSearchHit >
4848 > ( {
4949 query : '' ,
50- suggestions : [ ] ,
51- } as any ) ;
50+ collections : [ ] ,
51+ completion : null ,
52+ context : { } ,
53+ isOpen : false ,
54+ selectedItemId : null ,
55+ status : 'idle' ,
56+ } ) ;
5257
5358 const containerRef = React . useRef < HTMLDivElement | null > ( null ) ;
5459 const modalRef = React . useRef < HTMLDivElement | null > ( null ) ;
@@ -134,33 +139,39 @@ export function DocSearchModal({
134139
135140 return [
136141 {
137- onSelect ( { suggestion } ) {
138- saveRecentSearch ( suggestion ) ;
139- onClose ( ) ;
142+ onSelect ( { item, event } ) {
143+ saveRecentSearch ( item ) ;
144+
145+ if ( ! event . shiftKey && ! event . ctrlKey && ! event . metaKey ) {
146+ onClose ( ) ;
147+ }
140148 } ,
141- getSuggestionUrl ( { suggestion } ) {
142- return suggestion . url ;
149+ getItemUrl ( { item } ) {
150+ return item . url ;
143151 } ,
144- getSuggestions ( ) {
152+ getItems ( ) {
145153 return recentSearches . getAll ( ) ;
146154 } ,
147155 } ,
148156 {
149- onSelect ( { suggestion } ) {
150- saveRecentSearch ( suggestion ) ;
151- onClose ( ) ;
157+ onSelect ( { item, event } ) {
158+ saveRecentSearch ( item ) ;
159+
160+ if ( ! event . shiftKey && ! event . ctrlKey && ! event . metaKey ) {
161+ onClose ( ) ;
162+ }
152163 } ,
153- getSuggestionUrl ( { suggestion } ) {
154- return suggestion . url ;
164+ getItemUrl ( { item } ) {
165+ return item . url ;
155166 } ,
156- getSuggestions ( ) {
167+ getItems ( ) {
157168 return favoriteSearches . getAll ( ) ;
158169 } ,
159170 } ,
160171 ] ;
161172 }
162173
163- return getAlgoliaResults ( {
174+ return getAlgoliaResults < DocSearchHit > ( {
164175 searchClient,
165176 queries : [
166177 {
@@ -209,7 +220,7 @@ export function DocSearchModal({
209220 throw error ;
210221 } )
211222 . then ( ( results ) => {
212- const hits : DocSearchHit [ ] = results [ 0 ] . hits ;
223+ const hits = results [ 0 ] . hits ;
213224 const nbHits : number = results [ 0 ] . nbHits ;
214225 const sources = groupBy ( hits , ( hit ) => hit . hierarchy . lvl0 ) ;
215226
@@ -228,14 +239,17 @@ export function DocSearchModal({
228239
229240 return Object . values < DocSearchHit [ ] > ( sources ) . map ( ( items ) => {
230241 return {
231- onSelect ( { suggestion } ) {
232- saveRecentSearch ( suggestion ) ;
233- onClose ( ) ;
242+ onSelect ( { item, event } ) {
243+ saveRecentSearch ( item ) ;
244+
245+ if ( ! event . shiftKey && ! event . ctrlKey && ! event . metaKey ) {
246+ onClose ( ) ;
247+ }
234248 } ,
235- getSuggestionUrl ( { suggestion } ) {
236- return suggestion . url ;
249+ getItemUrl ( { item } ) {
250+ return item . url ;
237251 } ,
238- getSuggestions ( ) {
252+ getItems ( ) {
239253 return Object . values (
240254 groupBy ( items , ( item ) => item . hierarchy . lvl1 )
241255 )
0 commit comments