@@ -16,16 +16,37 @@ function SearchBarContent() {
1616 return ;
1717 }
1818
19- // Clean up previous instance and clear container
19+ const handleKeyDown = ( e ) => {
20+ const kapaContainer = document . getElementById ( 'kapa-widget-container' ) ;
21+
22+ if ( ! kapaContainer || ! kapaContainer . shadowRoot ) {
23+ return ;
24+ }
25+
26+ const shadowActiveElement = kapaContainer . shadowRoot . activeElement ;
27+
28+ if ( shadowActiveElement &&
29+ ( shadowActiveElement . tagName === 'INPUT' ||
30+ shadowActiveElement . tagName === 'TEXTAREA' ||
31+ shadowActiveElement . isContentEditable ) ) {
32+
33+ const allowedKeys = [ 'Enter' , 'Tab' , 'Escape' , 'ArrowUp' , 'ArrowDown' , 'ArrowLeft' , 'ArrowRight' ] ;
34+
35+ if ( ! allowedKeys . includes ( e . key ) ) {
36+ e . stopImmediatePropagation ( ) ;
37+ }
38+ }
39+ } ;
40+
41+ document . addEventListener ( 'keydown' , handleKeyDown , true ) ;
42+
2043 if ( searchInstanceRef . current ) {
2144 searchInstanceRef . current . destroy ?. ( ) ;
2245 searchInstanceRef . current = null ;
2346 }
2447
25- // Clear the container content
2648 searchButtonRef . current . innerHTML = '' ;
2749
28- // Dynamic import to avoid SSR issues with solid-js
2950 Promise . all ( [
3051 import ( 'meilisearch-docsearch' ) ,
3152 import ( 'meilisearch-docsearch/css' )
@@ -129,6 +150,7 @@ function SearchBarContent() {
129150 } ) ;
130151
131152 return ( ) => {
153+ document . removeEventListener ( 'keydown' , handleKeyDown , true ) ;
132154 if ( searchInstanceRef . current ) {
133155 searchInstanceRef . current . destroy ?. ( ) ;
134156 searchInstanceRef . current = null ;
0 commit comments