Skip to content

fix(button): disable all animations when using the NoopAnimationsModule #11477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/button/_button-base.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../core/style/variables';
@import '../core/style/elevation';
@import '../core/style/button-common';
@import '../core/style/noop-animation';


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

// Force hardware acceleration.
transform: translate3d(0, 0, 0);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@

transition: $mat-button-focus-transition;

._mat-animation-noopable & {
transition: none;
}

@include cdk-high-contrast {
// Note that IE will render this in the same way, no
// matter whether the theme is light or dark. This helps
Expand Down
18 changes: 15 additions & 3 deletions src/lib/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
OnDestroy,
ViewChild,
ViewEncapsulation,
Optional,
Inject,
} from '@angular/core';
import {
CanColor,
Expand All @@ -25,6 +27,7 @@ import {
mixinDisabled,
mixinDisableRipple
} from '@angular/material/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';

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

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

constructor(platform: Platform, focusMonitor: FocusMonitor, elementRef: ElementRef) {
super(elementRef, platform, focusMonitor);
constructor(
platform: Platform,
focusMonitor: FocusMonitor,
elementRef: ElementRef,
// @deletion-target 7.0.0 `animationMode` parameter to be made required.
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
super(elementRef, platform, focusMonitor, animationMode);
}

_haltDisabledEvents(event: Event) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/style/_noop-animation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// For example:
// .my-root {
// .my-subclass {
// @include _noop-animation()
// @include _noop-animation();
// }
// }
// results in:
Expand Down