fix: add throttle in autocomplete

This commit is contained in:
Yohan Boniface 2024-07-02 19:06:11 +02:00
parent 2d1c4ad3c0
commit abbd0eef62

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 = []
@ -125,7 +126,10 @@ export class BaseAutocomplete {
'Control', 'Control',
] ]
if (!special.includes(e.key)) { if (!special.includes(e.key)) {
if (this._typing) window.clearTimeout(this._typing)
this._typing = window.setTimeout(() => {
this.search() this.search()
}, this.options.throttling)
} }
} }