Skip to content

Commit 695af66

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 1f3324e commit 695af66

File tree

9 files changed

+39
-10
lines changed

9 files changed

+39
-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;
@@ -61,6 +62,7 @@ $mat-tab-animation-duration: 500ms !default;
6162
@mixin ink-bar {
6263
$height: 2px;
6364

65+
@include _noop-animation();
6466
position: absolute;
6567
bottom: 0;
6668
height: $height;

src/lib/tabs/ink-bar.ts

Lines changed: 5 additions & 2 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
/**
@@ -46,13 +47,15 @@ export function _MAT_INK_BAR_POSITIONER_FACTORY(): _MatInkBarPositioner {
4647
selector: 'mat-ink-bar',
4748
host: {
4849
'class': 'mat-ink-bar',
50+
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
4951
},
5052
})
5153
export class MatInkBar {
5254
constructor(
5355
private _elementRef: ElementRef<HTMLElement>,
5456
private _ngZone: NgZone,
55-
@Inject(_MAT_INK_BAR_POSITIONER) private _inkBarPositioner: _MatInkBarPositioner) { }
57+
@Inject(_MAT_INK_BAR_POSITIONER) private _inkBarPositioner: _MatInkBarPositioner,
58+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) { }
5659

5760
/**
5861
* Calculates the styles from the provided element in order to align the ink-bar to that element.

src/lib/tabs/tab-group.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
</div>
3232
</mat-tab-header>
3333

34-
<div class="mat-tab-body-wrapper" #tabBodyWrapper>
34+
<div
35+
class="mat-tab-body-wrapper"
36+
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
37+
#tabBodyWrapper>
3538
<mat-tab-body role="tabpanel"
3639
*ngFor="let tab of _tabs; let i = index"
3740
[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 {
@@ -37,6 +38,7 @@
3738

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

src/lib/tabs/tab-group.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import {
2222
QueryList,
2323
ViewChild,
2424
ViewEncapsulation,
25-
InjectionToken,
26-
Inject,
2725
Optional,
26+
Inject,
27+
InjectionToken,
2828
} from '@angular/core';
2929
import {
3030
CanColor,
@@ -38,6 +38,7 @@ import {
3838
import {merge, Subscription} from 'rxjs';
3939
import {MatTab} from './tab';
4040
import {MatTabHeader} from './tab-header';
41+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
4142

4243

4344
/** Used to generate unique ID's for each tab component */
@@ -171,7 +172,8 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
171172

172173
constructor(elementRef: ElementRef,
173174
private _changeDetectorRef: ChangeDetectorRef,
174-
@Inject(MAT_TABS_CONFIG) @Optional() defaultConfig?: MatTabsConfig) {
175+
@Inject(MAT_TABS_CONFIG) @Optional() defaultConfig?: MatTabsConfig,
176+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
175177
super(elementRef);
176178
this._groupId = nextId++;
177179
this.animationDuration = defaultConfig && defaultConfig.animationDuration ?

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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
EventEmitter,
2222
Input,
2323
NgZone,
24+
Inject,
2425
OnDestroy,
2526
Optional,
2627
Output,
@@ -35,6 +36,7 @@ import {MatInkBar} from './ink-bar';
3536
import {MatTabLabelWrapper} from './tab-label-wrapper';
3637
import {FocusKeyManager} from '@angular/cdk/a11y';
3738
import {Platform} from '@angular/cdk/platform';
39+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3840

3941

4042
/**
@@ -142,9 +144,11 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
142144
private _changeDetectorRef: ChangeDetectorRef,
143145
private _viewportRuler: ViewportRuler,
144146
@Optional() private _dir: Directionality,
145-
// @breaking-change 8.0.0 `_ngZone` and `_platforms` parameters to be made required.
147+
// @breaking-change 8.0.0 `_ngZone`, `_platforms` and
148+
// `_animationMode` parameters to be made required.
146149
private _ngZone?: NgZone,
147-
private _platform?: Platform) {
150+
private _platform?: Platform,
151+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
148152
super();
149153
}
150154

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {merge, of as observableOf, Subject} from 'rxjs';
4747
import {takeUntil} from 'rxjs/operators';
4848
import {MatInkBar} from '../ink-bar';
4949
import {FocusMonitor} from '@angular/cdk/a11y';
50+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
5051

5152

5253
// Boilerplate for applying mixins to MatTabNav.
@@ -229,7 +230,8 @@ export class MatTabLink extends _MatTabLinkMixinBase
229230
* @deprecated
230231
* @breaking-change 8.0.0 `_focusMonitor` parameter to be made required.
231232
*/
232-
private _focusMonitor?: FocusMonitor) {
233+
private _focusMonitor?: FocusMonitor,
234+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
233235
super();
234236

235237
this._tabLinkRipple = new RippleRenderer(this, ngZone, _elementRef, platform);
@@ -241,6 +243,10 @@ export class MatTabLink extends _MatTabLinkMixinBase
241243
if (_focusMonitor) {
242244
_focusMonitor.monitor(_elementRef);
243245
}
246+
247+
if (animationMode === 'NoopAnimations') {
248+
this.rippleConfig.animation = {enterDuration: 0, exitDuration: 0};
249+
}
244250
}
245251

246252
ngOnDestroy() {

0 commit comments

Comments
 (0)