Skip to content

Commit 1650562

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 d232d7c commit 1650562

File tree

10 files changed

+46
-14
lines changed

10 files changed

+46
-14
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
@@ -11,7 +11,12 @@
1111

1212
<div class="mat-tab-label-container" #tabListContainer
1313
(keydown)="_handleKeydown($event)">
14-
<div class="mat-tab-list" #tabList role="tablist" (cdkObserveContent)="_onContentChanges()">
14+
<div
15+
class="mat-tab-list"
16+
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
17+
#tabList
18+
role="tablist"
19+
(cdkObserveContent)="_onContentChanges()">
1520
<div class="mat-tab-labels">
1621
<ng-content></ng-content>
1722
</div>

src/lib/tabs/tab-header.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '../core/style/variables';
22
@import '../core/style/layout-common';
33
@import '../core/style/vendor-prefixes';
4+
@import '../core/style/noop-animation';
45
@import './tabs-common';
56

67
.mat-tab-header {
@@ -79,6 +80,7 @@
7980
}
8081

8182
.mat-tab-list {
83+
@include _noop-animation();
8284
flex-grow: 1;
8385
position: relative;
8486
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,
@@ -36,6 +37,7 @@ import {MatInkBar} from './ink-bar';
3637
import {MatTabLabelWrapper} from './tab-label-wrapper';
3738
import {FocusKeyManager} from '@angular/cdk/a11y';
3839
import {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';
40+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3941

4042

4143
/** Config used to bind passive event listeners */
@@ -164,9 +166,11 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
164166
private _changeDetectorRef: ChangeDetectorRef,
165167
private _viewportRuler: ViewportRuler,
166168
@Optional() private _dir: Directionality,
167-
// @breaking-change 8.0.0 `_ngZone` and `_platforms` parameters to be made required.
169+
// @breaking-change 8.0.0 `_ngZone`, `_platforms` and
170+
// `_animationMode` parameters to be made required.
168171
private _ngZone?: NgZone,
169-
private _platform?: Platform) {
172+
private _platform?: Platform,
173+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
170174
super();
171175

172176
const element = _elementRef.nativeElement;

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() {

tools/public_api_guard/lib/tabs.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export declare const _MatTabGroupMixinBase: CanColorCtor & CanDisableRippleCtor
1212
export declare const MAT_TABS_CONFIG: InjectionToken<{}>;
1313

1414
export declare class MatInkBar {
15-
constructor(_elementRef: ElementRef<HTMLElement>, _ngZone: NgZone, _inkBarPositioner: _MatInkBarPositioner);
15+
_animationMode?: string | undefined;
16+
constructor(_elementRef: ElementRef<HTMLElement>, _ngZone: NgZone, _inkBarPositioner: _MatInkBarPositioner, _animationMode?: string | undefined);
1617
alignToElement(element: HTMLElement): void;
1718
hide(): void;
1819
show(): void;
@@ -78,6 +79,7 @@ export declare class MatTabContent {
7879
}
7980

8081
export declare class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentInit, AfterContentChecked, OnDestroy, CanColor, CanDisableRipple {
82+
_animationMode?: string | undefined;
8183
_tabBodyWrapper: ElementRef;
8284
_tabHeader: MatTabHeader;
8385
_tabs: QueryList<MatTab>;
@@ -90,7 +92,7 @@ export declare class MatTabGroup extends _MatTabGroupMixinBase implements AfterC
9092
selectedIndex: number | null;
9193
readonly selectedIndexChange: EventEmitter<number>;
9294
readonly selectedTabChange: EventEmitter<MatTabChangeEvent>;
93-
constructor(elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, defaultConfig?: MatTabsConfig);
95+
constructor(elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, defaultConfig?: MatTabsConfig, _animationMode?: string | undefined);
9496
_focusChanged(index: number): void;
9597
_getTabContentId(i: number): string;
9698
_getTabIndex(tab: MatTab, idx: number): number | null;
@@ -110,6 +112,7 @@ export declare class MatTabGroupBase {
110112
}
111113

112114
export declare class MatTabHeader extends _MatTabHeaderMixinBase implements AfterContentChecked, AfterContentInit, AfterViewInit, OnDestroy, CanDisableRipple {
115+
_animationMode?: string | undefined;
113116
_disableScrollAfter: boolean;
114117
_disableScrollBefore: boolean;
115118
_inkBar: MatInkBar;
@@ -124,7 +127,7 @@ export declare class MatTabHeader extends _MatTabHeaderMixinBase implements Afte
124127
scrollDistance: number;
125128
readonly selectFocusedIndex: EventEmitter<number>;
126129
selectedIndex: number;
127-
constructor(_elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, _viewportRuler: ViewportRuler, _dir: Directionality, _ngZone?: NgZone | undefined, _platform?: Platform | undefined);
130+
constructor(_elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, _viewportRuler: ViewportRuler, _dir: Directionality, _ngZone?: NgZone | undefined, _platform?: Platform | undefined, _animationMode?: string | undefined);
128131
_alignInkBarToSelectedTab(): void;
129132
_checkPaginationEnabled(): void;
130133
_checkScrollingControls(): void;
@@ -171,7 +174,7 @@ export declare class MatTabLink extends _MatTabLinkMixinBase implements OnDestro
171174
rippleConfig: RippleConfig & RippleGlobalOptions;
172175
readonly rippleDisabled: boolean;
173176
constructor(_tabNavBar: MatTabNav, _elementRef: ElementRef, ngZone: NgZone, platform: Platform, globalRippleOptions: RippleGlobalOptions | null, tabIndex: string,
174-
_focusMonitor?: FocusMonitor | undefined);
177+
_focusMonitor?: FocusMonitor | undefined, animationMode?: string);
175178
ngOnDestroy(): void;
176179
}
177180

0 commit comments

Comments
 (0)