fix(drawer): open event not firing on init (#7214)

Fixes a regression that caused the drawer not to fire its `open` event if it is open on init.

Fixes #7208.
This commit is contained in:
Kristiyan Kostadinov
2017-09-29 22:06:57 +02:00
committed by Andrew Seguin
parent c7ab828b0a
commit ba5653db20
2 changed files with 15 additions and 4 deletions
+13 -2
View File
@@ -126,6 +126,15 @@ describe('MatDrawer', () => {
expect(testComponent.closeCount).toBe(1, 'Expected one close event.');
}));
it('should fire the open event when open on init', fakeAsync(() => {
let fixture = TestBed.createComponent(DrawerSetToOpenedTrue);
fixture.detectChanges();
tick();
expect(fixture.componentInstance.openCallback).toHaveBeenCalledTimes(1);
}));
it('should not close by pressing escape when disableClose is set', fakeAsync(() => {
let fixture = TestBed.createComponent(BasicTestApp);
let testComponent = fixture.debugElement.componentInstance;
@@ -430,12 +439,14 @@ class DrawerSetToOpenedFalse { }
@Component({
template: `
<mat-drawer-container>
<mat-drawer #drawer mode="side" opened="true">
<mat-drawer #drawer mode="side" opened="true" (open)="openCallback()">
Closed Drawer.
</mat-drawer>
</mat-drawer-container>`,
})
class DrawerSetToOpenedTrue { }
class DrawerSetToOpenedTrue {
openCallback = jasmine.createSpy('open callback');
}
@Component({
template: `
+2 -2
View File
@@ -329,9 +329,9 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
_onAnimationEnd(event: AnimationEvent) {
const {fromState, toState} = event;
if (toState === 'open' && fromState === 'void') {
if (toState.indexOf('open') === 0 && fromState === 'void') {
this.onOpen.emit(new MatDrawerToggleResult('open', true));
} else if (toState === 'void' && fromState === 'open') {
} else if (toState === 'void' && fromState.indexOf('open') === 0) {
this.onClose.emit(new MatDrawerToggleResult('close', true));
}