Merge pull request #1964 from umap-project/throttle-search

fix: add throttle in autocomplete
This commit is contained in:
Yohan Boniface 2024-07-02 22:51:09 +02:00 committed by GitHub
commit 6cbda1f373
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,6 +16,7 @@ export class BaseAutocomplete {
allowFree: true, allowFree: true,
minChar: 2, minChar: 2,
maxResults: 5, maxResults: 5,
throttling: 300,
} }
this.cache = '' this.cache = ''
this.results = [] this.results = []
@ -126,7 +127,10 @@ export class BaseAutocomplete {
'Control', 'Control',
] ]
if (!special.includes(e.key)) { if (!special.includes(e.key)) {
this.search() if (this._typing) window.clearTimeout(this._typing)
this._typing = window.setTimeout(() => {
this.search()
}, this.options.throttling)
} }
} }