Skip to content

Commit 11a4ff0

Browse files
crisbetommalerba
authored andcommitted
fix(card): disable all animations when using NoopAnimationsModule (#11538)
* fix(card): disable all animations when using NoopAnimationsModule Fixes the card `box-shadow` transition not being disabled when it's inside something with the `NoopAnimationsModule`. Relates to #10590. * fix lint * fix api test
1 parent 2e047b4 commit 11a4ff0

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/material/card/card.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/elevation';
3+
@import '../core/style/noop-animation';
34
@import '../../cdk/a11y/a11y';
45

56

@@ -9,6 +10,7 @@ $mat-card-header-size: 40px !default;
910

1011
.mat-card {
1112
@include mat-elevation-transition;
13+
@include _noop-animation();
1214
display: block;
1315
position: relative;
1416
padding: $mat-card-padding;

src/material/card/card.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
ChangeDetectionStrategy,
1313
Directive,
1414
Input,
15+
Optional,
16+
Inject,
1517
} from '@angular/core';
18+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
1619

1720

1821
/**
@@ -156,9 +159,15 @@ 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+
// @breaking-change 9.0.0 `_animationMode` parameter to be made required.
169+
constructor(@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {}
170+
}
162171

163172

164173
/**

tools/public_api_guard/material/card.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export declare class MatCard {
2+
_animationMode?: string | undefined;
3+
constructor(_animationMode?: string | undefined);
24
}
35

46
export declare class MatCardActions {

0 commit comments

Comments
 (0)