Skip to content

Commit 9e5f3cd

Browse files
authored
Merge pull request #15283 from IgniteUI/mvenkov/use-passed-overlay-settings
Use provided in show method overlay settings
2 parents 32a5e77 + f478bd1 commit 9e5f3cd

File tree

5 files changed

+116
-7
lines changed

5 files changed

+116
-7
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,38 @@ describe('igxOverlay', () => {
13781378
expect(overlayContent.style.getPropertyValue('--ig-size')).toEqual('1');
13791379
overlayInstance.detach(firstCallId);
13801380
}));
1381+
1382+
it('#15228 - Should use provided in show overlay settings ', fakeAsync(() => {
1383+
const fixture = TestBed.createComponent(SimpleRefComponent);
1384+
fixture.detectChanges();
1385+
const overlayInstance = fixture.componentInstance.overlay;
1386+
const id = overlayInstance.attach(SimpleDynamicComponent);
1387+
const info = overlayInstance.getOverlayById(id);
1388+
const initialPositionSpy = spyOn(info.settings.positionStrategy, 'position').and.callThrough();
1389+
1390+
overlayInstance.show(id);
1391+
tick();
1392+
1393+
expect(initialPositionSpy).toHaveBeenCalledTimes(1);
1394+
overlayInstance.hide(id);
1395+
tick();
1396+
1397+
const os: OverlaySettings = {
1398+
excludeFromOutsideClick: [],
1399+
positionStrategy: new GlobalPositionStrategy(),
1400+
scrollStrategy: new CloseScrollStrategy(),
1401+
modal: false,
1402+
closeOnOutsideClick: false,
1403+
closeOnEscape: true
1404+
};
1405+
const lastPositionSpy = spyOn(os.positionStrategy, 'position').and.callThrough();
1406+
overlayInstance.show(id, os);
1407+
tick();
1408+
1409+
expect(lastPositionSpy).toHaveBeenCalledTimes(1);
1410+
expect(info.settings.scrollStrategy).toBe(os.scrollStrategy);
1411+
expect(info.settings.positionStrategy).toBe(os.positionStrategy);
1412+
}));
13811413
});
13821414

