From abbd0eef62016d23d3424a005493cd04f451514c Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 2 Jul 2024 19:06:11 +0200 Subject: [PATCH] fix: add throttle in autocomplete --- umap/static/umap/js/modules/autocomplete.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/umap/static/umap/js/modules/autocomplete.js b/umap/static/umap/js/modules/autocomplete.js index 8e4bfae2..accd4ae3 100644 --- a/umap/static/umap/js/modules/autocomplete.js +++ b/umap/static/umap/js/modules/autocomplete.js @@ -16,6 +16,7 @@ export class BaseAutocomplete { allowFree: true, minChar: 2, maxResults: 5, + throttling: 300, } this.cache = '' this.results = [] @@ -125,7 +126,10 @@ export class BaseAutocomplete { 'Control', ] if (!special.includes(e.key)) { - this.search() + if (this._typing) window.clearTimeout(this._typing) + this._typing = window.setTimeout(() => { + this.search() + }, this.options.throttling) } }