fix(sidenav): resolve the promise when sidenav is initialized opened. (#1666)

Fixes #1382.
This commit is contained in:
Hans
2016-11-03 16:05:16 -07:00
committed by Jeremy Elbourn
parent 83f6efc2c8
commit a0d85d8793
3 changed files with 26 additions and 2 deletions
+13 -1
View File
@@ -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
@@ -34,4 +36,14 @@
</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
View File
@@ -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', () => {
+10 -1
View File
@@ -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.