Skip to content

Commit

Permalink
fix(sidenav): fix animation issue for initially open sidenav (#3045)
Browse files Browse the repository at this point in the history
* fix animation issue for initially open sidenav

* rename

* add import for rxjs first operator
  • Loading branch information
mmalerba authored and andrewseguin committed Feb 15, 2017
1 parent a08dc55 commit 37e4bad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
24 changes: 13 additions & 11 deletions src/lib/sidenav/sidenav-transitions.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Separate transitions to be able to disable them in unit tests by omitting this file.
@import '../core/style/variables';

.mat-sidenav {
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function;
}
.mat-sidenav-transition {
.mat-sidenav {
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function;
}

.mat-sidenav-content {
transition: {
duration: $swift-ease-out-duration;
timing-function: $swift-ease-out-timing-function;
property: transform, margin-left, margin-right;
.mat-sidenav-content {
transition: {
duration: $swift-ease-out-duration;
timing-function: $swift-ease-out-timing-function;
property: transform, margin-left, margin-right;
}
}
}

.mat-sidenav-backdrop.mat-sidenav-shown {
transition: background-color $swift-ease-out-duration $swift-ease-out-timing-function;
.mat-sidenav-backdrop.mat-sidenav-shown {
transition: background-color $swift-ease-out-duration $swift-ease-out-timing-function;
}
}
13 changes: 11 additions & 2 deletions src/lib/sidenav/sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import {
EventEmitter,
Renderer,
ViewEncapsulation,
ViewChild
ViewChild,
NgZone
} from '@angular/core';
import {CommonModule} from '@angular/common';
import {Dir, MdError, coerceBooleanProperty, CompatibilityModule} from '../core';
import {A11yModule} from '../core/a11y/index';
import {FocusTrap} from '../core/a11y/focus-trap';
import {ESCAPE} from '../core/keyboard/keycodes';
import {OverlayModule} from '../core/overlay/overlay-directives';
import 'rxjs/add/operator/first';


/** Exception thrown when two MdSidenav are matching the same side. */
Expand Down Expand Up @@ -321,6 +323,7 @@ export class MdSidenav implements AfterContentInit {
],
host: {
'[class.mat-sidenav-container]': 'true',
'[class.mat-sidenav-transition]': '_enableTransitions',
},
encapsulation: ViewEncapsulation.None,
})
Expand Down Expand Up @@ -349,8 +352,11 @@ export class MdSidenavContainer implements AfterContentInit {
private _left: MdSidenav;
private _right: MdSidenav;

/** Whether to enable open/close trantions. */
_enableTransitions = false;

constructor(@Optional() private _dir: Dir, private _element: ElementRef,
private _renderer: Renderer) {
private _renderer: Renderer, private _ngZone: NgZone) {
// If a `Dir` directive exists up the tree, listen direction changes and update the left/right
// properties to point to the proper start/end.
if (_dir != null) {
Expand All @@ -366,6 +372,9 @@ export class MdSidenavContainer implements AfterContentInit {
this._watchSidenavAlign(sidenav);
});
this._validateDrawers();

// Give the view a chance to render the initial state, then enable transitions.
this._ngZone.onMicrotaskEmpty.first().subscribe(() => this._enableTransitions = true);
}

/**
Expand Down

0 comments on commit 37e4bad

Please sign in to comment.