Skip to content

Commit aad41ca

Browse files
committed
fix: avoid initial animation
1 parent f86b7b2 commit aad41ca

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/lib/sidenav/sidenav.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,20 @@ export class MdSidenavToggleResult {
6060
encapsulation: ViewEncapsulation.None,
6161
animations: [
6262
trigger('transform', [
63-
state('open', style({
63+
state('open, initial-open', style({
6464
transform: 'translate3d(0, 0, 0)',
6565
visibility: 'visible',
6666
})),
6767
state('void', style({
6868
visibility: 'hidden',
6969
})),
70-
transition('* => *', animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)'))
70+
transition('void => initial-open', animate('0ms')),
71+
transition('void <=> open', animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)'))
7172
])
7273
],
7374
host: {
7475
'class': 'mat-sidenav',
75-
'[@transform]': 'opened ? "open" : "void"',
76+
'[@transform]': '_getAnimationState()',
7677
'(@transform.start)': '_isAnimating = true',
7778
'(@transform.done)': '_onAnimationEnd($event)',
7879
'(keydown)': 'handleKeydown($event)',
@@ -89,6 +90,9 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
8990
private _focusTrap: FocusTrap;
9091
private _elementFocusedBeforeSidenavWasOpened: HTMLElement | null = null;
9192

93+
/** Whether the sidenav is initialized. Used for disabling the initial animation. */
94+
private _isInitialized = false;
95+
9296
/** Alignment of the sidenav (direction neutral); whether 'start' or 'end'. */
9397
private _align: 'start' | 'end' = 'start';
9498

@@ -176,6 +180,7 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
176180
ngAfterContentInit() {
177181
this._focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement);
178182
this._focusTrap.enabled = this.isFocusTrapEnabled;
183+
Promise.resolve().then(() => this._isInitialized = true);
179184
}
180185

181186
ngOnDestroy() {
@@ -237,6 +242,17 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
237242
}
238243
}
239244

245+
/**
246+
* Figures out the state of the sidenav animation.
247+
*/
248+
_getAnimationState(): 'initial-open' | 'open' | 'void' {
249+
if (this.opened) {
250+
return this._isInitialized ? 'open' : 'initial-open';
251+
}
252+
253+
return 'void';
254+
}
255+
240256
_onAnimationEnd(event: AnimationEvent) {
241257
if (event.toState === 'open') {
242258
this.onOpen.emit(new MdSidenavToggleResult('open', true));

0 commit comments

Comments
 (0)