Skip to content

Commit 223df3d

Browse files
authored
Merge pull request #6510 from IgniteUI/mvenkov/fix-overlay-position-8.2.x
Position correctly overlay - 8.2.x
2 parents cedc291 + aea4b3b commit 223df3d

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
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
@@ -504,7 +504,7 @@ describe('igxOverlay', () => {
504504
expect(BaseFitPositionStrategy.prototype.position).toHaveBeenCalledTimes(3);
505505
});
506506

507-
it('fix for #1690 - click on second filter does not close first one.', fakeAsync(() => {
507+
it('#1690 - click on second filter does not close first one.', fakeAsync(() => {
508508
const fixture = TestBed.createComponent(TwoButtonsComponent);
509509
const button1 = fixture.nativeElement.getElementsByClassName('buttonOne')[0];
510510
const button2 = fixture.nativeElement.getElementsByClassName('buttonTwo')[0];
@@ -521,7 +521,7 @@ describe('igxOverlay', () => {
521521
expect(overlayDiv.children.length).toBe(1);
522522
}));
523523

524-
it('fix for #1692 - scroll strategy closes overlay when shown component is scrolled.', fakeAsync(() => {
524+
it('#1692 - scroll strategy closes overlay when shown component is scrolled.', fakeAsync(() => {
525525
const fixture = TestBed.createComponent(SimpleDynamicWithDirectiveComponent);
526526
const overlaySettings: OverlaySettings = { scrollStrategy: new CloseScrollStrategy() };
527527
fixture.componentInstance.show(overlaySettings);
@@ -548,7 +548,7 @@ describe('igxOverlay', () => {
548548
}));
549549

550550
// TODO: refactor utilities to include all exported methods in a class
551-
it('fix for #1799 - content div should reposition on window resize.', fakeAsync(() => {
551+
it('#1799 - content div should reposition on window resize.', fakeAsync(() => {
552552
const rect: ClientRect = {
553553
bottom: 50,
554554
height: 0,
@@ -590,7 +590,7 @@ describe('igxOverlay', () => {
590590
overlayInstance.hide(id);
591591
}));
592592

593-
it('fix for #2475 - An error is thrown for IgxOverlay when showing a component' +
593+
it('#2475 - An error is thrown for IgxOverlay when showing a component' +
594594
'instance that is not attached to the DOM', fakeAsync(() => {
595595
const fix = TestBed.createComponent(SimpleRefComponent);
596596
fix.detectChanges();
@@ -611,7 +611,7 @@ describe('igxOverlay', () => {
611611
expect(contentDiv.classList.contains(CLASS_OVERLAY_CONTENT_MODAL)).toBeTruthy();
612612
}));
613613

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

@@ -631,7 +631,7 @@ describe('igxOverlay', () => {
631631
expect(fix.componentInstance.customComponent.nativeElement.getBoundingClientRect().left).toBe(400);
632632
}));
633633

634-
it('fix for #2798 - Allow canceling of open and close of IgxDropDown through onOpening and onClosing events', fakeAsync(() => {
634+
it('#2798 - Allow canceling of open and close of IgxDropDown through onOpening and onClosing events', fakeAsync(() => {
635635
const fix = TestBed.createComponent(SimpleRefComponent);
636636
fix.detectChanges();
637637
const overlayInstance = fix.componentInstance.overlay;
@@ -668,7 +668,7 @@ describe('igxOverlay', () => {
668668
expect(overlayInstance.onOpened.emit).toHaveBeenCalledTimes(1);
669669
}));
670670

671-
it('fix for #3673 - Should not close dropdown in dropdown', fakeAsync(() => {
671+
it('#3673 - Should not close dropdown in dropdown', fakeAsync(() => {
672672
const fix = TestBed.createComponent(EmptyPageComponent);
673673
const button = fix.componentInstance.buttonElement;
674674
const overlay = fix.componentInstance.overlay;
@@ -704,7 +704,7 @@ describe('igxOverlay', () => {
704704
expect(overlayDiv.children[0].localName).toEqual('div');
705705
}));
706706

707-
it('fix for #3743 - Reposition correctly resized element.', () => {
707+
it('#3743 - Reposition correctly resized element.', () => {
708708
const fixture = TestBed.createComponent(TopLeftOffsetComponent);
709709
fixture.detectChanges();
710710

@@ -756,7 +756,7 @@ describe('igxOverlay', () => {
756756
document.body.removeChild(wrapperElement);
757757
});
758758

759-
it('Fix for #3988 - Should use ngModuleRef to create component', inject([ApplicationRef], (appRef: ApplicationRef) => {
759+
it('#3988 - Should use ngModuleRef to create component', inject([ApplicationRef], (appRef: ApplicationRef) => {
760760
const fixture = TestBed.createComponent(EmptyPageComponent);
761761
const overlay = fixture.componentInstance.overlay;
762762
fixture.detectChanges();
@@ -780,6 +780,46 @@ describe('igxOverlay', () => {
780780
expect(appRef.attachView).toHaveBeenCalledWith('test');
781781
expect(overlay.getOverlayById(id).componentRef as any).toBe(mockComponent);
782782
}));
783+
784+
it('#6474 - should calculate correctly position', () => {
785+
const elastic: ElasticPositionStrategy = new ElasticPositionStrategy();
786+
const targetRect: ClientRect = {
787+
top: 100,
788+
bottom: 200,
789+
height: 100,
790+
left: 100,
791+
right: 200,
792+
width: 100
793+
};
794+
const elementRect: ClientRect = {
795+
top: 0,
796+
bottom: 300,
797+
height: 300,
798+
left: 0,
799+
right: 300,
800+
width: 300
801+
};
802+
const viewPortRect: ClientRect = {
803+
top: 1000,
804+
bottom: 1300,
805+
height: 300,
806+
left: 1000,
807+
right: 1300,
808+
width: 300
809+
};
810+
spyOn<any>(elastic, 'setStyle').and.returnValue({});
811+
spyOn(Util, 'getViewportRect').and.returnValue(viewPortRect);
812+
spyOn(Util, 'getTargetRect').and.returnValue(targetRect);
813+
814+
const element = jasmine.createSpyObj('HTMLElement', ['getBoundingClientRect'] );
815+
spyOn(element, 'getBoundingClientRect').and.returnValue(elementRect);
816+
element.classList = { add: () => {} };
817+
element.style = { width: '', height: ''};
818+
elastic.position(element, null, null, true);
819+
820+
expect(element.style.width).toBe('200px');
821+
expect(element.style.height).toBe('100px');
822+
});
783823
});
784824

785825
describe('Unit Tests - Scroll Strategies: ', () => {
@@ -2532,7 +2572,7 @@ describe('igxOverlay', () => {
25322572
tick();
25332573
}));
25342574

2535-
// Test fix for #1883 #1820
2575+
// Test #1883 #1820
25362576
it('It should close the component when esc key is pressed and there were other keys pressed prior to esc.', fakeAsync(() => {
25372577
const fixture = TestBed.createComponent(EmptyPageComponent);
25382578
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);
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);
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export abstract class BaseFitPositionStrategy extends ConnectedPositioningStrate
3737
this.settings.horizontalDirection);
3838
connectedFit.right = connectedFit.left + connectedFit.contentElementRect.width;
3939
connectedFit.fitHorizontal =
40-
connectedFit.viewPortRect.left < connectedFit.left && connectedFit.right < connectedFit.viewPortRect.right;
40+
0 < connectedFit.left && connectedFit.right < connectedFit.viewPortRect.width;
4141

4242
connectedFit.top = this.calculateTop(
4343
connectedFit.targetRect,
@@ -46,7 +46,7 @@ export abstract class BaseFitPositionStrategy extends ConnectedPositioningStrate
4646
this.settings.verticalDirection);
4747
connectedFit.bottom = connectedFit.top + connectedFit.contentElementRect.height;
4848
connectedFit.fitVertical =
49-
connectedFit.viewPortRect.top < connectedFit.top && connectedFit.bottom < connectedFit.viewPortRect.bottom;
49+
0 < connectedFit.top && connectedFit.bottom < connectedFit.viewPortRect.height;
5050
}
5151

5252
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export class ElasticPositionStrategy extends BaseFitPositionStrategy {
1212
const transformString: string[] = [];
1313
if (!connectedFit.fitHorizontal) {
1414
const maxReduction = Math.max(0, connectedFit.contentElementRect.width - this.settings.minSize.width);
15-
const leftExtend = Math.max(0, connectedFit.viewPortRect.left - connectedFit.left);
16-
const rightExtend = Math.max(0, connectedFit.right - connectedFit.viewPortRect.right);
15+
const leftExtend = Math.max(0, 0 - connectedFit.left);
16+
const rightExtend = Math.max(0, connectedFit.right - connectedFit.viewPortRect.width);
1717
const reduction = Math.min(maxReduction, leftExtend + rightExtend);
1818
element.style.width = `${connectedFit.contentElementRect.width - reduction}px`;
1919

@@ -33,8 +33,8 @@ export class ElasticPositionStrategy extends BaseFitPositionStrategy {
3333

3434
if (!connectedFit.fitVertical) {
3535
const maxReduction = Math.max(0, connectedFit.contentElementRect.height - this.settings.minSize.height);
36-
const topExtend = Math.max(0, connectedFit.viewPortRect.top - connectedFit.top);
37-
const bottomExtend = Math.max(0, connectedFit.bottom - connectedFit.viewPortRect.bottom);
36+
const topExtend = Math.max(0, 0 - connectedFit.top);
37+
const bottomExtend = Math.max(0, connectedFit.bottom - connectedFit.viewPortRect.height);
3838
const reduction = Math.min(maxReduction, topExtend + bottomExtend);
3939
element.style.height = `${connectedFit.contentElementRect.height - reduction}px`;
4040

0 commit comments

Comments
 (0)