Skip to content

Commit

Permalink
Remove setTimeout not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Zefling committed Dec 11, 2024
1 parent 513a75c commit b492d26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
(scrolled)="onScroll('down')"
(scrolledUp)="onScroll('up')"
(keydown)="keyDown($event)"

>
@if (showSelectAll() && multiple()) {
<li class="select2-results__option select2-selectall" (click)="selectAll()" tabindex="1" aria-selected>
Expand Down
26 changes: 9 additions & 17 deletions projects/ng-select2-component/src/lib/select2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b492d26

Please sign in to comment.