Skip to content

Commit 2e992de

Browse files
committed
chore(*): fix dialog issues
1 parent 796cf99 commit 2e992de

File tree

2 files changed

+80
-32
lines changed

2 files changed

+80
-32
lines changed

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

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe('Dialog', () => {
2626
CustomTemplates1DialogComponent,
2727
CustomTemplates2DialogComponent,
2828
DialogSampleComponent,
29-
PositionSettingsDialogComponent
29+
PositionSettingsDialogComponent,
30+
DialogTwoWayDataBindingComponent
3031
],
3132
imports: [BrowserAnimationsModule, NoopAnimationsModule, IgxDialogModule]
3233
}).compileComponents();
@@ -80,17 +81,40 @@ describe('Dialog', () => {
8081
expect(messageDebugElement.nativeElement.textContent.trim()).toEqual(expectedMessage);
8182
});
8283

83-
it('Should open dialog when opened property is set to true', () => {
84+
it('Should open and close dialog when set values to IsOpen', fakeAsync(() => {
8485
const fixture = TestBed.createComponent(AlertComponent);
8586
const dialog = fixture.componentInstance.dialog;
8687
const expectedMessage = 'message';
8788

88-
dialog.opened = true;
89+
dialog.isOpen = true;
90+
tick();
8991
fixture.detectChanges();
92+
expect(dialog.isOpen).toEqual(true);
9093

91-
const messageDebugElement = fixture.debugElement.query(By.css('.igx-dialog__window-content'));
92-
expect(messageDebugElement.nativeElement.textContent.trim()).toEqual(expectedMessage);
93-
});
94+
dialog.close();
95+
tick();
96+
fixture.detectChanges();
97+
expect(dialog.isOpen).toEqual(false);
98+
}));
99+
100+
it('Should open and close dialog with isOpen two way data binding', fakeAsync(() => {
101+
const fixture = TestBed.createComponent(DialogTwoWayDataBindingComponent);
102+
const dialog = fixture.componentInstance.dialog;
103+
fixture.detectChanges();
104+
105+
fixture.componentInstance.myDialog = true;
106+
107+
fixture.detectChanges();
108+
tick();
109+
expect(dialog.isOpen).toEqual(true);
110+
111+
112+
fixture.componentInstance.myDialog = false;
113+
114+
fixture.detectChanges();
115+
tick();
116+
expect(dialog.isOpen).toEqual(false);
117+
}));
94118

95119
it('Should set custom modal message.', () => {
96120
const fixture = TestBed.createComponent(CustomDialogComponent);
@@ -322,6 +346,7 @@ describe('Dialog', () => {
322346
dialog.open();
323347
tick(100);
324348
fix.detectChanges();
349+
tick(100);
325350

326351
// Verify dialog is opened and its default right button is focused
327352
const dialogDOM = fix.debugElement.query(By.css('.igx-dialog'));
@@ -448,6 +473,28 @@ class AlertComponent {
448473
class DialogComponent {
449474
@ViewChild('dialog', { static: true }) public dialog: IgxDialogComponent;
450475
}
476+
477+
@Component({
478+
template: `<div #wrapper>
479+
<igx-dialog #dialog title="dialog" message="message"
480+
[(isOpen)]="myDialog"
481+
leftButtonLabel="left button"
482+
leftButtonType="raised"
483+
leftButtonColor="black"
484+
leftButtonBackgroundColor="darkblue"
485+
leftButtonRipple="pink"
486+
rightButtonLabel="right button"
487+
rightButtonType="raised"
488+
rightButtonColor="orange"
489+
rightButtonBackgroundColor="lightblue"
490+
rightButtonRipple="white">
491+
</igx-dialog>
492+
</div>` })
493+
class DialogTwoWayDataBindingComponent {
494+
@ViewChild('dialog', { static: true }) public dialog: IgxDialogComponent;
495+
public myDialog = false;
496+
}
497+
451498
@Component({
452499
template: `<div #wrapper>
453500
<igx-dialog #dialog

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
5858
private static NEXT_ID = 1;
5959
private static readonly DIALOG_CLASS = 'igx-dialog';
6060

61+
62+
6163
@ViewChild(IgxToggleDirective, { static: true })
6264
public toggleRef: IgxToggleDirective;
6365

@@ -316,6 +318,11 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
316318
@Output()
317319
public onRightButtonSelect = new EventEmitter<IDialogEventArgs>();
318320

321+
/**
322+
* @hidden
323+
*/
324+
@Output() public isOpenChange = new EventEmitter<boolean>();
325+
319326
private _positionSettings: PositionSettings = {
320327
openAnimation: useAnimation(slideInBottom, { params: { fromPosition: 'translateY(100%)' } }),
321328
closeAnimation: useAnimation(slideOutTop, { params: { toPosition: 'translateY(-100%)' } })
@@ -359,44 +366,38 @@ export class IgxDialogComponent implements IToggleView, OnInit, OnDestroy, After
359366
}
360367

361368
/**
362-
* Returns whether the dialog is visible to the end user.
369+
* State of the dialog.
370+
*
363371
* ```typescript
364-
* @ViewChild("MyDialog")
365-
* public dialog: IgxDialogComponent;
366-
* ngAfterViewInit() {
367-
* let dialogOpen = this.dialog.isOpen;
368-
* }
372+
* * // get
373+
* let dialogIsOpen = this.dialog.isOpen;
369374
* ```
370-
*/
371-
372-
get isOpen() {
373-
return !this.toggleRef.collapsed;
374-
}
375-
376-
377-
/**
378-
* An @Input property that allows you to open the dialog declaratively.
379-
* ```typescript
380-
* @ViewChild("MyDialog")
381-
* public dialog: IgxDialogComponent;
382-
* ngAfterViewInit() {
383-
* this.dialog.opened=true;
384-
* }
375+
*
376+
* ```html
377+
* <!--set-->
378+
* <igx-dialog [isOpen]='false'></igx-dialog>
385379
* ```
386380
*
381+
* Two-way data binding.
387382
* ```html
388383
* <!--set-->
389-
* <igx-dialog [opened]='true'></igx-dialog>
384+
* <igx-dialog [(isOpen)]='model.isOpen'></igx-dialog>
390385
* ```
391386
*/
392-
@Input()
393-
public set opened(value: boolean) {
387+
388+
public get isOpen() {
389+
return !this.toggleRef.collapsed;
390+
}
391+
public set isOpen(value: boolean) {
392+
393+
this.isOpenChange.emit(value);
394394
if (value) {
395-
this.open(this._overlayDefaultSettings);
395+
this.open();
396+
} else {
397+
this.close();
396398
}
397399
}
398400

399-
400401
@HostBinding('class.igx-dialog--hidden')
401402
get isCollapsed() {
402403
return this.toggleRef.collapsed;

0 commit comments

Comments
 (0)