Skip to content

Commit 0f52b6f

Browse files
committed
fix(overlay): conditionally cache element size
1 parent 0a81791 commit 0f52b6f

5 files changed

Lines changed: 32 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ describe('igxOverlay', () => {
569569
scrollStrategy: new NoOpScrollStrategy(),
570570
modal: true,
571571
closeOnOutsideClick: true,
572-
closeOnEscape: false
572+
closeOnEscape: false,
573+
cacheSize: true
573574
};
574575

575576
spyOn(overlayInstance.contentAppending, 'emit');
@@ -3506,7 +3507,7 @@ describe('igxOverlay', () => {
35063507
}));
35073508

35083509
// 4. Css
3509-
it('Should use component initial container\'s properties when is with 100% width and show in overlay element',
3510+
it('Should use component initial container\'s properties based on cacheSize when it\'s with 100% width and shown in overlay element',
35103511
fakeAsync(() => {
35113512
const fixture = TestBed.createComponent(WidthTestOverlayComponent);
35123513
fixture.detectChanges();
@@ -3525,6 +3526,15 @@ describe('igxOverlay', () => {
35253526
// content element has no height, so the shown element will calculate its own height by itself
35263527
// expect(overlayChild.style.height).toEqual('100%');
35273528
// expect(overlayChild.getBoundingClientRect().height).toEqual(280);
3529+
3530+
fixture.componentInstance.overlaySettings.cacheSize = false;
3531+
fixture.componentInstance.buttonElement.nativeElement.click();
3532+
tick();
3533+
const componentElement2 = fixture.componentInstance.customComponent.nativeElement;
3534+
expect(componentElement2.style.width).toEqual('100%');
3535+
expect(componentElement2.getBoundingClientRect().width).toEqual(123);
3536+
// Check overlay content element width
3537+
expect(componentElement2.parentElement.getBoundingClientRect().width).toEqual(123);
35283538
fixture.componentInstance.overlay.detachAll();
35293539
}));
35303540
});
@@ -4679,7 +4689,7 @@ export class TwoButtonsComponent {
46794689
<div style="width: 420px; height: 280px;">
46804690
<button class='300_button' igxToggle #button (click)='click($event)'>Show Overlay</button>
46814691
<div #myCustomComponent class="customList" style="width: 100%; height: 100%;">
4682-
Some Content
4692+
<p style="width: 123px;">Some Content</p>
46834693
</div>
46844694
</div>`,
46854695
styles: [`button {

projects/igniteui-angular/core/src/services/overlay/overlay.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ export class IgxOverlayService implements OnDestroy {
130130
scrollStrategy: new NoOpScrollStrategy(),
131131
modal: true,
132132
closeOnOutsideClick: true,
133-
closeOnEscape: false
133+
closeOnEscape: false,
134+
cacheSize: true
134135
};
135136

136137
constructor() {
@@ -331,11 +332,18 @@ export class IgxOverlayService implements OnDestroy {
331332
info.settings = eventArgs.settings;
332333
this._overlayInfos.push(info);
333334
info.hook = this.placeElementHook(info.elementRef.nativeElement);
334-
const elementRect = info.elementRef.nativeElement.getBoundingClientRect();
335-
info.initialSize = { width: elementRect.width, height: elementRect.height };
335+
let elementRect;
336+
// Get the element rect size before moving it into the overlay to cache its size.
337+
if (info.settings.cacheSize) {
338+
elementRect = info.elementRef.nativeElement.getBoundingClientRect();
339+
}
336340
// Get the size before moving the container into the overlay so that it does not forget about inherited styles.
337341
this.getComponentSize(info);
338342
this.moveElementToOverlay(info);
343+
if (!info.settings.cacheSize) {
344+
elementRect = info.elementRef.nativeElement.getBoundingClientRect();
345+
}
346+
info.initialSize = { width: elementRect.width, height: elementRect.height };
339347
// Update the container size after moving if there is size.
340348
if (info.size) {
341349
info.elementRef.nativeElement.parentElement.style.setProperty('--ig-size', info.size);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ export interface OverlaySettings {
134134
* Clicking on the elements in this collection will not close the overlay when closeOnOutsideClick = true.
135135
*/
136136
excludeFromOutsideClick?: HTMLElement[];
137+
/**
138+
* @hidden @internal
139+
* Set if the element should retain its size when moved to the overlay.
140+
*/
141+
cacheSize?: boolean;
137142
}
138143

139144
export interface OverlayEventArgs extends IBaseEventArgs {

projects/igniteui-angular/directives/src/directives/notification/notifications.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export abstract class IgxNotificationsDirective extends IgxToggleDirective
8686
closeOnEscape: false,
8787
closeOnOutsideClick: false,
8888
modal: false,
89-
outlet: this.outlet
89+
outlet: this.outlet,
90+
cacheSize: false
9091
};
9192

9293
super.open(overlaySettings);

projects/igniteui-angular/directives/src/directives/tooltip/tooltip-target.directive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
400400
this._overlayDefaults.positionStrategy = new TooltipPositionStrategy(this._positionSettings);
401401
this._overlayDefaults.closeOnOutsideClick = false;
402402
this._overlayDefaults.closeOnEscape = true;
403+
this._overlayDefaults.cacheSize = false;
403404

404405
this.target.closing.pipe(takeUntil(this._destroy$)).subscribe((event) => {
405406
if (this.target.tooltipTarget !== this) {

0 commit comments

Comments
 (0)