Skip to content

Commit d96ebd0

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 8ed0129 commit d96ebd0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/lib/badge/_badge-theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ $mat-badge-large-size: $mat-badge-default-size + 6;
139139
pointer-events: none;
140140
}
141141

142+
.ng-animate-disabled .mat-badge-content,
143+
.mat-badge-content._mat-animation-noopable {
144+
transition: none;
145+
}
146+
142147
// The active class is added after the element is added
143148
// so it can animate scale to default
144149
.mat-badge-content.mat-badge-active {

src/lib/badge/badge.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
Renderer2,
2121
} from '@angular/core';
2222
import {ThemePalette} from '@angular/material/core';
23+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
2324

2425

2526
let nextId = 0;
@@ -112,8 +113,12 @@ export class MatBadge implements OnDestroy {
112113
private _ngZone: NgZone,
113114
private _elementRef: ElementRef<HTMLElement>,
114115
private _ariaDescriber: AriaDescriber,
115-
/** @breaking-change 8.0.0 Make _renderer a required param and remove _document. */
116-
private _renderer?: Renderer2) {}
116+
/**
117+
* @breaking-change 8.0.0 Make _renderer and _animationMode
118+
* required params and remove _document.
119+
*/
120+
private _renderer?: Renderer2,
121+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) {}
117122

118123
/** Whether the badge is above the host or not */
119124
isAbove(): boolean {
@@ -152,14 +157,18 @@ export class MatBadge implements OnDestroy {
152157
badgeElement.classList.add('mat-badge-content');
153158
badgeElement.textContent = this.content;
154159

160+
if (this._animationMode === 'NoopAnimations') {
161+
badgeElement.classList.add('_mat-animation-noopable');
162+
}
163+
155164
if (this.description) {
156165
badgeElement.setAttribute('aria-label', this.description);
157166
}
158167

159168
this._elementRef.nativeElement.appendChild(badgeElement);
160169

161170
// animate in after insertion
162-
if (typeof requestAnimationFrame === 'function') {
171+
if (typeof requestAnimationFrame === 'function' && this._animationMode !== 'NoopAnimations') {
163172
this._ngZone.runOutsideAngular(() => {
164173
requestAnimationFrame(() => {
165174
badgeElement.classList.add(activeClass);

0 commit comments

Comments
 (0)