Skip to content

Commit 3acd66e

Browse files
fix(searchbar): clean up timeouts
1 parent 1c89cf0 commit 3acd66e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/src/components/searchbar/searchbar.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export class Searchbar implements ComponentInterface {
3030
private originalIonInput?: EventEmitter<SearchbarInputEventDetail>;
3131
private inputId = `ion-searchbar-${searchbarIds++}`;
3232
private inheritedAttributes: Attributes = {};
33+
private loadTimeout?: number
34+
private clearTimeout?: number
3335

3436
/**
3537
* The value of the input when the textarea is focused.
@@ -277,6 +279,11 @@ export class Searchbar implements ComponentInterface {
277279
this.emitStyle();
278280
}
279281

282+
disconnectedCallback() {
283+
clearTimeout(this.loadTimeout)
284+
clearTimeout(this.clearTimeout)
285+
}
286+
280287
componentWillLoad() {
281288
this.inheritedAttributes = {
282289
...inheritAttributes(this.el, ['lang', 'dir']),
@@ -288,7 +295,7 @@ export class Searchbar implements ComponentInterface {
288295
this.positionElements();
289296
this.debounceChanged();
290297

291-
setTimeout(() => {
298+
this.loadTimeout = setTimeout(() => {
292299
this.noAnimate = false;
293300
}, 300);
294301
}
@@ -358,12 +365,13 @@ export class Searchbar implements ComponentInterface {
358365
* Clears the input field and triggers the control change.
359366
*/
360367
private onClearInput = async (shouldFocus?: boolean) => {
368+
clearTimeout(this.clearTimeout)
361369
this.ionClear.emit();
362370

363371
return new Promise<void>((resolve) => {
364372
// setTimeout() fixes https://github.com/ionic-team/ionic-framework/issues/7527
365373
// wait for 4 frames
366-
setTimeout(() => {
374+
this.clearTimeout = setTimeout(() => {
367375
const value = this.getValue();
368376
if (value !== '') {
369377
this.value = '';

0 commit comments

Comments
 (0)