Skip to content

Commit

Permalink
fix(sidenav): resolve the promise when sidenav is initialized opened.
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Nov 1, 2016
1 parent ea6c817 commit 629a276
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/demo-app/sidenav/sidenav-demo.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>Basic Use Case</h2>

<md-sidenav-layout class="demo-sidenav-layout">
<md-sidenav #start (open)="myinput.focus()" mode="side">
Start Side Drawer
Expand Down Expand Up @@ -34,4 +36,14 @@ <h1>My Content</h1>
</div>
</md-sidenav-layout>

<h2>Content after Sidenav</h2>
<h2>Sidenav Already Opened</h2>

<md-sidenav-layout class="demo-sidenav-layout">
<md-sidenav #start2 opened mode="side">
Drawer
</md-sidenav>

<div class="demo-sidenav-content">
<button md-button (click)="start2.toggle()">Toggle Start Side Drawer</button>
</div>
</md-sidenav-layout>
2 changes: 2 additions & 0 deletions src/lib/sidenav/sidenav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
11 changes: 10 additions & 1 deletion src/lib/sidenav/sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 629a276

Please sign in to comment.