Skip to content

Commit 3f2f7e0

Browse files
authored
Merge pull request #4252 from IgniteUI/mvenkov/toggle-does-not-emit-closed-#4222
Toggle does not fire onClosed after first call to close
2 parents 910f67c + c39ea98 commit 3f2f7e0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

projects/igniteui-angular/src/lib/directives/toggle/toggle.directive.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,36 @@ describe('IgxToggle', () => {
420420
expect(toggle.onClosed.emit).toHaveBeenCalledTimes(1);
421421
}));
422422

423+
it('fix for #4222 - Should emit closed when closed second time', fakeAsync(() => {
424+
const fixture = TestBed.createComponent(IgxToggleTestComponent);
425+
fixture.detectChanges();
426+
427+
const toggle = fixture.componentInstance.toggle;
428+
toggle.onClosed.subscribe(() => {
429+
toggle.open();
430+
});
431+
432+
spyOn(toggle.onOpening, 'emit');
433+
spyOn(toggle.onClosed, 'emit').and.callThrough();
434+
435+
toggle.open();
436+
tick();
437+
fixture.detectChanges();
438+
expect(toggle.onOpening.emit).toHaveBeenCalledTimes(1);
439+
440+
toggle.close();
441+
tick();
442+
fixture.detectChanges();
443+
expect(toggle.onClosed.emit).toHaveBeenCalledTimes(1);
444+
expect(toggle.onOpening.emit).toHaveBeenCalledTimes(2);
445+
446+
toggle.close();
447+
tick();
448+
fixture.detectChanges();
449+
expect(toggle.onClosed.emit).toHaveBeenCalledTimes(2);
450+
expect(toggle.onOpening.emit).toHaveBeenCalledTimes(3);
451+
}));
452+
423453
describe('overlay settings', () => {
424454
configureTestSuite();
425455
it('should pass correct defaults from IgxToggleActionDirective and respect outsideClickClose', fakeAsync(() => {

projects/igniteui-angular/src/lib/directives/toggle/toggle.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {
305305
this._collapsed = true;
306306
this.cdr.detectChanges();
307307
delete this._overlayId;
308-
this.onClosed.emit();
309308
this.unsubscribe();
309+
this.onClosed.emit();
310310
}
311311

312312
private unsubscribe() {

0 commit comments

Comments
 (0)