Skip to content

Commit a6a8e06

Browse files
authored
Merge pull request #6504 from IgniteUI/mvenkov/fix-overlay-position
fix(overlay): Position correctly overlay
2 parents 3145e98 + af413fd commit a6a8e06

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

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

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ describe('igxOverlay', () => {
549549
expect(overlayContentTransform).toEqual(secondTransform);
550550
}));
551551

552-
it('fix for #1690 - click on second filter does not close first one.', fakeAsync(() => {
552+
it('#1690 - click on second filter does not close first one.', fakeAsync(() => {
553553
const fixture = TestBed.createComponent(TwoButtonsComponent);
554554
const button1 = fixture.nativeElement.getElementsByClassName('buttonOne')[0];
555555
const button2 = fixture.nativeElement.getElementsByClassName('buttonTwo')[0];
@@ -566,7 +566,7 @@ describe('igxOverlay', () => {
566566
expect(overlayDiv.children.length).toBe(1);
567567
}));
568568

569-
it('fix for #1692 - scroll strategy closes overlay when shown component is scrolled.', fakeAsync(() => {
569+
it('#1692 - scroll strategy closes overlay when shown component is scrolled.', fakeAsync(() => {
570570
const fixture = TestBed.createComponent(SimpleDynamicWithDirectiveComponent);
571571
const overlaySettings: OverlaySettings = { scrollStrategy: new CloseScrollStrategy() };
572572
fixture.componentInstance.show(overlaySettings);
@@ -593,7 +593,7 @@ describe('igxOverlay', () => {
593593
}));
594594

595595
// TODO: refactor utilities to include all exported methods in a class
596-
it('fix for #1799 - content div should reposition on window resize.', fakeAsync(() => {
596+
it('#1799 - content div should reposition on window resize.', fakeAsync(() => {
597597
const rect: ClientRect = {
598598
bottom: 50,
599599
height: 0,
@@ -635,7 +635,7 @@ describe('igxOverlay', () => {
635635
overlayInstance.hide(id);
636636
}));
637637

638-
it('fix for #2475 - An error is thrown for IgxOverlay when showing a component' +
638+
it('#2475 - An error is thrown for IgxOverlay when showing a component' +
639639
'instance that is not attached to the DOM', fakeAsync(() => {
640640
const fix = TestBed.createComponent(SimpleRefComponent);
641641
fix.detectChanges();
@@ -656,7 +656,7 @@ describe('igxOverlay', () => {
656656
expect(contentDiv.classList.contains(CLASS_OVERLAY_CONTENT_MODAL)).toBeTruthy();
657657
}));
658658

659-
it('fix for #2486 - filtering dropdown is not correctly positioned', fakeAsync(() => {
659+
it('#2486 - filtering dropdown is not correctly positioned', fakeAsync(() => {
660660
const fix = TestBed.createComponent(WidthTestOverlayComponent);
661661
fix.debugElement.nativeElement.style.transform = 'translatex(100px)';
662662

@@ -676,7 +676,7 @@ describe('igxOverlay', () => {
676676
expect(fix.componentInstance.customComponent.nativeElement.getBoundingClientRect().left).toBe(400);
677677
}));
678678

679-
it('fix for #2798 - Allow canceling of open and close of IgxDropDown through onOpening and onClosing events', fakeAsync(() => {
679+
it('#2798 - Allow canceling of open and close of IgxDropDown through onOpening and onClosing events', fakeAsync(() => {
680680
const fix = TestBed.createComponent(SimpleRefComponent);
681681
fix.detectChanges();
682682
const overlayInstance = fix.componentInstance.overlay;
@@ -713,7 +713,7 @@ describe('igxOverlay', () => {
713713
expect(overlayInstance.onOpened.emit).toHaveBeenCalledTimes(1);
714714
}));
715715

716-
it('fix for #3673 - Should not close dropdown in dropdown', fakeAsync(() => {
716+
it('#3673 - Should not close dropdown in dropdown', fakeAsync(() => {
717717
const fix = TestBed.createComponent(EmptyPageComponent);
718718
const button = fix.componentInstance.buttonElement;
719719
const overlay = fix.componentInstance.overlay;
@@ -749,7 +749,7 @@ describe('igxOverlay', () => {
749749
expect(overlayDiv.children[0].localName).toEqual('div');
750750
}));
751751

752-
it('fix for #3743 - Reposition correctly resized element.', () => {
752+
it('#3743 - Reposition correctly resized element.', () => {
753753
const fixture = TestBed.createComponent(TopLeftOffsetComponent);
754754
fixture.detectChanges();
755755

@@ -801,7 +801,7 @@ describe('igxOverlay', () => {
801801
document.body.removeChild(wrapperElement);
802802
});
803803

804-
it('Fix for #3988 - Should use ngModuleRef to create component', inject([ApplicationRef], (appRef: ApplicationRef) => {
804+
it('#3988 - Should use ngModuleRef to create component', inject([ApplicationRef], (appRef: ApplicationRef) => {
805805
const fixture = TestBed.createComponent(EmptyPageComponent);
806806
const overlay = fixture.componentInstance.overlay;
807807
fixture.detectChanges();
@@ -825,6 +825,46 @@ describe('igxOverlay', () => {
825825
expect(appRef.attachView).toHaveBeenCalledWith('test');
826826
expect(overlay.getOverlayById(id).componentRef as any).toBe(mockComponent);
827827
}));
828+
829+
it('##6474 - should calculate correctly position', () => {
830+
const elastic: ElasticPositionStrategy = new ElasticPositionStrategy();
831+
const targetRect: ClientRect = {
832+
top: 100,
833+
bottom: 200,
834+
height: 100,
835+
left: 100,
836+
right: 200,
837+
width: 100
838+
};
839+
const elementRect: ClientRect = {
840+
top: 0,
841+
bottom: 300,
842+
height: 300,
843+
left: 0,
844+
right: 300,
845+
width: 300
846+
};
847+
const viewPortRect: ClientRect = {
848+
top: 1000,
849+
bottom: 1300,
850+
height: 300,
851+
left: 1000,
852+
right: 1300,
853+
width: 300
854+
};
855+
spyOn<any>(elastic, 'setStyle').and.returnValue({});
856+
spyOn(Util, 'getViewportRect').and.returnValue(viewPortRect);
857+
spyOn(Util, 'getTargetRect').and.returnValue(targetRect);
858+
859+
const element = jasmine.createSpyObj('HTMLElement', ['getBoundingClientRect'] );
860+
spyOn(element, 'getBoundingClientRect').and.returnValue(elementRect);
861+
element.classList = { add: () => {} };
862+
element.style = { width: '', height: ''};
863+
elastic.position(element, null, null, true);
864+
865+
expect(element.style.width).toBe('200px');
866+
expect(element.style.height).toBe('100px');
867+
});
828868
});
829869

830870
describe('Unit Tests - Scroll Strategies: ', () => {
@@ -2617,7 +2657,7 @@ describe('igxOverlay', () => {
26172657
tick();
26182658
}));
26192659

2620-
// Test fix for #1883 #1820
2660+
// Test #1883 #1820
26212661
it('It should close the component when esc key is pressed and there were other keys pressed prior to esc.', fakeAsync(() => {
26222662
const fixture = TestBed.createComponent(EmptyPageComponent);
26232663
const overlay = fixture.componentInstance.overlay;

projects/igniteui-angular/src/lib/services/overlay/position/auto-position-strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class AutoPositionStrategy extends BaseFitPositionStrategy {
5050
const leftBorder = this.calculateLeft(
5151
connectedFit.targetRect, connectedFit.contentElementRect, flippedStartPoint, flippedDirection, 0);
5252
const rightBorder = leftBorder + connectedFit.contentElementRect.width;
53-
return connectedFit.viewPortRect.left < leftBorder && rightBorder < connectedFit.viewPortRect.right;
53+
return 0 < leftBorder && rightBorder < connectedFit.viewPortRect.width;
5454
}
5555

5656
/**
@@ -65,7 +65,7 @@ export class AutoPositionStrategy extends BaseFitPositionStrategy {
6565
const topBorder = this.calculateTop(
6666
connectedFit.targetRect, connectedFit.contentElementRect, flippedStartPoint, flippedDirection, 0);
6767
const bottomBorder = topBorder + connectedFit.contentElementRect.height;
68-
return connectedFit.viewPortRect.top < topBorder && bottomBorder < connectedFit.viewPortRect.bottom;
68+
return 0 < topBorder && bottomBorder < connectedFit.viewPortRect.height;
6969
}
7070

7171
/**

projects/igniteui-angular/src/lib/services/overlay/position/base-fit-position-strategy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export abstract class BaseFitPositionStrategy extends ConnectedPositioningStrate
3838
connectedFit.horizontalOffset ? connectedFit.horizontalOffset : 0);
3939
connectedFit.right = connectedFit.left + connectedFit.contentElementRect.width;
4040
connectedFit.fitHorizontal = {
41-
back: Math.round(connectedFit.left - connectedFit.viewPortRect.left),
42-
forward: Math.round(connectedFit.viewPortRect.right - connectedFit.right)
41+
back: Math.round(connectedFit.left),
42+
forward: Math.round(connectedFit.viewPortRect.width - connectedFit.right)
4343
};
4444

4545
connectedFit.top = this.calculateTop(
@@ -50,8 +50,8 @@ export abstract class BaseFitPositionStrategy extends ConnectedPositioningStrate
5050
connectedFit.verticalOffset ? connectedFit.verticalOffset : 0);
5151
connectedFit.bottom = connectedFit.top + connectedFit.contentElementRect.height;
5252
connectedFit.fitVertical = {
53-
back: Math.round(connectedFit.top - connectedFit.viewPortRect.top),
54-
forward: Math.round(connectedFit.viewPortRect.bottom - connectedFit.bottom)
53+
back: Math.round(connectedFit.top),
54+
forward: Math.round(connectedFit.viewPortRect.height - connectedFit.bottom)
5555
};
5656
}
5757

0 commit comments

Comments
 (0)