13831415
describe('Unit Tests - Scroll Strategies: ', () => {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export class IgxOverlayService implements OnDestroy {
347347
const elementRect = info.elementRef.nativeElement.getBoundingClientRect();
348348
info.initialSize = { width: elementRect.width, height: elementRect.height };
349349
// Get the size before moving the container into the overlay so that it does not forget about inherited styles.
350-
this.getComponentSize(info);
350+
this.getComponentSize(info);
351351
this.moveElementToOverlay(info);
352352
// Update the container size after moving if there is size.
353353
if (info.size) {
@@ -416,7 +416,9 @@ export class IgxOverlayService implements OnDestroy {
416416
return;
417417
}
418418
if (settings) {
419-
// TODO: update attach
419+
settings.positionStrategy ??= info.settings.positionStrategy;
420+
settings.scrollStrategy ??= info.settings.scrollStrategy;
421+
info.settings = { ...info.settings, ...settings };
420422
}
421423
this.updateSize(info);
422424
info.settings.positionStrategy.position(
@@ -597,7 +599,7 @@ export class IgxOverlayService implements OnDestroy {
597599
const createSettings = viewContainerRefOrSettings as OverlayCreateSettings | undefined;
598600
let elementInjector: Injector;
599601
if (createSettings) {
600-
({ injector: elementInjector, ...overlaySettings} = createSettings);
602+
({ injector: elementInjector, ...overlaySettings } = createSettings);
601603
}
602604
dynamicComponent = createComponent(component, { environmentInjector, elementInjector });
603605
this._appRef.attachView(dynamicComponent.hostView);
@@ -615,7 +617,7 @@ export class IgxOverlayService implements OnDestroy {
615617
info.elementRef = { nativeElement: element };
616618
info.componentRef = dynamicComponent;
617619
}
618-
info.settings = Object.assign({}, this._defaultSettings, overlaySettings);
620+
info.settings = Object.assign({}, this._defaultSettings, overlaySettings);
619621
return info;
620622
}
621623

src/app/overlay/overlay-animation.sample.html

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div #container>
2-
<section class="sample-content">
2+
<h5 style="text-align: center;">Move mouse over the avatars to start animations</h5>
3+
<section class="sample-content padding">
34
<igx-avatar id="audi" initials="BS" size="large" (mouseenter)="mouseenter($event)"
45
(mouseleave)="mouseleave($event)">
56
</igx-avatar>
@@ -10,6 +11,18 @@
1011
(mouseleave)="mouseleave($event)">
1112
</igx-avatar>
1213
</section>
14+
<h5 style="text-align: center;">Move mouse over the avatars to reuse overlay settings</h5>
15+
<section class="sample-content padding">
16+
<igx-avatar id="audi" initials="BS" size="large" (mouseenter)="mouseenterReuse($event)"
17+
(mouseleave)="mouseleaveReuse($event)">
18+
</igx-avatar>
19+
<igx-avatar id="bmw" initials="HK" size="large" (mouseenter)="mouseenterReuse($event)"
20+
(mouseleave)="mouseleaveReuse($event)">
21+
</igx-avatar>
22+
<igx-avatar id="mercedes" initials="DZ" size="large" (mouseenter)="mouseenterReuse($event)"
23+
(mouseleave)="mouseleaveReuse($event)">
24+
</igx-avatar>
25+
</section>
1326
<div igxToggle #audiToggle="toggle" style="max-width: 400px; min-width:250px;">
1427
<igx-card>
1528
<igx-card-header>
@@ -48,4 +61,15 @@ <h5 class="igx-card-header__subtitle">Daimler AG</h5>
4861
</igx-card-content>
4962
</igx-card>
5063
</div>
64+
<div igxToggle #commonToggle="toggle" style="max-width: 400px; min-width:250px;">
65+
<igx-card>
66+
<igx-card-header>
67+
<h3 class="igx-card-header__title">No Name</h3>
68+
<h5 class="igx-card-header__subtitle">No Company</h5>
69+
</igx-card-header>
70+
<igx-card-content>
71+
<p class="igx-card-content__text">This is a common toggle with no specific information.</p>
72+
</igx-card-content>
73+
</igx-card>
74+
</div>
5175
</div>

src/app/overlay/overlay-animation.sample.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ $new-card-theme: card-theme(
88
::ng-deep {
99
@include card($new-card-theme);
1010
}
11+
12+
.padding {
13+
gap: 2rem;
14+
}

src/app/overlay/overlay-animation.sample.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
IgxToggleDirective,
88
HorizontalAlignment,
99
IgxAvatarComponent,
10-
IGX_CARD_DIRECTIVES
10+
IGX_CARD_DIRECTIVES,
11+
ConnectedPositioningStrategy,
12+
VerticalAlignment
1113
} from 'igniteui-angular';
1214

1315
@Component({
@@ -20,6 +22,7 @@ export class OverlayAnimationSampleComponent {
2022
@ViewChild('audiToggle', { static: true }) public audiToggle: IgxToggleDirective;
2123
@ViewChild('bmwToggle', { static: true }) public bmwToggle: IgxToggleDirective;
2224
@ViewChild('mercedesToggle', { static: true }) public mercedesToggle: IgxToggleDirective;
25+
@ViewChild('commonToggle', { static: true }) public commonToggle: IgxToggleDirective;
2326

2427
private _overlaySettings: OverlaySettings = {
2528
positionStrategy: new GlobalPositionStrategy(),
@@ -58,7 +61,6 @@ export class OverlayAnimationSampleComponent {
5861
break;
5962
}
6063
}
61-
6264
public mouseleave(ev) {
6365
switch (ev.target.id) {
6466
case 'audi':
@@ -72,4 +74,49 @@ export class OverlayAnimationSampleComponent {
7274
break;
7375
}
7476
}
77+
public mouseenterReuse(ev) {
78+
const os: OverlaySettings = {
79+
positionStrategy: new ConnectedPositioningStrategy(),
80+
scrollStrategy: new NoOpScrollStrategy(),
81+
modal: false,
82+
closeOnOutsideClick: false,
83+
};
84+
85+
os.positionStrategy.settings.horizontalDirection = HorizontalAlignment.Center;
86+
os.positionStrategy.settings.horizontalStartPoint = HorizontalAlignment.Center;
87+
os.positionStrategy.settings.verticalDirection = VerticalAlignment.Bottom;
88+
os.positionStrategy.settings.verticalStartPoint = VerticalAlignment.Bottom;
89+
os.target = ev.target;
90+
91+
const closeAnimationMetaData: AnimationMetadata[] = [
92+
style({ opacity: `1`, transform: `scale(1)`, transformOrigin: `50% 50%` }),
93+
animate(`6000ms`, style({ opacity: `0`, transform: `scale(0.5)`, transformOrigin: `50% 50%` }))
94+
];
95+
const closeAnimation: AnimationReferenceMetadata = animation(closeAnimationMetaData);
96+
this._overlaySettings.positionStrategy.settings.closeAnimation = closeAnimation;
97+
switch (ev.target.id) {
98+
case 'audi':
99+
this.commonToggle.open(os);
100+
break;
101+
case 'bmw':
102+
this.commonToggle.open(os);
103+
break;
104+
case 'mercedes':
105+
this.commonToggle.open(os);
106+
break;
107+
}
108+
}
109+
public mouseleaveReuse(ev) {
110+
switch (ev.target.id) {
111+
case 'audi':
112+
this.commonToggle.close();
113+
break;
114+
case 'bmw':
115+
this.commonToggle.close();
116+
break;
117+
case 'mercedes':
118+
this.commonToggle.close();
119+
break;
120+
}
121+
}
75122
}

0 commit comments

Comments
 (0)