Skip to content

Commit e052fd5

Browse files
committed
fix: missing components not respecting disabled animations
* Ensures that all components with custom CSS transitions respect the `NoopAnimationsModule` or `[@.disabled]` state. Related to #12829
1 parent 36d8412 commit e052fd5

File tree

10 files changed

+52
-7
lines changed

10 files changed

+52
-7
lines changed

src/lib/badge/_badge-theme.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ $mat-badge-large-size: $mat-badge-default-size + 6;
137137
white-space: nowrap;
138138
text-overflow: ellipsis;
139139
pointer-events: none;
140+
141+
._mat-animation-noopable &, .ng-animate-disabled & {
142+
transition: none;
143+
}
140144
}
141145

142146
// The active class is added after the element is added

src/lib/badge/badge.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {DOCUMENT} from '@angular/common';
1212
import {Directive, ElementRef, Inject, Input, NgZone, OnDestroy, Optional} from '@angular/core';
1313
import {ThemePalette} from '@angular/material/core';
14+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
1415

1516

1617
let nextId = 0;
@@ -32,6 +33,7 @@ export type MatBadgeSize = 'small' | 'medium' | 'large';
3233
'[class.mat-badge-medium]': 'size === "medium"',
3334
'[class.mat-badge-large]': 'size === "large"',
3435
'[class.mat-badge-hidden]': 'hidden || !_hasContent',
36+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
3537
},
3638
})
3739
export class MatBadge implements OnDestroy {
@@ -102,7 +104,8 @@ export class MatBadge implements OnDestroy {
102104
@Optional() @Inject(DOCUMENT) private _document: any,
103105
private _ngZone: NgZone,
104106
private _elementRef: ElementRef,
105-
private _ariaDescriber: AriaDescriber) {}
107+
private _ariaDescriber: AriaDescriber,
108+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {}
106109

107110
/** Whether the badge is above the host or not */
108111
isAbove(): boolean {

src/lib/button/_button-base.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ $mat-mini-fab-padding: 8px !default;
8686
transition: background $swift-ease-out-duration $swift-ease-out-timing-function,
8787
mat-elevation-transition-property-value();
8888

89+
&._mat-animation-noopable, &.ng-animate-disabled, .ng-animate-disabled & {
90+
transition: none;
91+
}
92+
8993
&:not([disabled]):active {
9094
@include mat-overridable-elevation(8);
9195
}

src/lib/card/card.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ $mat-card-header-size: 40px !default;
1616
padding: $mat-card-default-padding;
1717
border-radius: $mat-card-border-radius;
1818

19+
&._mat-animation-noopable, &.ng-animate-disabled, .ng-animate-disabled & {
20+
transition: none;
21+
}
22+
1923
.mat-divider-horizontal {
2024
position: absolute;
2125
left: 0;

src/lib/card/card.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
*/
88

99
import {
10-
Component,
11-
ViewEncapsulation,
1210
ChangeDetectionStrategy,
11+
Component,
1312
Directive,
13+
Inject,
1414
Input,
15+
Optional,
16+
ViewEncapsulation,
1517
} from '@angular/core';
18+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
1619

1720

1821
/**
@@ -156,9 +159,14 @@ export class MatCardAvatar {}
156159
styleUrls: ['card.css'],
157160
encapsulation: ViewEncapsulation.None,
158161
changeDetection: ChangeDetectionStrategy.OnPush,
159-
host: {'class': 'mat-card'}
162+
host: {
163+
'class': 'mat-card',
164+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
165+
}
160166
})
161-
export class MatCard {}
167+
export class MatCard {
168+
constructor(@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {}
169+
}
162170

163171

164172
/**

src/lib/chips/chip.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
RippleRenderer,
3737
RippleTarget
3838
} from '@angular/material/core';
39+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3940
import {Subject} from 'rxjs';
4041
import {take} from 'rxjs/operators';
4142

@@ -104,6 +105,7 @@ export class MatChipTrailingIcon {}
104105
'[class.mat-chip-with-avatar]': 'avatar',
105106
'[class.mat-chip-with-trailing-icon]': 'trailingIcon || removeIcon',
106107
'[class.mat-chip-disabled]': 'disabled',
108+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
107109
'[attr.disabled]': 'disabled || null',
108110
'[attr.aria-disabled]': 'disabled.toString()',
109111
'[attr.aria-selected]': 'ariaSelected',
@@ -221,7 +223,8 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
221223
constructor(public _elementRef: ElementRef,
222224
private _ngZone: NgZone,
223225
platform: Platform,
224-
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalOptions: RippleGlobalOptions) {
226+
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalOptions: RippleGlobalOptions,
227+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
225228
super(_elementRef);
226229

227230
this._addHostClassName();

src/lib/chips/chips.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ $mat-chip-remove-size: 18px;
4040
height: $mat-chip-remove-size;
4141
}
4242

43+
&._mat-animation-noopable, &.ng-animate-disabled, .ng-animate-disabled & {
44+
transition: none;
45+
}
46+
4347
&:focus {
4448
@include mat-elevation(3);
4549
outline: none;

src/lib/expansion/expansion-panel.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
transition: margin 225ms $mat-fast-out-slow-in-timing-function;
1414
border-radius: $border-radius;
1515

16+
&._mat-animation-noopable, &.ng-animate-disabled, .ng-animate-disabled & {
17+
transition: none;
18+
}
19+
1620
.mat-accordion & {
1721
&:not(.mat-expanded), &:not(.mat-expansion-panel-spacing) {
1822
border-radius: 0;

src/lib/expansion/expansion-panel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
ViewChild,
3434
} from '@angular/core';
3535
import {DOCUMENT} from '@angular/common';
36+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3637
import {Subject} from 'rxjs';
3738
import {filter, startWith, take} from 'rxjs/operators';
3839
import {MatAccordion} from './accordion';
@@ -74,6 +75,7 @@ let uniqueId = 0;
7475
'class': 'mat-expansion-panel',
7576
'[class.mat-expanded]': 'expanded',
7677
'[class.mat-expansion-panel-spacing]': '_hasSpacing()',
78+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
7779
}
7880
})
7981
export class MatExpansionPanel extends CdkAccordionItem implements AfterContentInit, OnChanges,
@@ -121,8 +123,10 @@ export class MatExpansionPanel extends CdkAccordionItem implements AfterContentI
121123
_changeDetectorRef: ChangeDetectorRef,
122124
_uniqueSelectionDispatcher: UniqueSelectionDispatcher,
123125
private _viewContainerRef: ViewContainerRef,
124-
@Inject(DOCUMENT) _document?: any) {
126+
@Inject(DOCUMENT) _document?: any,
127+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
125128
super(accordion, _changeDetectorRef, _uniqueSelectionDispatcher);
129+
126130
this.accordion = accordion;
127131
this._document = _document;
128132
}

src/lib/sidenav/drawer.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ $mat-drawer-over-drawer-z-index: 4;
5151
&.mat-drawer-container-explicit-backdrop .mat-drawer-side {
5252
z-index: $mat-drawer-backdrop-z-index;
5353
}
54+
55+
// Note that the `NoopAnimationsModule` is being handled inside of the component code.
56+
&.ng-animate-disabled, .ng-animate-disabled & {
57+
.mat-drawer-backdrop, .mat-drawer-content {
58+
transition: none;
59+
}
60+
}
5461
}
5562

5663
.mat-drawer-backdrop {

0 commit comments

Comments
 (0)