mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(sidenav): resolve the promise when sidenav is initialized opened. (#1666)
Fixes #1382.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user