Trim search query before doing search (#3042)

This commit is contained in:
Samy Pessé
2025-03-26 11:18:18 +01:00
committed by GitHub
parent 57ca4e0e88
commit e9fa50dfb5
2 changed files with 12 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Trim the search query to avoid showing a loading state when typing
@@ -189,6 +189,9 @@ function SearchModalBody(
setSearchState((state) => (state ? { ...state, ask: true } : null));
};
// We trim the query to avoid invalidating the search when the user is typing between words.
const normalizedQuery = state.query.trim();
return (
<motion.div
transition={{
@@ -288,12 +291,14 @@ function SearchModalBody(
<SearchResults
ref={resultsRef}
global={isMultiVariants && state.global}
query={state.query}
query={normalizedQuery}
withAsk={withAsk}
onSwitchToAsk={onSwitchToAsk}
/>
) : null}
{state.query && state.ask && withAsk ? <SearchAskAnswer query={state.query} /> : null}
{normalizedQuery && state.ask && withAsk ? (
<SearchAskAnswer query={normalizedQuery} />
) : null}
</motion.div>
);
}