Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/lib/sidenav/drawer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: `
Expand Down
4 changes: 2 additions & 2 deletions src/lib/sidenav/drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down