Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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