Skip to content

Commit ebf1377

Browse files
authored
Merge branch 'master' into tzhelev/fix-5577-8.2.x
2 parents a52dfc3 + 78d94aa commit ebf1377

File tree

7 files changed

+218
-9
lines changed

7 files changed

+218
-9
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ All notable changes for each version of this project will be documented in this
1414
- **Breaking Change** `igxExcelStyleMovingTemplate` directive is renamed to `igxExcelStyleMoving`.
1515
- **Breaking Change** `igxExcelStyleHidingTemplate` directive is renamed to `igxExcelStyleHiding`.
1616
- **Breaking Change** `igxExcelStylePinningTemplate` directive is renamed to `igxExcelStylePinning`.
17+
## 8.1.4
18+
- `IgxDialog` new @Input `positionSettings` is now available. It provides the ability to get/set both position and animation settings of the Dialog component.
1719

1820
## 8.1.3
1921
- `IgxCombo`

projects/igniteui-angular/src/lib/dialog/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,23 @@ or
9393
<div igxDialogActions>BUTTONS</div>
9494
</igx-dialog>
9595
```
96+
97+
You can now set set the position and animation settings used by the dialog by using `positionSettings` @Input
98+
99+
```typescript
100+
import { slideInLeft, slideOutRight } from 'igniteui-angular';
101+
...
102+
@ViewChild('alert', { static: true }) public alert: IgxDialogComponent;
103+
public newPositionSettings: PositionSettings = {
104+
openAnimation: useAnimation(slideInTop, { params: { duration: '2000ms' } }),
105+
closeAnimation: useAnimation(slideOutBottom, { params: { duration: '2000ms'} }),
106+
horizontalDirection: HorizontalAlignment.Left,
107+
verticalDirection: VerticalAlignment.Middle,
108+
horizontalStartPoint: HorizontalAlignment.Left,
109+
verticalStartPoint: VerticalAlignment.Middle,
110+
minSize: { height: 100, width: 100 }
111+
};
112+
113+
this.alert.positionSettings = this.newPositionSettings;
114+
```
115+

projects/igniteui-angular/src/lib/dialog/dialog.component.spec.ts

+108-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import { Component, DebugElement, ElementRef, ViewChild } from '@angular/core';
2-
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
1+
import { Component, ViewChild } from '@angular/core';
2+
import { async, TestBed, fakeAsync, tick } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
66
import { IDialogEventArgs, IgxDialogComponent, IgxDialogModule } from './dialog.component';
77
import { configureTestSuite } from '../test-utils/configure-suite';
8+
import { PositionSettings, slideInTop, slideOutBottom, HorizontalAlignment, VerticalAlignment } from 'igniteui-angular';
9+
import { useAnimation } from '@angular/animations';
810

911
const OVERLAY_MAIN_CLASS = 'igx-overlay';
1012
const OVERLAY_WRAPPER_CLASS = `${OVERLAY_MAIN_CLASS}__wrapper`;
1113
const OVERLAY_MODAL_WRAPPER_CLASS = `${OVERLAY_WRAPPER_CLASS}--modal`;
14+
const CLASS_OVERLAY_CONTENT_MODAL = `${OVERLAY_MAIN_CLASS}__content--modal`;
1215

1316
describe('Dialog', () => {
1417
configureTestSuite();
@@ -21,7 +24,8 @@ describe('Dialog', () => {
2124
NestedDialogsComponent,
2225
CustomTemplates1DialogComponent,
2326
CustomTemplates2DialogComponent,
24-
DialogSampleComponent
27+
DialogSampleComponent,
28+
PositionSettingsDialogComponent
2529
],
2630
imports: [BrowserAnimationsModule, NoopAnimationsModule, IgxDialogModule]
2731
}).compileComponents();
@@ -322,6 +326,78 @@ describe('Dialog', () => {
322326
expect(dialog.isOpen).toEqual(false);
323327
}));
324328

329+
describe('Position settings', () => {
330+
let fix;
331+
let dialog;
332+
let detect;
333+
334+
beforeEach( fakeAsync(() => {
335+
fix = TestBed.createComponent(PositionSettingsDialogComponent);
336+
fix.detectChanges();
337+
dialog = fix.componentInstance.dialog;
338+
detect = () => dialog.cdr.detectChanges();
339+
}));
340+
341+
it('Define different position settings ', (async() => {
342+
const currentElement = fix.componentInstance;
343+
dialog.open();
344+
fix.detectChanges();
345+
await wait(16);
346+
347+
expect(dialog.isOpen).toEqual(true);
348+
const firstContentRect = document.getElementsByClassName(CLASS_OVERLAY_CONTENT_MODAL)[0].getBoundingClientRect();
349+
const middleDialogPosition = document.documentElement.offsetHeight / 2 - firstContentRect.height / 2;
350+
expect(firstContentRect.left).toEqual(0, 'OffsetLeft position check');
351+
expect(firstContentRect.top).toBeGreaterThanOrEqual(middleDialogPosition - 2, 'OffsetTop position check');
352+
expect(firstContentRect.top).toBeLessThanOrEqual(middleDialogPosition + 2, 'OffsetTop position check');
353+
354+
dialog.close();
355+
fix.detectChanges();
356+
await wait(16);
357+
358+
expect(dialog.isOpen).toEqual(false);
359+
dialog.positionSettings = currentElement.newPositionSettings;
360+
fix.detectChanges();
361+
await wait(16);
362+
363+
dialog.open();
364+
fix.detectChanges();
365+
await wait(16);
366+
367+
expect(dialog.isOpen).toEqual(true);
368+
const secondContentRect = document.getElementsByClassName(CLASS_OVERLAY_CONTENT_MODAL)[0].getBoundingClientRect();
369+
const topDialogPosition = document.documentElement.offsetWidth / 2 - secondContentRect.width / 2;
370+
expect(secondContentRect.top).toEqual(0, 'OffsetTop position check');
371+
expect(secondContentRect.left).toBeGreaterThanOrEqual(topDialogPosition - 2, 'OffsetLeft position check');
372+
expect(secondContentRect.left).toBeLessThanOrEqual(topDialogPosition + 2, 'OffsetLeft position check');
373+
374+
dialog.close();
375+
fix.detectChanges();
376+
await wait(16);
377+
378+
expect(dialog.isOpen).toEqual(false);
379+
}));
380+
381+
it('Set animation settings', (async() => {
382+
const currentElement = fix.componentInstance;
383+
384+
// Check initial animation settings
385+
expect(dialog.positionSettings.openAnimation.animation.type).toEqual(8, 'Animation type is set');
386+
expect(dialog.positionSettings.openAnimation.options.params.duration).toEqual('200ms', 'Animation duration is set to 200ms');
387+
388+
expect(dialog.positionSettings.closeAnimation.animation.type).toEqual(8, 'Animation type is set');
389+
expect(dialog.positionSettings.closeAnimation.options.params.duration).toEqual('200ms', 'Animation duration is set to 200ms');
390+
391+
dialog.positionSettings = currentElement.animationSettings;
392+
fix.detectChanges();
393+
await wait(16);
394+
395+
// Check the new animation settings
396+
expect(dialog.positionSettings.openAnimation.options.params.duration).toEqual('800ms', 'Animation duration is set to 800ms');
397+
expect(dialog.positionSettings.closeAnimation.options.params.duration).toEqual('700ms', 'Animation duration is set to 700ms');
398+
}));
399+
});
400+
325401
function dispatchEvent(element: HTMLElement, eventType: string) {
326402
const event = new Event(eventType);
327403
element.dispatchEvent(event);
@@ -436,3 +512,32 @@ class CustomTemplates1DialogComponent {
436512
class CustomTemplates2DialogComponent {
437513
@ViewChild('dialog', { static: true }) public dialog: IgxDialogComponent;
438514
}
515+
516+
517+
@Component({
518+
template: `<igx-dialog #dialog title="Notification" message="Your email has been sent successfully!" leftButtonLabel="OK"
519+
[positionSettings]="positionSettings" >
520+
</igx-dialog>` })
521+
class PositionSettingsDialogComponent {
522+
@ViewChild('dialog', { static: true }) public dialog: IgxDialogComponent;
523+
524+
public positionSettings: PositionSettings = {
525+
horizontalDirection: HorizontalAlignment.Left,
526+
verticalDirection: VerticalAlignment.Middle,
527+
horizontalStartPoint: HorizontalAlignment.Left,
528+
verticalStartPoint: VerticalAlignment.Middle,
529+
openAnimation: useAnimation(slideInTop, { params: { duration: '200ms' } }),
530+
closeAnimation: useAnimation(slideOutBottom, { params: { duration: '200ms'} })
531+
};
532+
533+
public newPositionSettings: PositionSettings = {
534+
horizontalDirection: HorizontalAlignment.Center,
535+
verticalDirection: VerticalAlignment.Top
536+
};
537+
538+
public animationSettings: PositionSettings = {
539+
openAnimation: useAnimation(slideInTop, { params: { duration: '800ms' } }),
540+
closeAnimation: useAnimation(slideOutBottom, { params: { duration: '700ms'} })
541+
};
542+
543+
}

projects/igniteui-angular/src/lib/dialog/dialog.component.ts

+37-2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,41 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
216216
this._closeOnOutsideSelect = val;
217217
}
218218

219+
/**
220+
* Get the position and animation settings used by the dialog.
221+
* ```typescript
222+
* @ViewChild('alert', { static: true }) public alert: IgxDialogComponent;
223+
* let currentPosition: PositionSettings = this.alert.positionSettings
224+
* ```
225+
*/
226+
@Input()
227+
public get positionSettings(): PositionSettings {
228+
return this._positionSettings;
229+
}
230+
231+
/**
232+
* Set the position and animation settings used by the dialog.
233+
* ```typescript
234+
* import { slideInLeft, slideOutRight } from 'igniteui-angular';
235+
* ...
236+
* @ViewChild('alert', { static: true }) public alert: IgxDialogComponent;
237+
* public newPositionSettings: PositionSettings = {
238+
* openAnimation: useAnimation(slideInTop, { params: { duration: '2000ms' } }),
239+
* closeAnimation: useAnimation(slideOutBottom, { params: { duration: '2000ms'} }),
240+
* horizontalDirection: HorizontalAlignment.Left,
241+
* verticalDirection: VerticalAlignment.Middle,
242+
* horizontalStartPoint: HorizontalAlignment.Left,
243+
* verticalStartPoint: VerticalAlignment.Middle,
244+
* minSize: { height: 100, width: 100 }
245+
* };
246+
* this.alert.positionSettings = this.newPositionSettings;
247+
* ```
248+
*/
249+
public set positionSettings(settings: PositionSettings) {
250+
this._positionSettings = settings;
251+
this._overlayDefaultSettings.positionStrategy = new GlobalPositionStrategy(this._positionSettings);
252+
}
253+
219254
/**
220255
* An event that is emitted when the dialog is opened.
221256
*```html
@@ -258,7 +293,7 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
258293
@Output()
259294
public onRightButtonSelect = new EventEmitter<IDialogEventArgs>();
260295

