Skip to content

Commit df4ece4

Browse files
authored
Merge branch '18.2.x' into mvenkov/pass-toggle-target-to-toggle-18.2
2 parents 134a85c + dc22baa commit df4ece4

File tree

5 files changed

+115
-6
lines changed

5 files changed

+115
-6
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ export class IgxOverlayService implements OnDestroy {
411411
return;
412412
}
413413
if (settings) {
414-
// TODO: update attach
414+
settings.positionStrategy ??= info.settings.positionStrategy;
415+
settings.scrollStrategy ??= info.settings.scrollStrategy;
416+
info.settings = { ...info.settings, ...settings };
415417
}
416418
this.updateSize(info);
417419
info.settings.positionStrategy.position(
@@ -592,7 +594,7 @@ export class IgxOverlayService implements OnDestroy {
592594
const createSettings = viewContainerRefOrSettings as OverlayCreateSettings | undefined;
593595
let elementInjector: Injector;
594596
if (createSettings) {
595-
({ injector: elementInjector, ...overlaySettings} = createSettings);
597+
({ injector: elementInjector, ...overlaySettings } = createSettings);
596598
}
597599
dynamicComponent = createComponent(component, { environmentInjector, elementInjector });
598600
this._appRef.attachView(dynamicComponent.hostView);
@@ -610,7 +612,7 @@ export class IgxOverlayService implements OnDestroy {
610612
info.elementRef = { nativeElement: element };
611613
info.componentRef = dynamicComponent;
612614
}
613-
info.settings = Object.assign({}, this._defaultSettings, overlaySettings);
615+
info.settings = Object.assign({}, this._defaultSettings, overlaySettings);
614616
return info;
615617
}
616618

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({
@@ -22,6 +24,7 @@ export class OverlayAnimationSampleComponent {
2224
@ViewChild('audiToggle', { static: true }) public audiToggle: IgxToggleDirective;
2325
@ViewChild('bmwToggle', { static: true }) public bmwToggle: IgxToggleDirective;
2426
@ViewChild('mercedesToggle', { static: true }) public mercedesToggle: IgxToggleDirective;
27+
@ViewChild('commonToggle', { static: true }) public commonToggle: IgxToggleDirective;
2528

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

0 commit comments

Comments
 (0)