Skip to content

Commit ba5653d

Browse files
crisbetoandrewseguin
authored andcommitted
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.
1 parent c7ab828 commit ba5653d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/lib/sidenav/drawer.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ describe('MatDrawer', () => {
126126
expect(testComponent.closeCount).toBe(1, 'Expected one close event.');
127127
}));
128128

129+
it('should fire the open event when open on init', fakeAsync(() => {
130+
let fixture = TestBed.createComponent(DrawerSetToOpenedTrue);
131+
132+
fixture.detectChanges();
133+
tick();
134+
135+
expect(fixture.componentInstance.openCallback).toHaveBeenCalledTimes(1);
136+
}));
137+
129138
it('should not close by pressing escape when disableClose is set', fakeAsync(() => {
130139
let fixture = TestBed.createComponent(BasicTestApp);
131140
let testComponent = fixture.debugElement.componentInstance;
@@ -430,12 +439,14 @@ class DrawerSetToOpenedFalse { }
430439
@Component({
431440
template: `
432441
<mat-drawer-container>
433-
<mat-drawer #drawer mode="side" opened="true">
442+
<mat-drawer #drawer mode="side" opened="true" (open)="openCallback()">
434443
Closed Drawer.
435444
</mat-drawer>
436445
</mat-drawer-container>`,
437446
})
438-
class DrawerSetToOpenedTrue { }
447+
class DrawerSetToOpenedTrue {
448+
openCallback = jasmine.createSpy('open callback');
449+
}
439450

440451
@Component({
441452
template: `

src/lib/sidenav/drawer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
329329
_onAnimationEnd(event: AnimationEvent) {
330330
const {fromState, toState} = event;
331331

332-
if (toState === 'open' && fromState === 'void') {
332+
if (toState.indexOf('open') === 0 && fromState === 'void') {
333333
this.onOpen.emit(new MatDrawerToggleResult('open', true));
334-
} else if (toState === 'void' && fromState === 'open') {
334+
} else if (toState === 'void' && fromState.indexOf('open') === 0) {
335335
this.onClose.emit(new MatDrawerToggleResult('close', true));
336336
}
337337

0 commit comments

Comments
 (0)