261-
private _animaitonSettings: PositionSettings = {
296+
private _positionSettings: PositionSettings = {
262297
openAnimation: useAnimation(slideInBottom, { params: { fromPosition: 'translateY(100%)' } }),
263298
closeAnimation: useAnimation(slideOutTop, { params: { toPosition: 'translateY(-100%)' } })
264299
};
@@ -365,7 +400,7 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
365400
this._titleId = IgxDialogComponent.NEXT_ID++ + '_title';
366401

367402
this._overlayDefaultSettings = {
368-
positionStrategy: new GlobalPositionStrategy(this._animaitonSettings),
403+
positionStrategy: new GlobalPositionStrategy(this._positionSettings),
369404
scrollStrategy: new NoOpScrollStrategy(),
370405
modal: this.isModal,
371406
closeOnOutsideClick: this.closeOnOutsideSelect

src/app/dialog/dialog.sample.css

+5
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@
1313
igx-input-group+igx-input-group {
1414
margin-top: 24px;
1515
}
16+
17+
.alertSection button {
18+
width: 140px;
19+
margin-right: 5px;
20+
}

src/app/dialog/dialog.sample.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
<h4 class="sample-title">Alert</h4>
66
<p class="sample-description">Detailed description to be added.</p>
77
<br>
8-
<button igxButton="raised" igxRipple (click)="alert.open()">Trigger Alert</button>
9-
<igx-dialog #alert title="Notification" message="Your email has been sent successfully!" leftButtonLabel="OK" (onLeftButtonSelect)="alert.close()">
8+
<div class="alertSection">
9+
<button igxButton="raised" igxRipple (click)="alert.open()">Open Alert</button>
10+
<button igxButton="flat" (click)="togglePosition()">Toggle position</button>
11+
</div>
12+
13+
<igx-dialog #alert title="Notification" message="Your email has been sent successfully!" leftButtonLabel="OK" (onLeftButtonSelect)="alert.close()"
14+
[positionSettings]="positionSettings" >
1015
</igx-dialog>
1116
</article>
1217

src/app/dialog/dialog.sample.ts

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
1-
import { Component } from '@angular/core';
1+
import { Component, ViewChild, OnInit } from '@angular/core';
2+
import { IgxDialogComponent, slideOutBottom, slideInTop,
3+
PositionSettings, HorizontalAlignment, VerticalAlignment } from 'igniteui-angular';
4+
import { useAnimation } from '@angular/animations';
25

36
@Component({
47
selector: 'app-dialog-sample',
58
styleUrls: ['dialog.sample.css'],
69
templateUrl: 'dialog.sample.html'
710
})
8-
export class DialogSampleComponent {
11+
export class DialogSampleComponent implements OnInit {
12+
13+
@ViewChild('alert', { static: true }) public alert: IgxDialogComponent;
14+
15+
public positionSettings: PositionSettings = {
16+
openAnimation: useAnimation(slideInTop, { params: { duration: '2000ms' } }),
17+
closeAnimation: useAnimation(slideOutBottom, { params: { duration: '2000ms'} }),
18+
horizontalDirection: HorizontalAlignment.Left,
19+
verticalDirection: VerticalAlignment.Middle,
20+
horizontalStartPoint: HorizontalAlignment.Left,
21+
verticalStartPoint: VerticalAlignment.Middle,
22+
minSize: { height: 100, width: 100 }
23+
};
24+
25+
public newPositionSettings: PositionSettings = {
26+
horizontalDirection: HorizontalAlignment.Center,
27+
verticalDirection: VerticalAlignment.Middle,
28+
};
29+
30+
public newAnimationSettings: PositionSettings = {
31+
openAnimation: useAnimation(slideInTop),
32+
closeAnimation: useAnimation(slideOutBottom)
33+
};
34+
35+
public ngOnInit() {
36+
// Set position settings on ngOnInit
37+
// this.alert.positionSettings = this.newAnimationSettings;
38+
39+
console.log(this.alert.positionSettings);
40+
}
41+
42+
togglePosition() {
43+
this.alert.positionSettings = this.alert.positionSettings === this.positionSettings ?
44+
this.newPositionSettings : this.positionSettings;
45+
}
946

1047
onDialogOKSelected(args) {
1148
// args.event - event

0 commit comments

Comments
 (0)