Skip to content

Commit 1a75152

Browse files
crisbetommalerba
authored andcommitted
fix(button): disable all animations when using the NoopAnimationsModule (#11477)
Disables all of the button transitions and animations when the directive is inside a module with the `NoopAnimationsModule`. Relates to #10590.
1 parent c68ccc9 commit 1a75152

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

src/lib/button/_button-base.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '../core/style/variables';
22
@import '../core/style/elevation';
33
@import '../core/style/button-common';
4+
@import '../core/style/noop-animation';
45

56

67
// Flat and raised button standards
@@ -76,6 +77,7 @@ $mat-mini-fab-padding: 8px !default;
7677
@mixin mat-raised-button {
7778
@include mat-button-base;
7879
@include mat-overridable-elevation(2);
80+
@include _noop-animation();
7981

8082
// Force hardware acceleration.
8183
transform: translate3d(0, 0, 0);

src/lib/button/button.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888

8989
transition: $mat-button-focus-transition;
9090

91+
._mat-animation-noopable & {
92+
transition: none;
93+
}
94+
9195
@include cdk-high-contrast {
9296
// Note that IE will render this in the same way, no
9397
// matter whether the theme is light or dark. This helps

src/lib/button/button.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
OnDestroy,
1616
ViewChild,
1717
ViewEncapsulation,
18+
Optional,
19+
Inject,
1820
} from '@angular/core';
1921
import {
2022
CanColor,
@@ -25,6 +27,7 @@ import {
2527
mixinDisabled,
2628
mixinDisableRipple
2729
} from '@angular/material/core';
30+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
2831

2932
/** Default color palette for round buttons (mat-fab and mat-mini-fab) */
3033
const DEFAULT_ROUND_BUTTON_COLOR = 'accent';
@@ -65,6 +68,7 @@ export const _MatButtonMixinBase = mixinColor(mixinDisabled(mixinDisableRipple(M
6568
exportAs: 'matButton',
6669
host: {
6770
'[disabled]': 'disabled || null',
71+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
6872
},
6973
templateUrl: 'button.html',
7074
styleUrls: ['button.css'],
@@ -91,7 +95,9 @@ export class MatButton extends _MatButtonMixinBase
9195
*/
9296
// tslint:disable-next-line:no-unused-variable
9397
private _platform: Platform,
94-
private _focusMonitor: FocusMonitor) {
98+
private _focusMonitor: FocusMonitor,
99+
// @deletion-target 7.0.0 `_animationMode` parameter to be made required.
100+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
95101
super(elementRef);
96102

97103
// For each of the variant selectors that is prevent in the button's host
@@ -147,6 +153,7 @@ export class MatButton extends _MatButtonMixinBase
147153
'[attr.disabled]': 'disabled || null',
148154
'[attr.aria-disabled]': 'disabled.toString()',
149155
'(click)': '_haltDisabledEvents($event)',
156+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
150157
},
151158
inputs: ['disabled', 'disableRipple', 'color'],
152159
templateUrl: 'button.html',
@@ -156,8 +163,13 @@ export class MatButton extends _MatButtonMixinBase
156163
})
157164
export class MatAnchor extends MatButton {
158165

159-
constructor(platform: Platform, focusMonitor: FocusMonitor, elementRef: ElementRef) {
160-
super(elementRef, platform, focusMonitor);
166+
constructor(
167+
platform: Platform,
168+
focusMonitor: FocusMonitor,
169+
elementRef: ElementRef,
170+
// @deletion-target 7.0.0 `animationMode` parameter to be made required.
171+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
172+
super(elementRef, platform, focusMonitor, animationMode);
161173
}
162174

163175
_haltDisabledEvents(event: Event) {

src/lib/core/style/_noop-animation.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// For example:
1010
// .my-root {
1111
// .my-subclass {
12-
// @include _noop-animation()
12+
// @include _noop-animation();
1313
// }
1414
// }
1515
// results in:

0 commit comments

Comments
 (0)