Skip to content

Commit 063924f

Browse files
authored
Merge branch '19.0.x' into mvenkov/pass-toggle-target-to-toggle-19.0
2 parents a419788 + d4bf5f6 commit 063924f

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({
@@ -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)