Skip to content

Commit ca39351

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 707a7ee commit ca39351

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/lib/badge/_badge-theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ $mat-badge-large-size: $mat-badge-default-size + 6;
155155
pointer-events: none;
156156
}
157157

158+
.ng-animate-disabled .mat-badge-content,
159+
.mat-badge-content._mat-animation-noopable {
160+
transition: none;
161+
}
162+
158163
// The active class is added after the element is added
159164
// so it can animate scale to default
160165
.mat-badge-content.mat-badge-active {

src/lib/badge/badge.ts

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

2425

2526
let nextId = 0;
@@ -122,9 +123,10 @@ export class MatBadge extends _MatBadgeMixinBase implements OnDestroy, CanDisabl
122123
private _elementRef: ElementRef<HTMLElement>,
123124
private _ariaDescriber: AriaDescriber,
124125
/** @breaking-change 8.0.0 Make _renderer a required param and remove _document. */
125-
private _renderer?: Renderer2) {
126-
super();
127-
}
126+
private _renderer?: Renderer2,
127+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) {
128+
super();
129+
}
128130

129131
/** Whether the badge is above the host or not */
130132
isAbove(): boolean {
@@ -163,14 +165,18 @@ export class MatBadge extends _MatBadgeMixinBase implements OnDestroy, CanDisabl
163165
badgeElement.classList.add('mat-badge-content');
164166
badgeElement.textContent = this.content;
165167

168+
if (this._animationMode === 'NoopAnimations') {
169+
badgeElement.classList.add('_mat-animation-noopable');
170+
}
171+
166172
if (this.description) {
167173
badgeElement.setAttribute('aria-label', this.description);
168174
}
169175

170176
this._elementRef.nativeElement.appendChild(badgeElement);
171177

172178
// animate in after insertion
173-
if (typeof requestAnimationFrame === 'function') {
179+
if (typeof requestAnimationFrame === 'function' && this._animationMode !== 'NoopAnimations') {
174180
this._ngZone.runOutsideAngular(() => {
175181
requestAnimationFrame(() => {
176182
badgeElement.classList.add(activeClass);

src/lib/bottom-sheet/bottom-sheet.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ describe('MatBottomSheet with default options', () => {
669669
dispatchKeyboardEvent(document.body, 'keydown', ESCAPE);
670670

671671
expect(overlayContainerElement.querySelector('mat-bottom-sheet-container')).toBeTruthy();
672-
expect(document.activeElement.tagName).not.toBe('INPUT');
672+
expect(document.activeElement!.tagName).not.toBe('INPUT');
673673
});
674674

675675
it('should be overridable by open() options', fakeAsync(() => {

0 commit comments

Comments
 (0)