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 authored and jelbourn committed Nov 3, 2016
1 parent 83f6efc commit a0d85d8
Show file tree
Hide file tree
Showing 3 changed files with 26 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>
3 changes: 3 additions & 0 deletions src/lib/sidenav/sidenav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,12 @@ describe('MdSidenav', () => {
endSidenavTransition(fixture);

let sidenavEl = fixture.debugElement.query(By.css('md-sidenav')).nativeElement;
let testComponent = fixture.debugElement.query(By.css('md-sidenav')).componentInstance;

expect(sidenavEl.classList).not.toContain('md-sidenav-closed');
expect(sidenavEl.classList).toContain('md-sidenav-opened');

expect((testComponent 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 a0d85d8

Please sign in to comment.