Skip to content

Commit e8f7c7d

Browse files
authored
Merge pull request #2491 from IgniteUI/mvenkov/reposition-outlet-in-perspective-container
Fix the position of content element, #2486
2 parents 2c4c07b + aaaa18e commit e8f7c7d

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,26 @@ describe('igxOverlay', () => {
717717
expect(contentDiv).toBeDefined();
718718
expect(contentDiv.classList.contains(CLASS_OVERLAY_CONTENT_MODAL)).toBeTruthy();
719719
}));
720+
721+
it('fix for #2486 - filtering dropdown is not correctly positioned', fakeAsync(() => {
722+
const fix = TestBed.createComponent(WidthTestOverlayComponent);
723+
fix.debugElement.nativeElement.style.transform = 'translatex(100px)';
724+
725+
fix.detectChanges();
726+
tick();
727+
728+
fix.componentInstance.overlaySettings.outlet = fix.componentInstance.elementRef;
729+
730+
const buttonElement: HTMLElement = fix.componentInstance.buttonElement.nativeElement;
731+
buttonElement.click();
732+
733+
fix.detectChanges();
734+
tick();
735+
736+
const wrapper = document.getElementsByClassName(CLASS_OVERLAY_WRAPPER)[0];
737+
expect(wrapper.getBoundingClientRect().left).toBe(100);
738+
expect(fix.componentInstance.customComponent.nativeElement.getBoundingClientRect().left).toBe(400);
739+
}));
720740
});
721741

722742
describe('Integration tests: ', () => {
@@ -2560,20 +2580,22 @@ export class TwoButtonsComponent {
25602580
})
25612581
export class WidthTestOverlayComponent {
25622582

2563-
constructor(@Inject(IgxOverlayService) public overlay: IgxOverlayService) { }
2583+
constructor(
2584+
@Inject(IgxOverlayService) public overlay: IgxOverlayService,
2585+
public elementRef: ElementRef
2586+
) { }
25642587

25652588
@ViewChild('button') buttonElement: ElementRef;
25662589
@ViewChild('myCustomComponent') customComponent: ElementRef;
2590+
public overlaySettings: OverlaySettings = {};
25672591
click(event) {
2568-
const overlaySettings: OverlaySettings = {
2569-
positionStrategy: new ConnectedPositioningStrategy(),
2570-
scrollStrategy: new NoOpScrollStrategy(),
2571-
closeOnOutsideClick: true,
2572-
modal: false
2573-
};
2592+
this.overlaySettings.positionStrategy = new ConnectedPositioningStrategy();
2593+
this.overlaySettings.scrollStrategy = new NoOpScrollStrategy();
2594+
this.overlaySettings.closeOnOutsideClick = true;
2595+
this.overlaySettings.modal = false;
25742596

2575-
overlaySettings.positionStrategy.settings.target = this.buttonElement.nativeElement;
2576-
this.overlay.show(this.customComponent, overlaySettings);
2597+
this.overlaySettings.positionStrategy.settings.target = this.buttonElement.nativeElement;
2598+
this.overlay.show(this.customComponent, this.overlaySettings);
25772599
}
25782600
}
25792601

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ export class ConnectedPositioningStrategy implements IPositionStrategy {
2020

2121
// we no longer use the element inside the position() as its dimensions are cached in rect
2222
position(contentElement: HTMLElement, size: { width: number, height: number}, document?: Document, initialCall?: boolean): void {
23-
const eWidth = size.width;
24-
const eHeight = size.height;
23+
const startPoint = getPointFromPositionsSettings(this.settings, contentElement.parentElement);
2524

26-
contentElement.style.top = getPointFromPositionsSettings(this.settings).y + this.settings.verticalDirection * size.height + 'px';
27-
contentElement.style.left = getPointFromPositionsSettings(this.settings).x + this.settings.horizontalDirection * size.width + 'px';
25+
contentElement.style.top = startPoint.y + this.settings.verticalDirection * size.height + 'px';
26+
contentElement.style.left = startPoint.x + this.settings.horizontalDirection * size.width + 'px';
2827
}
2928
}
3029

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface OverlayEventArgs {
4848
}
4949

5050
/** @hidden */
51-
export function getPointFromPositionsSettings(settings: PositionSettings): Point {
51+
export function getPointFromPositionsSettings(settings: PositionSettings, overlayWrapper: HTMLElement): Point {
5252
let result: Point = new Point(0, 0);
5353

5454
if (settings.target instanceof HTMLElement) {
@@ -59,6 +59,15 @@ export function getPointFromPositionsSettings(settings: PositionSettings): Point
5959
result = settings.target;
6060
}
6161

62+
// if for some reason overlayWrapper is not at 0,0 position, e.g. overlay is in outlet
63+
// which is in element with transform,perspective or filter set, we should translate the result
64+
// accordingly
65+
if (overlayWrapper) {
66+
const overlayWrapperPosition = overlayWrapper.getBoundingClientRect();
67+
result.x -= overlayWrapperPosition.left;
68+
result.y -= overlayWrapperPosition.top;
69+
}
70+
6271
return result;
6372
}
6473

0 commit comments

Comments
 (0)