mirror of
https://github.com/tauri-apps/meilisearch-docsearch.git
synced 2026-01-31 00:45:16 +01:00
5
.changes/debounce-duration.md
Normal file
5
.changes/debounce-duration.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"meilisearch-docsearch": "minor"
|
||||
---
|
||||
|
||||
Add `debounceDuration` option to set debouce duration or disable it.
|
||||
@@ -26,6 +26,19 @@ export interface DocSearchProps {
|
||||
translations?: DocSearchTranslations;
|
||||
searchParams?: SearchParams;
|
||||
environment?: typeof window;
|
||||
/**
|
||||
* Duration to wait between keystores to determine whether a search should happen or not.
|
||||
* Defaults to `200`.
|
||||
*
|
||||
* Set to `false` to disable debouncing.
|
||||
*
|
||||
* This is an optimization that discards unnecessary search operations, for example,
|
||||
* if a user is typing `hello`, we skip search operations for `h`, `he`, `hel` and `hell`
|
||||
* as this usually not what the user wants to search for, and instead wait a few milliseconds until
|
||||
* the user stops typing for a brief moment, and then we do the search operation.
|
||||
* In the previous example, that would be `hello`.
|
||||
*/
|
||||
debounceDuration?: number | false;
|
||||
}
|
||||
|
||||
export type DocSearchTranslations = Partial<{
|
||||
|
||||
@@ -62,6 +62,7 @@ export const DocSearchModal: Component<DocSearchModalProps> = ({
|
||||
clientAgents,
|
||||
searchParams,
|
||||
environment = window,
|
||||
debounceDuration = 200,
|
||||
translations = {},
|
||||
onClose,
|
||||
initialQuery,
|
||||
@@ -200,7 +201,10 @@ export const DocSearchModal: Component<DocSearchModalProps> = ({
|
||||
setHitsCategories(catgeories);
|
||||
});
|
||||
}
|
||||
const debouncedSearch = utils.debounce(search, 100);
|
||||
|
||||
const debouncedSearch = !debounceDuration
|
||||
? search
|
||||
: utils.debounce(search, debounceDuration);
|
||||
|
||||
if (initialQuery) {
|
||||
onMount(() => {
|
||||
|
||||
Reference in New Issue
Block a user