Skip to content

Commit 1ff3ad9

Browse files
committed
fix animation issue for initially open sidenav
1 parent 516720f commit 1ff3ad9

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// Separate transitions to be able to disable them in unit tests by omitting this file.
22
@import '../core/style/variables';
33

4-
.mat-sidenav {
5-
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function;
6-
}
4+
.mat-sidenav-transition {
5+
.mat-sidenav {
6+
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function;
7+
}
78

8-
.mat-sidenav-content {
9-
transition: {
10-
duration: $swift-ease-out-duration;
11-
timing-function: $swift-ease-out-timing-function;
12-
property: transform, margin-left, margin-right;
9+
.mat-sidenav-content {
10+
transition: {
11+
duration: $swift-ease-out-duration;
12+
timing-function: $swift-ease-out-timing-function;
13+
property: transform, margin-left, margin-right;
14+
}
1315
}
14-
}
1516

16-
.mat-sidenav-backdrop.mat-sidenav-shown {
17-
transition: background-color $swift-ease-out-duration $swift-ease-out-timing-function;
17+
.mat-sidenav-backdrop.mat-sidenav-shown {
18+
transition: background-color $swift-ease-out-duration $swift-ease-out-timing-function;
19+
}
1820
}

src/lib/sidenav/sidenav.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
EventEmitter,
1414
Renderer,
1515
ViewEncapsulation,
16-
ViewChild
16+
ViewChild, NgZone
1717
} from '@angular/core';
1818
import {CommonModule} from '@angular/common';
1919
import {Dir, MdError, coerceBooleanProperty, CompatibilityModule} from '../core';
@@ -321,6 +321,7 @@ export class MdSidenav implements AfterContentInit {
321321
],
322322
host: {
323323
'[class.mat-sidenav-container]': 'true',
324+
'[class.mat-sidenav-transition]': '_initialized',
324325
},
325326
encapsulation: ViewEncapsulation.None,
326327
})
@@ -349,8 +350,10 @@ export class MdSidenavContainer implements AfterContentInit {
349350
private _left: MdSidenav;
350351
private _right: MdSidenav;
351352

353+
_initialized = false;
354+
352355
constructor(@Optional() private _dir: Dir, private _element: ElementRef,
353-
private _renderer: Renderer) {
356+
private _renderer: Renderer, private _ngZone: NgZone) {
354357
// If a `Dir` directive exists up the tree, listen direction changes and update the left/right
355358
// properties to point to the proper start/end.
356359
if (_dir != null) {
@@ -366,6 +369,9 @@ export class MdSidenavContainer implements AfterContentInit {
366369
this._watchSidenavAlign(sidenav);
367370
});
368371
this._validateDrawers();
372+
373+
// Give the view a chance to render the initial state, then enable transitions.
374+
this._ngZone.onMicrotaskEmpty.first().subscribe(() => this._initialized = true);
369375
}
370376

371377
/**

0 commit comments

Comments
 (0)