@@ -4,8 +4,8 @@ import RouterLink from '@docusaurus/Link';
4
4
// import { useHistory, useLocation } from '@docusaurus/router';
5
5
import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
6
6
import clsx from 'clsx' ;
7
- // import React, { useCallback } from 'react';
8
7
import React , { useEffect , useState } from 'react' ;
8
+ import { useHotkeys } from 'react-hotkeys-hook' ;
9
9
10
10
// import { ApifySearch } from '@apify/docs-search-modal';
11
11
import { ControlKeyIcon , SearchIcon } from '@apify/docs-search-modal/dist/utils/icons' ;
@@ -82,6 +82,7 @@ export function Link(props) {
82
82
83
83
export default function SearchBar ( { onClick } ) {
84
84
const [ variant , setVariant ] = useState ( null ) ;
85
+ const [ opened , setOpened ] = useState ( false ) ;
85
86
const { siteConfig } = useDocusaurusContext ( ) ;
86
87
const { inkeepApiKey } = siteConfig . customFields ;
87
88
@@ -98,9 +99,18 @@ export default function SearchBar({ onClick }) {
98
99
} , [ ] ) ;
99
100
100
101
onClick = ( ) => {
102
+ if ( opened ) {
103
+ return ;
104
+ }
105
+
106
+ setOpened ( true ) ;
107
+
101
108
if ( variant === 'kapa' ) {
102
109
if ( window . Kapa && typeof window . Kapa . open === 'function' ) {
103
110
window . Kapa . open ( ) ;
111
+ window . Kapa ( 'onModalClose' , ( ) => {
112
+ setOpened ( false ) ;
113
+ } ) ;
104
114
} else {
105
115
console . error ( 'Kapa.ai widget is not available.' ) ;
106
116
}
@@ -178,11 +188,13 @@ export default function SearchBar({ onClick }) {
178
188
} ,
179
189
] ,
180
190
} ,
191
+ defaultView : 'chat' ,
181
192
} ;
182
193
const modal = window . Inkeep . ModalSearchAndChat ( config ) ;
183
194
184
195
function handleOpenChange ( newOpen ) {
185
196
modal . update ( { modalSettings : { isOpen : newOpen } } ) ;
197
+ setOpened ( newOpen ) ;
186
198
}
187
199
188
200
modal . update ( { modalSettings : { isOpen : true } } ) ;
@@ -200,6 +212,10 @@ export default function SearchBar({ onClick }) {
200
212
}
201
213
} , [ ] ) ;
202
214
215
+ useHotkeys ( 'mod+k, /' , ( ) => {
216
+ onClick ( ) ;
217
+ } , { preventDefault : true } ) ;
218
+
203
219
return (
204
220
< BrowserOnly >
205
221
{ ( ) => (
0 commit comments