Skip to content

Commit 51b28f4

Browse files
committed
fix: opt for app ref tick call inside dropdown list
1 parent 1166c73 commit 51b28f4

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/dropdown/dropdown.component.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ export class Dropdown implements OnInit, AfterContentInit, AfterViewInit, OnDest
357357
protected elementRef: ElementRef,
358358
protected i18n: I18n,
359359
protected dropdownService: DropdownService,
360-
protected ngZone: NgZone,
361360
protected elementService: ElementService) {}
362361

363362
/**
@@ -387,36 +386,34 @@ export class Dropdown implements OnInit, AfterContentInit, AfterViewInit, OnDest
387386
const isUpdate = event => event && event.isUpdate;
388387

389388
this.view.select.subscribe(event => {
390-
this.ngZone.run(() => {
391-
if (this.type === "single" && !isUpdate(event)) {
392-
this.closeMenu();
393-
if (event.item && event.item.selected) {
394-
if (this.itemValueKey) {
395-
this.propagateChange(event.item[this.itemValueKey]);
396-
} else {
397-
this.propagateChange(event.item);
398-
}
389+
if (this.type === "single" && !isUpdate(event)) {
390+
this.closeMenu();
391+
if (event.item && event.item.selected) {
392+
if (this.itemValueKey) {
393+
this.propagateChange(event.item[this.itemValueKey]);
399394
} else {
400-
this.propagateChange(null);
395+
this.propagateChange(event.item);
401396
}
397+
} else {
398+
this.propagateChange(null);
402399
}
400+
}
403401

404-
if (this.type === "multi" && !isUpdate(event)) {
405-
// if we have a `value` selector and selected items map them appropriately
406-
if (this.itemValueKey && this.view.getSelected()) {
407-
const values = this.view.getSelected().map(item => item[this.itemValueKey]);
408-
this.propagateChange(values);
409-
// otherwise just pass up the values from `getSelected`
410-
} else {
411-
this.propagateChange(this.view.getSelected());
412-
}
413-
}
414-
// only emit selected for "organic" selections
415-
if (!isUpdate(event)) {
416-
this.checkForReorder();
417-
this.selected.emit(event);
402+
if (this.type === "multi" && !isUpdate(event)) {
403+
// if we have a `value` selector and selected items map them appropriately
404+
if (this.itemValueKey && this.view.getSelected()) {
405+
const values = this.view.getSelected().map(item => item[this.itemValueKey]);
406+
this.propagateChange(values);
407+
// otherwise just pass up the values from `getSelected`
408+
} else {
409+
this.propagateChange(this.view.getSelected());
418410
}
419-
});
411+
}
412+
// only emit selected for "organic" selections
413+
if (!isUpdate(event)) {
414+
this.checkForReorder();
415+
this.selected.emit(event);
416+
}
420417
});
421418
}
422419

src/dropdown/list/dropdown-list.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
ViewChild,
1010
ElementRef,
1111
ViewChildren,
12-
QueryList
12+
QueryList,
13+
ApplicationRef
1314
} from "@angular/core";
1415
import { Observable, isObservable, Subscription, of } from "rxjs";
1516
import { first } from "rxjs/operators";
@@ -226,7 +227,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
226227
/**
227228
* Creates an instance of `DropdownList`.
228229
*/
229-
constructor(public elementRef: ElementRef, protected i18n: I18n) {}
230+
constructor(public elementRef: ElementRef, protected i18n: I18n, protected appRef: ApplicationRef) {}
230231

231232
/**
232233
* Retrieves array of list items and index of the selected item after view has rendered.
@@ -574,6 +575,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
574575
this.index = this.displayItems.indexOf(item);
575576
this.highlightedItem = this.getItemId(this.index);
576577
this.doEmitSelect(false);
578+
this.appRef.tick();
577579
}
578580
}
579581

0 commit comments

Comments
 (0)