Skip to content

Commit 470d083

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 aa09628 commit 470d083

File tree

9 files changed

+38
-9
lines changed

9 files changed

+38
-9
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
bottom: 0;
5456
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,
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 {
@@ -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,
@@ -32,6 +33,7 @@ import {merge, of as observableOf, Subscription} from 'rxjs';
3233
import {MatInkBar} from './ink-bar';
3334
import {MatTabLabelWrapper} from './tab-label-wrapper';
3435
import {FocusKeyManager} from '@angular/cdk/a11y';
36+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3537

3638

3739
/**
@@ -135,7 +137,8 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
135137
constructor(private _elementRef: ElementRef,
136138
private _changeDetectorRef: ChangeDetectorRef,
137139
private _viewportRuler: ViewportRuler,
138-
@Optional() private _dir: Directionality) {
140+
@Optional() private _dir: Directionality,
141+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
139142
super();
140143
}
141144

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) {
@@ -234,6 +235,10 @@ export class MatTabLink extends _MatTabLinkMixinBase
234235
animation: globalOptions.animation,
235236
};
236237
}
238+
239+
if (animationMode === 'NoopAnimations') {
240+
this.rippleConfig.animation = {enterDuration: 0, exitDuration: 0};
241+
}
237242
}
238243

239244
ngOnDestroy() {

0 commit comments

Comments
 (0)