Skip to content

Commit a0d85d8

Browse files
hansljelbourn
authored andcommitted
fix(sidenav): resolve the promise when sidenav is initialized opened. (#1666)
Fixes #1382.
1 parent 83f6efc commit a0d85d8

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/demo-app/sidenav/sidenav-demo.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<h2>Basic Use Case</h2>
2+
13
<md-sidenav-layout class="demo-sidenav-layout">
24
<md-sidenav #start (open)="myinput.focus()" mode="side">
35
Start Side Drawer
@@ -34,4 +36,14 @@ <h1>My Content</h1>
3436
</div>
3537
</md-sidenav-layout>
3638

37-
<h2>Content after Sidenav</h2>
39+
<h2>Sidenav Already Opened</h2>
40+
41+
<md-sidenav-layout class="demo-sidenav-layout">
42+
<md-sidenav #start2 opened mode="side">
43+
Drawer
44+
</md-sidenav>
45+
46+
<div class="demo-sidenav-content">
47+
<button md-button (click)="start2.toggle()">Toggle Start Side Drawer</button>
48+
</div>
49+
</md-sidenav-layout>

src/lib/sidenav/sidenav.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ describe('MdSidenav', () => {
221221
endSidenavTransition(fixture);
222222

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

225226
expect(sidenavEl.classList).not.toContain('md-sidenav-closed');
226227
expect(sidenavEl.classList).toContain('md-sidenav-opened');
228+
229+
expect((testComponent as any)._openPromise).toBeNull();
227230
});
228231

229232
it('should remove align attr from DOM', () => {

src/lib/sidenav/sidenav.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class MdDuplicatedSidenavError extends MdError {
4545
changeDetection: ChangeDetectionStrategy.OnPush,
4646
encapsulation: ViewEncapsulation.None,
4747
})
48-
export class MdSidenav {
48+
export class MdSidenav implements AfterContentInit {
4949
/** Alignment of the sidenav (direction neutral); whether 'start' or 'end'. */
5050
@Input() align: 'start' | 'end' = 'start';
5151

@@ -73,6 +73,15 @@ export class MdSidenav {
7373
*/
7474
constructor(private _elementRef: ElementRef) {}
7575

76+
ngAfterContentInit() {
77+
// This can happen when the sidenav is set to opened in the template and the transition
78+
// isn't ended.
79+
if (this._openPromise) {
80+
this._openPromiseResolve();
81+
this._openPromise = null;
82+
}
83+
}
84+
7685
/**
7786
* Whether the sidenav is opened. We overload this because we trigger an event when it
7887
* starts or end.

0 commit comments

Comments
 (0)