Skip to content

Commit 03e749a

Browse files
crisbetojelbourn
authored andcommitted
fix(sidenav): disable all sidenav animations when using NoopAnimationsModule (#11180)
Currently when the `NoopAnimationsModule` is used, only the Angular-based animations in the sidenav are disabled, however this doesn't include the transitions on the content and the backdrop. With these changes all transitions will be disabled.
1 parent 9715928 commit 03e749a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/lib/sidenav/drawer.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $mat-drawer-over-drawer-z-index: 4;
1313
// Mixin that creates a new stacking context.
1414
// see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
1515
// stylelint-enable
16-
@mixin mat-drawer-stacking-context($z-index:1) {
16+
@mixin mat-drawer-stacking-context($z-index: 1) {
1717
position: relative;
1818

1919
// Use a z-index to create a new stacking context. (We can't use transform because it breaks fixed

src/lib/sidenav/drawer.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,14 @@ describe('MatDrawerContainer', () => {
609609
}));
610610

611611
it('should not animate when the sidenav is open on load ', fakeAsync(() => {
612+
TestBed
613+
.resetTestingModule()
614+
.configureTestingModule({
615+
imports: [MatSidenavModule, BrowserAnimationsModule],
616+
declarations: [DrawerSetToOpenedTrue],
617+
})
618+
.compileComponents();
619+
612620
const fixture = TestBed.createComponent(DrawerSetToOpenedTrue);
613621

614622
fixture.detectChanges();

src/lib/sidenav/drawer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {DOCUMENT} from '@angular/common';
3838
import {filter, take, startWith, takeUntil, map, debounceTime} from 'rxjs/operators';
3939
import {merge, fromEvent, Observable, Subject} from 'rxjs';
4040
import {matDrawerAnimations} from './drawer-animations';
41+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
4142

4243

4344
/** Throws an exception when two MatDrawer are matching the same position. */
@@ -474,7 +475,8 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
474475
private _element: ElementRef,
475476
private _ngZone: NgZone,
476477
private _changeDetectorRef: ChangeDetectorRef,
477-
@Inject(MAT_DRAWER_DEFAULT_AUTOSIZE) defaultAutosize = false) {
478+
@Inject(MAT_DRAWER_DEFAULT_AUTOSIZE) defaultAutosize = false,
479+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) {
478480

479481
// If a `Dir` directive exists up the tree, listen direction changes
480482
// and update the left/right properties to point to the proper start/end.
@@ -550,7 +552,7 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
550552
.subscribe((event: AnimationEvent) => {
551553
// Set the transition class on the container so that the animations occur. This should not
552554
// be set initially because animations should only be triggered via a change in state.
553-
if (event.toState !== 'open-instant') {
555+
if (event.toState !== 'open-instant' && this._animationMode !== 'NoopAnimations') {
554556
this._element.nativeElement.classList.add('mat-drawer-transition');
555557
}
556558

0 commit comments

Comments
 (0)