@@ -51,13 +51,13 @@ export function DocSearchModal({
5151 completion : null ,
5252 context : { } ,
5353 isOpen : false ,
54- selectedItemId : null ,
54+ activeItemId : null ,
5555 status : 'idle' ,
5656 } ) ;
5757
5858 const containerRef = React . useRef < HTMLDivElement | null > ( null ) ;
5959 const modalRef = React . useRef < HTMLDivElement | null > ( null ) ;
60- const searchBoxRef = React . useRef < HTMLDivElement | null > ( null ) ;
60+ const formElementRef = React . useRef < HTMLDivElement | null > ( null ) ;
6161 const dropdownRef = React . useRef < HTMLDivElement | null > ( null ) ;
6262 const inputRef = React . useRef < HTMLInputElement | null > ( null ) ;
6363 const snippetLength = React . useRef < number > ( 10 ) ;
@@ -117,7 +117,7 @@ export function DocSearchModal({
117117 React . KeyboardEvent
118118 > ( {
119119 id : 'docsearch' ,
120- defaultSelectedItemId : 0 ,
120+ defaultActiveItemId : 0 ,
121121 placeholder,
122122 openOnFocus : true ,
123123 initialState : {
@@ -139,6 +139,7 @@ export function DocSearchModal({
139139
140140 return [
141141 {
142+ sourceId : 'recentSearches' ,
142143 onSelect ( { item, event } ) {
143144 saveRecentSearch ( item ) ;
144145
@@ -154,6 +155,7 @@ export function DocSearchModal({
154155 } ,
155156 } ,
156157 {
158+ sourceId : 'favoriteSearches' ,
157159 onSelect ( { item, event } ) {
158160 saveRecentSearch ( item ) ;
159161
@@ -237,43 +239,46 @@ export function DocSearchModal({
237239
238240 setContext ( { nbHits } ) ;
239241
240- return Object . values < DocSearchHit [ ] > ( sources ) . map ( ( items ) => {
241- return {
242- onSelect ( { item, event } ) {
243- saveRecentSearch ( item ) ;
244-
245- if ( ! event . shiftKey && ! event . ctrlKey && ! event . metaKey ) {
246- onClose ( ) ;
247- }
248- } ,
249- getItemUrl ( { item } ) {
250- return item . url ;
251- } ,
252- getItems ( ) {
253- return Object . values (
254- groupBy ( items , ( item ) => item . hierarchy . lvl1 )
255- )
256- . map ( transformItems )
257- . map ( ( hits ) =>
258- hits . map ( ( item ) => {
259- return {
260- ...item ,
261- // eslint-disable-next-line @typescript-eslint/camelcase
262- __docsearch_parent :
263- item . type !== 'lvl1' &&
264- hits . find (
265- ( siblingItem ) =>
266- siblingItem . type === 'lvl1' &&
267- siblingItem . hierarchy . lvl1 ===
268- item . hierarchy . lvl1
269- ) ,
270- } ;
271- } )
242+ return Object . values < DocSearchHit [ ] > ( sources ) . map (
243+ ( items , index ) => {
244+ return {
245+ sourceId : `hits${ index } ` ,
246+ onSelect ( { item, event } ) {
247+ saveRecentSearch ( item ) ;
248+
249+ if ( ! event . shiftKey && ! event . ctrlKey && ! event . metaKey ) {
250+ onClose ( ) ;
251+ }
252+ } ,
253+ getItemUrl ( { item } ) {
254+ return item . url ;
255+ } ,
256+ getItems ( ) {
257+ return Object . values (
258+ groupBy ( items , ( item ) => item . hierarchy . lvl1 )
272259 )
273- . flat ( ) ;
274- } ,
275- } ;
276- } ) ;
260+ . map ( transformItems )
261+ . map ( ( hits ) =>
262+ hits . map ( ( item ) => {
263+ return {
264+ ...item ,
265+ // eslint-disable-next-line @typescript-eslint/camelcase
266+ __docsearch_parent :
267+ item . type !== 'lvl1' &&
268+ hits . find (
269+ ( siblingItem ) =>
270+ siblingItem . type === 'lvl1' &&
271+ siblingItem . hierarchy . lvl1 ===
272+ item . hierarchy . lvl1
273+ ) ,
274+ } ;
275+ } )
276+ )
277+ . flat ( ) ;
278+ } ,
279+ } ;
280+ }
281+ ) ;
277282 } ) ;
278283 } ,
279284 } ) ,
@@ -298,7 +303,7 @@ export function DocSearchModal({
298303 useTouchEvents ( {
299304 getEnvironmentProps,
300305 panelElement : dropdownRef . current ,
301- searchBoxElement : searchBoxRef . current ,
306+ formElement : formElementRef . current ,
302307 inputElement : inputRef . current ,
303308 } ) ;
304309 useTrapFocus ( { container : containerRef . current } ) ;
@@ -387,7 +392,7 @@ export function DocSearchModal({
387392 } }
388393 >
389394 < div className = "DocSearch-Modal" ref = { modalRef } >
390- < header className = "DocSearch-SearchBar" ref = { searchBoxRef } >
395+ < header className = "DocSearch-SearchBar" ref = { formElementRef } >
391396 < SearchBox
392397 { ...autocomplete }
393398 state = { state }
0 commit comments