Skip to content

Commit

Permalink
fix(material/radio): disable ripples under noop animations module (#2…
Browse files Browse the repository at this point in the history
…2855)

Fixes that we weren't disabling the radio button ripples when the `NoopAnimationsModule` is used.

(cherry picked from commit babf80f)
  • Loading branch information
crisbeto authored and mmalerba committed Jun 2, 2021
1 parent cfc4ad9 commit a3bb573
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/material-experimental/mdc-radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,18 @@ export class MatRadioButton extends _MatRadioButtonBase implements AfterViewInit

_radioFoundation = new MDCRadioFoundation(this._radioAdapter);
_classes: {[key: string]: boolean} = {};
_noopAnimations: boolean;

constructor(@Optional() @Inject(MAT_RADIO_GROUP) radioGroup: MatRadioGroup,
elementRef: ElementRef,
_changeDetector: ChangeDetectorRef,
_focusMonitor: FocusMonitor,
_radioDispatcher: UniqueSelectionDispatcher,
@Optional() @Inject(ANIMATION_MODULE_TYPE) _animationMode?: string,
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string,
@Optional() @Inject(MAT_RADIO_DEFAULT_OPTIONS)
_providerOverride?: MatRadioDefaultOptions,
@Attribute('tabindex') tabIndex?: string) {
super(radioGroup, elementRef, _changeDetector, _focusMonitor,
_radioDispatcher, _animationMode, _providerOverride, tabIndex);
this._noopAnimations = _animationMode === 'NoopAnimations';
_radioDispatcher, animationMode, _providerOverride, tabIndex);
this._rippleAnimation =
this._noopAnimations ? {enterDuration: 0, exitDuration: 0} : RIPPLE_ANIMATION_CONFIG;
}
Expand Down
2 changes: 1 addition & 1 deletion src/material/radio/radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
[matRippleDisabled]="_isRippleDisabled()"
[matRippleCentered]="true"
[matRippleRadius]="20"
[matRippleAnimation]="{enterDuration: 150}">
[matRippleAnimation]="{enterDuration: _noopAnimations ? 0 : 150}">

<span class="mat-ripple-element mat-radio-persistent-ripple"></span>
</span>
Expand Down
8 changes: 6 additions & 2 deletions src/material/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,23 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
/** The native `<input type=radio>` element */
@ViewChild('input') _inputElement: ElementRef<HTMLInputElement>;

/** Whether animations are disabled. */
_noopAnimations: boolean;

constructor(radioGroup: _MatRadioGroupBase<_MatRadioButtonBase>,
elementRef: ElementRef,
protected _changeDetector: ChangeDetectorRef,
private _focusMonitor: FocusMonitor,
private _radioDispatcher: UniqueSelectionDispatcher,
public _animationMode?: string,
animationMode?: string,
private _providerOverride?: MatRadioDefaultOptions,
tabIndex?: string) {
super(elementRef);

// Assertions. Ideally these should be stripped out by the compiler.
// TODO(jelbourn): Assert that there's no name binding AND a parent radio group.
this.radioGroup = radioGroup;
this._noopAnimations = animationMode === 'NoopAnimations';

if (tabIndex) {
this.tabIndex = coerceNumberProperty(tabIndex, 0);
Expand Down Expand Up @@ -636,7 +640,7 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
'class': 'mat-radio-button',
'[class.mat-radio-checked]': 'checked',
'[class.mat-radio-disabled]': 'disabled',
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
'[class._mat-animation-noopable]': '_noopAnimations',
'[class.mat-primary]': 'color === "primary"',
'[class.mat-accent]': 'color === "accent"',
'[class.mat-warn]': 'color === "warn"',
Expand Down
4 changes: 2 additions & 2 deletions tools/public_api_guard/material/radio.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export declare abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase implements OnInit, AfterViewInit, OnDestroy, CanDisableRipple, HasTabIndex {
_animationMode?: string | undefined;
protected _changeDetector: ChangeDetectorRef;
_inputElement: ElementRef<HTMLInputElement>;
_noopAnimations: boolean;
ariaDescribedby: string;
ariaLabel: string;
ariaLabelledby: string;
Expand All @@ -22,7 +22,7 @@ export declare abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBa
set required(value: boolean);
get value(): any;
set value(value: any);
constructor(radioGroup: _MatRadioGroupBase<_MatRadioButtonBase>, elementRef: ElementRef, _changeDetector: ChangeDetectorRef, _focusMonitor: FocusMonitor, _radioDispatcher: UniqueSelectionDispatcher, _animationMode?: string | undefined, _providerOverride?: MatRadioDefaultOptions | undefined, tabIndex?: string);
constructor(radioGroup: _MatRadioGroupBase<_MatRadioButtonBase>, elementRef: ElementRef, _changeDetector: ChangeDetectorRef, _focusMonitor: FocusMonitor, _radioDispatcher: UniqueSelectionDispatcher, animationMode?: string, _providerOverride?: MatRadioDefaultOptions | undefined, tabIndex?: string);
_isRippleDisabled(): boolean;
_markForCheck(): void;
_onInputChange(event: Event): void;
Expand Down

0 comments on commit a3bb573

Please sign in to comment.