From aa3fc8d46ce96035a98aab40ed3ceb2343b85db0 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sat, 12 May 2018 11:44:12 +0200 Subject: [PATCH] fix(radio): disable animations when using NoopAnimationsModule Disables the CSS-based animations in the radio buttons when the `NoopAnimationsModule` is used. --- src/lib/radio/radio.scss | 8 ++++++++ src/lib/radio/radio.ts | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/radio/radio.scss b/src/lib/radio/radio.scss index 09663dd6497a..7baa894e3469 100644 --- a/src/lib/radio/radio.scss +++ b/src/lib/radio/radio.scss @@ -47,6 +47,10 @@ $mat-radio-ripple-radius: 25px; style: solid; radius: 50%; } + + ._mat-animation-noopable & { + transition: none; + } } // The inner circle for the radio, shown when checked. @@ -64,6 +68,10 @@ $mat-radio-ripple-radius: 25px; // IE to flash the entire circle for a couple of frames, throwing off the entire animation. transform: scale(0.001); + ._mat-animation-noopable & { + transition: none; + } + .mat-radio-checked & { transform: scale(0.5); diff --git a/src/lib/radio/radio.ts b/src/lib/radio/radio.ts index 54e00a3c6f5e..e601a1caf568 100644 --- a/src/lib/radio/radio.ts +++ b/src/lib/radio/radio.ts @@ -28,6 +28,7 @@ import { QueryList, ViewChild, ViewEncapsulation, + Inject, } from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; import { @@ -42,6 +43,8 @@ import { mixinTabIndex, RippleRef, } from '@angular/material/core'; +import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations'; + // Increasing integer for generating unique ids for radio components. let nextUniqueId = 0; @@ -324,6 +327,7 @@ export const _MatRadioButtonMixinBase = 'class': 'mat-radio-button', '[class.mat-radio-checked]': 'checked', '[class.mat-radio-disabled]': 'disabled', + '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"', '[attr.id]': 'id', // Note: under normal conditions focus shouldn't land on this element, however it may be // programmatically set, for example inside of a focus trap, in this case we want to forward @@ -467,7 +471,8 @@ export class MatRadioButton extends _MatRadioButtonMixinBase elementRef: ElementRef, private _changeDetector: ChangeDetectorRef, private _focusMonitor: FocusMonitor, - private _radioDispatcher: UniqueSelectionDispatcher) { + private _radioDispatcher: UniqueSelectionDispatcher, + @Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) { super(elementRef); // Assertions. Ideally these should be stripped out by the compiler.