From b492d264f2abe8b444fc914bee772e826d7dd597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=A9fling?= Date: Wed, 11 Dec 2024 23:42:59 +0100 Subject: [PATCH] Remove setTimeout not necessary --- .../src/lib/select2.component.html | 1 + .../src/lib/select2.component.ts | 26 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/projects/ng-select2-component/src/lib/select2.component.html b/projects/ng-select2-component/src/lib/select2.component.html index 0dbff62..4c416fd 100644 --- a/projects/ng-select2-component/src/lib/select2.component.html +++ b/projects/ng-select2-component/src/lib/select2.component.html @@ -192,6 +192,7 @@ (scrolled)="onScroll('down')" (scrolledUp)="onScroll('up')" (keydown)="keyDown($event)" + > @if (showSelectAll() && multiple()) {
  • diff --git a/projects/ng-select2-component/src/lib/select2.component.ts b/projects/ng-select2-component/src/lib/select2.component.ts index 0923137..ded94d6 100644 --- a/projects/ng-select2-component/src/lib/select2.component.ts +++ b/projects/ng-select2-component/src/lib/select2.component.ts @@ -515,8 +515,6 @@ export class Select2 implements ControlValueAccessor, OnInit, DoCheck, AfterView } reset(event?: MouseEvent) { - // const test = Select2Utils.getOptionByValue(this._data, this.resetSelectedValue); - // debugger; const resetSelectedValue = this.resetSelectedValue(); this.select( resetSelectedValue !== undefined @@ -556,22 +554,16 @@ export class Select2 implements ControlValueAccessor, OnInit, DoCheck, AfterView if (this.isSearchboxHidden && !changeEmit && event) { this.keyDown(event); } else { - setTimeout(() => { - if (this.selectedOption) { - const option = Array.isArray(this.selectedOption) - ? this.selectedOption[0] - : this.selectedOption; - this.updateScrollFromOption(option); - } else if (this.resultsElement) { - this.resultsElement.scrollTop = 0; - } - this._changeDetectorRef.detectChanges(); + if (this.selectedOption) { + const option = Array.isArray(this.selectedOption) ? this.selectedOption[0] : this.selectedOption; + this.updateScrollFromOption(option); + } else if (this.resultsElement) { + this.resultsElement.scrollTop = 0; + } + this._changeDetectorRef.detectChanges(); - setTimeout(() => { - this.triggerRect(); - this.cdkConnectedOverlay().overlayRef?.updatePosition(); - }, 100); - }); + this.triggerRect(); + this.cdkConnectedOverlay().overlayRef?.updatePosition(); } if (changeEmit) { this.open.emit(this);