File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
packages/gitbook/src/components/Search Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " gitbook " : patch
3+ ---
4+
5+ Trim the search query to avoid showing a loading state when typing
Original file line number Diff line number Diff line change @@ -189,6 +189,9 @@ function SearchModalBody(
189189 setSearchState ( ( state ) => ( state ? { ...state , ask : true } : null ) ) ;
190190 } ;
191191
192+ // We trim the query to avoid invalidating the search when the user is typing between words.
193+ const normalizedQuery = state . query . trim ( ) ;
194+
192195 return (
193196 < motion . div
194197 transition = { {
@@ -288,12 +291,14 @@ function SearchModalBody(
288291 < SearchResults
289292 ref = { resultsRef }
290293 global = { isMultiVariants && state . global }
291- query = { state . query }
294+ query = { normalizedQuery }
292295 withAsk = { withAsk }
293296 onSwitchToAsk = { onSwitchToAsk }
294297 />
295298 ) : null }
296- { state . query && state . ask && withAsk ? < SearchAskAnswer query = { state . query } /> : null }
299+ { normalizedQuery && state . ask && withAsk ? (
300+ < SearchAskAnswer query = { normalizedQuery } />
301+ ) : null }
297302 </ motion . div >
298303 ) ;
299304}
You can’t perform that action at this time.
0 commit comments