From 629a276baef537fd324830be69465d01faec18ef Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Mon, 31 Oct 2016 17:33:38 -0700 Subject: [PATCH] fix(sidenav): resolve the promise when sidenav is initialized opened. Fixes #1382. --- src/demo-app/sidenav/sidenav-demo.html | 14 +++++++++++++- src/lib/sidenav/sidenav.spec.ts | 2 ++ src/lib/sidenav/sidenav.ts | 11 ++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/demo-app/sidenav/sidenav-demo.html b/src/demo-app/sidenav/sidenav-demo.html index 3835438303de..83d58e7a47a4 100644 --- a/src/demo-app/sidenav/sidenav-demo.html +++ b/src/demo-app/sidenav/sidenav-demo.html @@ -1,3 +1,5 @@ +

Basic Use Case

+ Start Side Drawer @@ -34,4 +36,14 @@

My Content

-

Content after Sidenav

+

Sidenav Already Opened

+ + + + Drawer + + +
+ +
+
diff --git a/src/lib/sidenav/sidenav.spec.ts b/src/lib/sidenav/sidenav.spec.ts index 712fe2129c89..8d2b4099ed60 100644 --- a/src/lib/sidenav/sidenav.spec.ts +++ b/src/lib/sidenav/sidenav.spec.ts @@ -224,6 +224,8 @@ describe('MdSidenav', () => { expect(sidenavEl.classList).not.toContain('md-sidenav-closed'); expect(sidenavEl.classList).toContain('md-sidenav-opened'); + + expect((sidenavEl as any)._openPromise).toBeNull(); }); it('should remove align attr from DOM', () => { diff --git a/src/lib/sidenav/sidenav.ts b/src/lib/sidenav/sidenav.ts index a95398efbd9e..6674c1bf6471 100644 --- a/src/lib/sidenav/sidenav.ts +++ b/src/lib/sidenav/sidenav.ts @@ -45,7 +45,7 @@ export class MdDuplicatedSidenavError extends MdError { changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, }) -export class MdSidenav { +export class MdSidenav implements AfterContentInit { /** Alignment of the sidenav (direction neutral); whether 'start' or 'end'. */ @Input() align: 'start' | 'end' = 'start'; @@ -73,6 +73,15 @@ export class MdSidenav { */ constructor(private _elementRef: ElementRef) {} + ngAfterContentInit() { + // This can happen when the sidenav is set to opened in the template and the transition + // isn't ended. + if (this._openPromise) { + this._openPromiseResolve(); + this._openPromise = null; + } + } + /** * Whether the sidenav is opened. We overload this because we trigger an event when it * starts or end.