Skip to content

Commit f996da9

Browse files
authored
Merge pull request #6165 from IgniteUI/dpetev/overlay-absolute-scroll-calls
Fix overlay absolute scroll strategy unnecessary position calls
2 parents 70f86c9 + 97f3bea commit f996da9

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

Diff for: projects/igniteui-angular/src/lib/services/overlay/overlay.spec.ts

+40
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,46 @@ describe('igxOverlay', () => {
915915
expect(scrollStrat.detach).toHaveBeenCalledTimes(1);
916916
}));
917917

918+
it('Should only call reposition once on scroll - Absolute.', fakeAsync(async () => {
919+
TestBed.overrideComponent(EmptyPageComponent, {
920+
set: {
921+
styles: [`button {
922+
position: absolute,
923+
bottom: 200%;
924+
}`]
925+
}
926+
});
927+
await TestBed.compileComponents();
928+
const fixture = TestBed.createComponent(EmptyPageComponent);
929+
fixture.detectChanges();
930+
931+
const scrollStrat = new AbsoluteScrollStrategy();
932+
const overlaySettings: OverlaySettings = {
933+
positionStrategy: new GlobalPositionStrategy(),
934+
scrollStrategy: scrollStrat,
935+
modal: false,
936+
closeOnOutsideClick: false
937+
};
938+
const overlay = fixture.componentInstance.overlay;
939+
const scrollSpy = spyOn<any>(scrollStrat, 'onScroll').and.callThrough();
940+
spyOn(overlay, 'reposition');
941+
const id = overlay.attach(SimpleDynamicComponent, overlaySettings);
942+
overlay.show(id, overlaySettings);
943+
tick();
944+
945+
const content = document.getElementsByClassName(CLASS_OVERLAY_CONTENT)[0];
946+
content.children[0].dispatchEvent(new Event('scroll'));
947+
expect(scrollSpy).toHaveBeenCalledTimes(1);
948+
expect(overlay.reposition).not.toHaveBeenCalled();
949+
950+
document.dispatchEvent(new Event('scroll'));
951+
expect(scrollSpy).toHaveBeenCalledTimes(2);
952+
expect(overlay.reposition).toHaveBeenCalledTimes(1);
953+
expect(overlay.reposition).toHaveBeenCalledWith(id);
954+
955+
overlay.hide(id);
956+
}));
957+
918958
it('Should properly initialize Scroll Strategy - Close.', fakeAsync(async () => {
919959
TestBed.overrideComponent(EmptyPageComponent, {
920960
set: {

Diff for: projects/igniteui-angular/src/lib/services/overlay/scroll/absolute-scroll-strategy.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ export class AbsoluteScrollStrategy extends ScrollStrategy {
6060
}
6161
}
6262

63-
private onScroll = () => {
64-
this._overlayService.repositionAll();
63+
private onScroll = (e: Event) => {
64+
const overlayInfo = this._overlayService.getOverlayById(this._id);
65+
if (!overlayInfo) {
66+
return;
67+
}
68+
if (!overlayInfo.elementRef.nativeElement.contains(e.target)) {
69+
this._overlayService.reposition(this._id);
70+
}
6571
}
6672
}

0 commit comments

Comments
 (0)