Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/src/components/searchbar/searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class Searchbar implements ComponentInterface {
private originalIonInput?: EventEmitter<SearchbarInputEventDetail>;
private inputId = `ion-searchbar-${searchbarIds++}`;
private inheritedAttributes: Attributes = {};
private loadTimeout?: number
private clearTimeout?: number

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

disconnectedCallback() {
clearTimeout(this.loadTimeout)
clearTimeout(this.clearTimeout)
}

componentWillLoad() {
this.inheritedAttributes = {
...inheritAttributes(this.el, ['lang', 'dir']),
Expand All @@ -288,7 +295,7 @@ export class Searchbar implements ComponentInterface {
this.positionElements();
this.debounceChanged();

setTimeout(() => {
this.loadTimeout = setTimeout(() => {
this.noAnimate = false;
}, 300);
}
Expand Down Expand Up @@ -358,12 +365,13 @@ export class Searchbar implements ComponentInterface {
* Clears the input field and triggers the control change.
*/
private onClearInput = async (shouldFocus?: boolean) => {
clearTimeout(this.clearTimeout)
this.ionClear.emit();

return new Promise<void>((resolve) => {
// setTimeout() fixes https://github.com/ionic-team/ionic-framework/issues/7527
// wait for 4 frames
setTimeout(() => {
this.clearTimeout = setTimeout(() => {
const value = this.getValue();
if (value !== '') {
this.value = '';
Expand Down
Loading