Skip to content

Commit e9fa50d

Browse files
authored
Trim search query before doing search (#3042)
1 parent 57ca4e0 commit e9fa50d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.changeset/wise-dryers-nail.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Trim the search query to avoid showing a loading state when typing

packages/gitbook/src/components/Search/SearchModal.tsx

+7-2
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)