Skip to content

Commit fd6761c

Browse files
committed
fix(badge): disable animations when using NoopAnimationsModule
Fixes the badge transitions not being disabled when using the `NoopAnimationsModule`. Relates to #10590.
1 parent abc3d38 commit fd6761c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/lib/badge/_badge-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@import '../core/theming/palette';
55
@import '../core/theming/theming';
66
@import '../core/typography/typography-utils';
7+
@import '../core/style/noop-animation';
78
@import '../../cdk/a11y/a11y';
89

910
$mat-badge-font-size: 12px;
@@ -147,6 +148,7 @@ $mat-badge-large-size: $mat-badge-default-size + 6;
147148
}
148149

149150
.mat-badge-content {
151+
@include _noop-animation();
150152
position: absolute;
151153
text-align: center;
152154
display: inline-block;

src/lib/badge/badge.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {DOCUMENT} from '@angular/common';
1212
import {Directive, ElementRef, Inject, Input, NgZone, OnDestroy, Optional} from '@angular/core';
1313
import {ThemePalette} from '@angular/material/core';
14+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
1415

1516

1617
let nextId = 0;
@@ -99,7 +100,8 @@ export class MatBadge implements OnDestroy {
99100
@Optional() @Inject(DOCUMENT) private _document: any,
100101
private _ngZone: NgZone,
101102
private _elementRef: ElementRef,
102-
private _ariaDescriber: AriaDescriber) {}
103+
private _ariaDescriber: AriaDescriber,
104+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) {}
103105

104106
/** Whether the badge is above the host or not */
105107
isAbove(): boolean {
@@ -136,14 +138,18 @@ export class MatBadge implements OnDestroy {
136138
badgeElement.classList.add('mat-badge-content');
137139
badgeElement.textContent = this.content;
138140

141+
if (this._animationMode === 'NoopAnimations') {
142+
badgeElement.classList.add('_mat-animation-noopable');
143+
}
144+
139145
if (this.description) {
140146
badgeElement.setAttribute('aria-label', this.description);
141147
}
142148

143149
this._elementRef.nativeElement.appendChild(badgeElement);
144150

145151
// animate in after insertion
146-
if (typeof requestAnimationFrame === 'function') {
152+
if (typeof requestAnimationFrame === 'function' && this._animationMode !== 'NoopAnimations') {
147153
this._ngZone.runOutsideAngular(() => {
148154
requestAnimationFrame(() => {
149155
badgeElement.classList.add(activeClass);

0 commit comments

Comments
 (0)