Skip to content

Commit 443da89

Browse files
authored
Merge branch 'master' into rkaraivanov/multi-column-headers
2 parents c8a844e + f01bb52 commit 443da89

File tree

6 files changed

+145
-75
lines changed

6 files changed

+145
-75
lines changed

projects/igniteui-angular/src/lib/directives/toggle/toggle.directive.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
7373
public open(fireEvents?: boolean, overlaySettings?: OverlaySettings) {
7474
if (!this.collapsed) { return; }
7575

76+
this.collapsed = false;
77+
this.cdr.detectChanges();
78+
7679
if (fireEvents) {
7780
this.onOpening.emit();
7881
}
7982

80-
this.collapsed = false;
81-
8283
this._overlayId = this.overlayService.show(this.elementRef, overlaySettings);
8384
this._overlayClosedSub = this.overlayService.onClosed
8485
.pipe(...this._overlaySubFilter)

projects/igniteui-angular/src/lib/drop-down/drop-down-item.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
HostBinding,
66
HostListener,
77
Inject,
8-
Input } from '@angular/core';
8+
Input
9+
} from '@angular/core';
910
import { IgxDropDownComponent, ISelectionEventArgs } from './drop-down.component';
1011

1112
/**
@@ -52,7 +53,7 @@ export class IgxDropDownItemComponent {
5253
}
5354

5455
if (value && !this.dropDown.collapsed) {
55-
this.elementRef.nativeElement.focus();
56+
this.elementRef.nativeElement.focus({ preventScroll: true });
5657
}
5758
this._isFocused = value;
5859
}

projects/igniteui-angular/src/lib/drop-down/drop-down.component.spec.ts

+48-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ContentChildren, DebugElement, ViewChild } from '@angular/core';
1+
import { Component, ContentChildren, DebugElement, ViewChild, OnInit } from '@angular/core';
22
import { async, fakeAsync, TestBed, tick } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
@@ -29,7 +29,8 @@ describe('IgxDropDown ', () => {
2929
IgxDropDownTestScrollComponent,
3030
IgxDropDownTestDisabledComponent,
3131
IgxDropDownTestDisabledAnyComponent,
32-
IgxDropDownTestEmptyListComponent
32+
IgxDropDownTestEmptyListComponent,
33+
IgxDropDownWithScrollComponent
3334
],
3435
imports: [
3536
IgxDropDownModule,
@@ -807,6 +808,19 @@ describe('IgxDropDown ', () => {
807808
expect(igxDropDown.collapsed).toEqual(true);
808809
});
809810
}));
811+
812+
it('#1663 drop down flickers on open', () => {
813+
const fixture = TestBed.createComponent(IgxDropDownWithScrollComponent);
814+
fixture.detectChanges();
815+
const button = fixture.debugElement.query(By.css('button')).nativeElement;
816+
const igxDropDown = fixture.componentInstance.dropdownScroll;
817+
button.click();
818+
igxDropDown.open();
819+
fixture.whenStable().then(() => {
820+
fixture.detectChanges();
821+
expect((<any>igxDropDown).toggleDirective.element.scrollTop).toEqual(44);
822+
});
823+
});
810824
});
811825

812826
@Component({
@@ -997,3 +1011,35 @@ class IgxDropDownTestEmptyListComponent {
9971011
this.dropdownEmpty.toggle();
9981012
}
9991013
}
1014+
@Component({
1015+
template: `
1016+
<button (click)="selectItem5()">Select 5</button>
1017+
<igx-drop-down #scrollDropDown>
1018+
<igx-drop-down-item *ngFor="let item of items">
1019+
{{ item.field }}
1020+
</igx-drop-down-item>
1021+
</igx-drop-down>
1022+
`
1023+
})
1024+
class IgxDropDownWithScrollComponent implements OnInit {
1025+
1026+
@ViewChild('scrollDropDown', { read: IgxDropDownComponent })
1027+
public dropdownScroll: IgxDropDownComponent;
1028+
1029+
public items: any[] = [];
1030+
1031+
public toggleDropDown() {
1032+
this.dropdownScroll.toggle();
1033+
}
1034+
1035+
public selectItem5() {
1036+
this.dropdownScroll.setSelectedItem(4);
1037+
}
1038+
1039+
ngOnInit() {
1040+
this.dropdownScroll.height = '200px';
1041+
for (let index = 1; index < 100; index++) {
1042+
this.items.push({ field: 'Item ' + index });
1043+
}
1044+
}
1045+
}

projects/igniteui-angular/src/lib/drop-down/drop-down.component.ts

-2
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,6 @@ export class IgxDropDownComponent implements OnInit {
402402
* @hidden
403403
*/
404404
onToggleOpening() {
405-
this.toggleDirective.collapsed = false;
406-
this.cdr.detectChanges();
407405
this.scrollToItem(this.selectedItem);
408406
this.onOpening.emit();
409407
}

0 commit comments

Comments
 (0)