Skip to content

Commit 37e4bad

Browse files
mmalerbaandrewseguin
authored andcommitted
fix(sidenav): fix animation issue for initially open sidenav (#3045)
* fix animation issue for initially open sidenav * rename * add import for rxjs first operator
1 parent a08dc55 commit 37e4bad

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ import {
1313
EventEmitter,
1414
Renderer,
1515
ViewEncapsulation,
16-
ViewChild
16+
ViewChild,
17+
NgZone
1718
} from '@angular/core';
1819
import {CommonModule} from '@angular/common';
1920
import {Dir, MdError, coerceBooleanProperty, CompatibilityModule} from '../core';
2021
import {A11yModule} from '../core/a11y/index';
2122
import {FocusTrap} from '../core/a11y/focus-trap';
2223
import {ESCAPE} from '../core/keyboard/keycodes';
2324
import {OverlayModule} from '../core/overlay/overlay-directives';
25+
import 'rxjs/add/operator/first';
2426

2527

2628
/** Exception thrown when two MdSidenav are matching the same side. */
@@ -321,6 +323,7 @@ export class MdSidenav implements AfterContentInit {
321323
],
322324
host: {
323325
'[class.mat-sidenav-container]': 'true',
326+
'[class.mat-sidenav-transition]': '_enableTransitions',
324327
},
325328
encapsulation: ViewEncapsulation.None,
326329
})
@@ -349,8 +352,11 @@ export class MdSidenavContainer implements AfterContentInit {
349352
private _left: MdSidenav;
350353
private _right: MdSidenav;
351354

355+
/** Whether to enable open/close trantions. */
356+
_enableTransitions = false;
357+
352358
constructor(@Optional() private _dir: Dir, private _element: ElementRef,
353-
private _renderer: Renderer) {
359+
private _renderer: Renderer, private _ngZone: NgZone) {
354360
// If a `Dir` directive exists up the tree, listen direction changes and update the left/right
355361
// properties to point to the proper start/end.
356362
if (_dir != null) {
@@ -366,6 +372,9 @@ export class MdSidenavContainer implements AfterContentInit {
366372
this._watchSidenavAlign(sidenav);
367373
});
368374
this._validateDrawers();
375+
376+
// Give the view a chance to render the initial state, then enable transitions.
377+
this._ngZone.onMicrotaskEmpty.first().subscribe(() => this._enableTransitions = true);
369378
}
370379

371380
/**

0 commit comments

Comments
 (0)