@@ -9,14 +9,14 @@ import {
99import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
1010import { createPortal } from 'react-dom' ;
1111import translations from '@theme/SearchTranslations' ;
12- import { useAskAI } from '@site/src/hooks/useAskAI'
12+ import { useAskAI } from '@site/src/hooks/useAskAI'
1313import { shouldPreventSearchAction , handleSearchKeyboardConflict } from './utils/aiConflictHandler' ;
1414import { initializeSearchAnalytics , createEnhancedSearchClient } from './utils/searchAnalytics' ;
1515import { useDocSearchModal } from './utils/useDocSearchModal' ;
16- import {
17- createSearchParameters ,
18- createSearchNavigator ,
19- transformSearchItems
16+ import {
17+ createSearchParameters ,
18+ createSearchNavigator ,
19+ transformSearchItems
2020} from './utils/searchConfig' ;
2121import { SearchHit } from './searchHit' ;
2222import { SearchResultsFooter } from './searchResultsFooter' ;
@@ -31,10 +31,10 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
3131 const { isAskAIOpen } = useAskAI ( ) ;
3232 const history = useHistory ( ) ;
3333 const searchButtonRef = useRef ( null ) ;
34-
34+
3535 const [ selectedDocTypes , setSelectedDocTypes ] = useState ( null ) ;
3636 const searchParametersRef = useRef ( null ) ;
37-
37+
3838 const {
3939 isOpen,
4040 initialQuery,
@@ -49,12 +49,12 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
4949 // Update searchParameters ref instead of creating new object
5050 useEffect ( ( ) => {
5151 const newParams = createSearchParameters (
52- props ,
53- contextualSearch ,
52+ props ,
53+ contextualSearch ,
5454 contextualSearchFacetFilters ,
5555 selectedDocTypes
5656 ) ;
57-
57+
5858 if ( ! searchParametersRef . current ) {
5959 searchParametersRef . current = newParams ;
6060 } else {
@@ -67,8 +67,8 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
6767 // Initialize on mount
6868 if ( ! searchParametersRef . current ) {
6969 searchParametersRef . current = createSearchParameters (
70- props ,
71- contextualSearch ,
70+ props ,
71+ contextualSearch ,
7272 contextualSearchFacetFilters ,
7373 selectedDocTypes
7474 ) ;
@@ -77,14 +77,14 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
7777 // Track input changes to capture the query
7878 useEffect ( ( ) => {
7979 if ( ! isOpen ) return ;
80-
80+
8181 const handleInput = ( e ) => {
8282 const input = e . target ;
8383 if ( input . classList . contains ( 'DocSearch-Input' ) ) {
8484 lastQueryRef . current = input . value ;
8585 }
8686 } ;
87-
87+
8888 document . addEventListener ( 'input' , handleInput , true ) ;
8989 return ( ) => document . removeEventListener ( 'input' , handleInput , true ) ;
9090 } , [ isOpen ] ) ;
@@ -94,15 +94,15 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
9494 } , [ props . appId , props . apiKey ] ) ;
9595
9696 const navigator = useMemo (
97- ( ) => createSearchNavigator ( history , externalUrlRegex ) ,
98- [ history , externalUrlRegex ]
97+ ( ) => createSearchNavigator ( history , externalUrlRegex , currentLocale ) ,
98+ [ history , externalUrlRegex , currentLocale ]
9999 ) ;
100100
101101 const transformItems = useCallback ( ( items , state ) => {
102102 if ( state ?. query ) {
103103 lastQueryRef . current = state . query ;
104104 }
105-
105+
106106 return transformSearchItems ( items , {
107107 transformItems : props . transformItems ,
108108 processSearchResultUrl,
@@ -111,34 +111,34 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
111111 } ) ;
112112 } , [ props . transformItems , processSearchResultUrl , currentLocale ] ) ;
113113
114- const handleDocTypeChange = useCallback ( ( docTypes ) => {
115- setSelectedDocTypes ( docTypes ) ;
116-
117- // Re-trigger search with updated filters after state update completes
118- setTimeout ( ( ) => {
119- const input = document . querySelector ( '.DocSearch-Input' ) ;
120- const query = lastQueryRef . current ;
121-
122- if ( input && query ) {
123- // Access React's internal value setter to bypass readonly property
124- const nativeInputValueSetter = Object . getOwnPropertyDescriptor (
125- window . HTMLInputElement . prototype ,
126- 'value'
127- ) . set ;
128-
129- // Clear input to trigger change detection
130- nativeInputValueSetter . call ( input , '' ) ;
131- input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
132-
133- // Restore original query to execute search with new filters
134- setTimeout ( ( ) => {
135- nativeInputValueSetter . call ( input , query ) ;
114+ const handleDocTypeChange = useCallback ( ( docTypes ) => {
115+ setSelectedDocTypes ( docTypes ) ;
116+
117+ // Re-trigger search with updated filters after state update completes
118+ setTimeout ( ( ) => {
119+ const input = document . querySelector ( '.DocSearch-Input' ) ;
120+ const query = lastQueryRef . current ;
121+
122+ if ( input && query ) {
123+ // Access React's internal value setter to bypass readonly property
124+ const nativeInputValueSetter = Object . getOwnPropertyDescriptor (
125+ window . HTMLInputElement . prototype ,
126+ 'value'
127+ ) . set ;
128+
129+ // Clear input to trigger change detection
130+ nativeInputValueSetter . call ( input , '' ) ;
136131 input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
137- input . focus ( ) ;
138- } , 0 ) ;
139- }
140- } , 100 ) ;
141- } , [ ] ) ;
132+
133+ // Restore original query to execute search with new filters
134+ setTimeout ( ( ) => {
135+ nativeInputValueSetter . call ( input , query ) ;
136+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
137+ input . focus ( ) ;
138+ } , 0 ) ;
139+ }
140+ } , 100 ) ;
141+ } , [ ] ) ;
142142
143143 const resultsFooterComponent = useMemo (
144144 ( ) => ( footerProps ) => < SearchResultsFooter { ...footerProps } onClose = { onClose } /> ,
@@ -147,13 +147,13 @@ const handleDocTypeChange = useCallback((docTypes) => {
147147
148148 const transformSearchClient = useCallback ( ( searchClient ) => {
149149 const enhancedClient = createEnhancedSearchClient (
150- searchClient ,
151- siteMetadata . docusaurusVersion ,
150+ searchClient ,
151+ siteMetadata . docusaurusVersion ,
152152 queryIDRef
153153 ) ;
154-
154+
155155 const originalSearch = enhancedClient . search . bind ( enhancedClient ) ;
156-
156+
157157 let debounceTimeout ;
158158 enhancedClient . search = ( ...args ) => {
159159 return new Promise ( ( resolve , reject ) => {
@@ -165,7 +165,7 @@ const handleDocTypeChange = useCallback((docTypes) => {
165165 } , 200 ) ;
166166 } ) ;
167167 } ;
168-
168+
169169 return enhancedClient ;
170170 } , [ siteMetadata . docusaurusVersion ] ) ;
171171
@@ -190,7 +190,7 @@ const handleDocTypeChange = useCallback((docTypes) => {
190190 onInput : handleOnInput ,
191191 searchButtonRef,
192192 } ) ;
193-
193+
194194 return (
195195 < >
196196 < Head >
@@ -214,7 +214,7 @@ const handleDocTypeChange = useCallback((docTypes) => {
214214 DocSearchModal &&
215215 searchContainer &&
216216 createPortal (
217- < >
217+ < >
218218 < DocSearchModal
219219 onClose = { onClose }
220220 initialScrollY = { window . scrollY }
@@ -232,7 +232,7 @@ const handleDocTypeChange = useCallback((docTypes) => {
232232 placeholder = { translations . placeholder }
233233 translations = { translations . modal }
234234 />
235-
235+
236236 < div style = { {
237237 position : 'fixed' ,
238238 top : window . innerWidth < 768 ? '55px' : '120px' ,
@@ -241,7 +241,7 @@ const handleDocTypeChange = useCallback((docTypes) => {
241241 backgroundColor : 'var(--docsearch-modal-background)' ,
242242 boxShadow : '0 2px 8px rgba(0,0,0,0.1)'
243243 } } >
244- < DocTypeSelector
244+ < DocTypeSelector
245245 selectedDocTypes = { selectedDocTypes }
246246 onSelectionChange = { handleDocTypeChange }
247247 />
0 commit comments