Skip to content

Commit e28cc3d

Browse files
committed
fix(tabs): disable all animations when using NoopAnimationsModule
Currently some animations in the tab components don't get disabled, when using the `NoopAnimationsModule`, because they don't go through the Angular animations. These changes ensure that everything will be disabled. Fixes #10590.
1 parent 9f6aa84 commit e28cc3d

File tree

9 files changed

+38
-10
lines changed

9 files changed

+38
-10
lines changed

src/lib/tabs/_tabs-common.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import '../core/style/variables';
2+
@import '../core/style/noop-animation';
23
@import '../../cdk/a11y/a11y';
34

45
$mat-tab-bar-height: 48px !default;
@@ -49,6 +50,7 @@ $mat-tab-animation-duration: 500ms !default;
4950
@mixin ink-bar {
5051
$height: 2px;
5152

53+
@include _noop-animation();
5254
position: absolute;
5355
left: 0;
5456
bottom: 0;

src/lib/tabs/ink-bar.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Directive, ElementRef, Inject, InjectionToken, NgZone} from '@angular/core';
9+
import {Directive, ElementRef, Inject, InjectionToken, NgZone, Optional} from '@angular/core';
10+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
1011

1112
/**
1213
* Interface for a a MatInkBar positioner method, defining the positioning and width of the ink
@@ -55,7 +56,8 @@ export class MatInkBar {
5556
constructor(
5657
private _elementRef: ElementRef<HTMLElement>,
5758
private _ngZone: NgZone,
58-
@Inject(_MAT_INK_BAR_POSITIONER) private _inkBarPositioner: _MatInkBarPositioner) { }
59+
@Inject(_MAT_INK_BAR_POSITIONER) private _inkBarPositioner: _MatInkBarPositioner,
60+
@Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) { }
5961

6062
/**
6163
* Calculates the styles from the provided element in order to align the ink-bar to that element.
@@ -93,6 +95,6 @@ export class MatInkBar {
9395
const inkBar = this._elementRef.nativeElement;
9496

9597
inkBar.style.transform = `translateX(${positions.left}px) scaleX(${positions.width})`;
96-
this.shouldAnimate = true;
98+
this.shouldAnimate = this._animationMode !== 'NoopAnimations';
9799
}
98100
}

src/lib/tabs/tab-group.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
</div>
2828
</mat-tab-header>
2929

30-
<div class="mat-tab-body-wrapper" #tabBodyWrapper>
30+
<div
31+
class="mat-tab-body-wrapper"
32+
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
33+
#tabBodyWrapper>
3134
<mat-tab-body role="tabpanel"
3235
*ngFor="let tab of _tabs; let i = index"
3336
[id]="_getTabContentId(i)"

src/lib/tabs/tab-group.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/layout-common';
3+
@import '../core/style/noop-animation';
34
@import 'tabs-common';
45

56
.mat-tab-group {
@@ -36,6 +37,7 @@
3637

3738
// The bottom section of the view; contains the tab bodies
3839
.mat-tab-body-wrapper {
40+
@include _noop-animation();
3941
position: relative;
4042
overflow: hidden;
4143
display: flex;

src/lib/tabs/tab-group.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ import {
2222
QueryList,
2323
ViewChild,
2424
ViewEncapsulation,
25+
Optional,
26+
Inject,
2527
} from '@angular/core';
2628
import {
2729
CanColor,
2830
CanDisableRipple,
2931
mixinColor,
3032
mixinDisableRipple,
31-
ThemePalette
33+
ThemePalette,
3234
} from '@angular/material/core';
3335
import {merge, Subscription} from 'rxjs';
3436
import {MatTab} from './tab';
3537
import {MatTabHeader} from './tab-header';
38+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3639

3740

3841
/** Used to generate unique ID's for each tab component */
@@ -147,7 +150,8 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
147150
private _groupId: number;
148151

149152
constructor(elementRef: ElementRef,
150-
private _changeDetectorRef: ChangeDetectorRef) {
153+
private _changeDetectorRef: ChangeDetectorRef,
154+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
151155
super(elementRef);
152156
this._groupId = nextId++;
153157
}

src/lib/tabs/tab-header.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
<div class="mat-tab-label-container" #tabListContainer
1010
(keydown)="_handleKeydown($event)">
11-
<div class="mat-tab-list" #tabList role="tablist" (cdkObserveContent)="_onContentChanges()">
11+
<div
12+
class="mat-tab-list"
13+
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
14+
#tabList
15+
role="tablist"
16+
(cdkObserveContent)="_onContentChanges()">
1217
<div class="mat-tab-labels">
1318
<ng-content></ng-content>
1419
</div>

src/lib/tabs/tab-header.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import '../core/style/variables';
22
@import '../core/style/layout-common';
3+
@import '../core/style/noop-animation';
34
@import 'tabs-common';
45

56
.mat-tab-header {
@@ -75,6 +76,7 @@
7576
}
7677

7778
.mat-tab-list {
79+
@include _noop-animation();
7880
flex-grow: 1;
7981
position: relative;
8082
transition: transform 500ms cubic-bezier(0.35, 0, 0.25, 1);

src/lib/tabs/tab-header.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ElementRef,
2121
EventEmitter,
2222
Input,
23+
Inject,
2324
OnDestroy,
2425
Optional,
2526
Output,
@@ -31,6 +32,7 @@ import {CanDisableRipple, mixinDisableRipple} from '@angular/material/core';
3132
import {merge, of as observableOf, Subscription} from 'rxjs';
3233
import {MatInkBar} from './ink-bar';
3334
import {MatTabLabelWrapper} from './tab-label-wrapper';
35+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3436

3537

3638
/**
@@ -131,7 +133,8 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
131133
constructor(private _elementRef: ElementRef,
132134
private _changeDetectorRef: ChangeDetectorRef,
133135
private _viewportRuler: ViewportRuler,
134-
@Optional() private _dir: Directionality) {
136+
@Optional() private _dir: Directionality,
137+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
135138
super();
136139
}
137140

src/lib/tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
import {merge, of as observableOf, Subject} from 'rxjs';
4747
import {takeUntil} from 'rxjs/operators';
4848
import {MatInkBar} from '../ink-bar';
49+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
4950

5051

5152
// Boilerplate for applying mixins to MatTabNav.
@@ -218,12 +219,12 @@ export class MatTabLink extends _MatTabLinkMixinBase
218219
ngZone: NgZone,
219220
platform: Platform,
220221
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalOptions: RippleGlobalOptions,
221-
@Attribute('tabindex') tabIndex: string) {
222+
@Attribute('tabindex') tabIndex: string,
223+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
222224
super();
223225

224226
this._tabLinkRipple = new RippleRenderer(this, ngZone, _elementRef, platform);
225227
this._tabLinkRipple.setupTriggerEvents(_elementRef.nativeElement);
226-
227228
this.tabIndex = parseInt(tabIndex) || 0;
228229

229230
if (globalOptions) {
@@ -233,6 +234,10 @@ export class MatTabLink extends _MatTabLinkMixinBase
233234
animation: globalOptions.animation,
234235
};
235236
}
237+
238+
if (animationMode === 'NoopAnimations') {
239+
this.rippleConfig.animation = {enterDuration: 0, exitDuration: 0};
240+
}
236241
}
237242

238243
ngOnDestroy() {

0 commit comments

Comments
 (0)