Skip to content

Commit bf9e542

Browse files
authored
Merge pull request #8357 from IgniteUI/dTsvetkov/fix-issue-8320-master
fix(dialog): exposed opened property-10.2.x #8320
2 parents ba7e2cc + 16b7132 commit bf9e542

File tree

3 files changed

+96
-9
lines changed

3 files changed

+96
-9
lines changed

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

Lines changed: 60 additions & 1 deletion
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,6 +81,41 @@ describe('Dialog', () => {
8081
expect(messageDebugElement.nativeElement.textContent.trim()).toEqual(expectedMessage);
8182
});
8283

84+
it('Should open and close dialog when set values to IsOpen', fakeAsync(() => {
85+
const fixture = TestBed.createComponent(AlertComponent);
86+
const dialog = fixture.componentInstance.dialog;
87+
const expectedMessage = 'message';
88+
89+
dialog.isOpen = true;
90+
tick();
91+
fixture.detectChanges();
92+
expect(dialog.isOpen).toEqual(true);
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+
}));
118+
83119
it('Should set custom modal message.', () => {
84120
const fixture = TestBed.createComponent(CustomDialogComponent);
85121
const dialog = fixture.componentInstance.dialog;
@@ -310,6 +346,7 @@ describe('Dialog', () => {
310346
dialog.open();
311347
tick(100);
312348
fix.detectChanges();
349+
tick(100);
313350

314351
// Verify dialog is opened and its default right button is focused
315352
const dialogDOM = fix.debugElement.query(By.css('.igx-dialog'));
@@ -436,6 +473,28 @@ class AlertComponent {
436473
class DialogComponent {
437474
@ViewChild('dialog', { static: true }) public dialog: IgxDialogComponent;
438475
}
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+
439498
@Component({
440499
template: `<div #wrapper>
441500
<igx-dialog #dialog

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

Lines changed: 32 additions & 7 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,19 +366,37 @@ 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;
374+
* ```
375+
*
376+
* ```html
377+
* <!--set-->
378+
* <igx-dialog [isOpen]='false'></igx-dialog>
379+
* ```
380+
*
381+
* Two-way data binding.
382+
* ```html
383+
* <!--set-->
384+
* <igx-dialog [(isOpen)]='model.isOpen'></igx-dialog>
369385
* ```
370386
*/
371387
@Input()
372-
get isOpen() {
388+
public get isOpen() {
373389
return !this.toggleRef.collapsed;
374390
}
391+
public set isOpen(value: boolean) {
392+
393+
this.isOpenChange.emit(value);
394+
if (value) {
395+
this.open();
396+
} else {
397+
this.close();
398+
}
399+
}
375400

376401
@HostBinding('class.igx-dialog--hidden')
377402
get isCollapsed() {

projects/igniteui-angular/src/lib/grids/grid/grid-cell-selection.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,8 @@ describe('IgxGrid - Cell selection #grid', () => {
12951295
UIInteractions.triggerKeyDownEvtUponElem('arrowright', firstCell.nativeElement, true, false, true, true);
12961296
await wait(100);
12971297
fix.detectChanges();
1298+
await wait(50);
1299+
fix.detectChanges();
12981300

12991301
expect(selectionChangeSpy).toHaveBeenCalledTimes(1);
13001302
GridSelectionFunctions.verifySelectedRange(grid, 4, 4, 2, 5);
@@ -1332,14 +1334,15 @@ describe('IgxGrid - Cell selection #grid', () => {
13321334
const selectionChangeSpy = spyOn<any>(grid.onRangeSelection, 'emit').and.callThrough();
13331335

13341336
UIInteractions.simulateClickAndSelectEvent(firstCell);
1337+
await wait();
13351338
fix.detectChanges();
13361339

13371340
expect(selectionChangeSpy).toHaveBeenCalledTimes(0);
13381341
GridSelectionFunctions.verifyCellSelected(firstCell);
13391342
expect(grid.selectedCells.length).toBe(1);
13401343

13411344
UIInteractions.triggerKeyDownEvtUponElem('end', firstCell.nativeElement, true, false, true, true);
1342-
await wait(100);
1345+
await wait(200);
13431346
fix.detectChanges();
13441347

13451348
expect(selectionChangeSpy).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)