Skip to content

Commit

Permalink
fix(tabs): disable all animations when using NoopAnimationsModule (#1…
Browse files Browse the repository at this point in the history
…1395)

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.
  • Loading branch information
crisbeto authored and mmalerba committed Jun 13, 2019
1 parent 86c626a commit 27a08cc
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/material/tabs/_tabs-common.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../core/style/variables';
@import '../core/style/noop-animation';
@import '../../cdk/a11y/a11y';

$mat-tab-bar-height: 48px !default;
Expand Down Expand Up @@ -61,6 +62,7 @@ $mat-tab-animation-duration: 500ms !default;
@mixin ink-bar {
$height: 2px;

@include _noop-animation();
position: absolute;
bottom: 0;
height: $height;
Expand Down
7 changes: 5 additions & 2 deletions src/material/tabs/ink-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

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


/**
Expand Down Expand Up @@ -46,13 +47,15 @@ export function _MAT_INK_BAR_POSITIONER_FACTORY(): _MatInkBarPositioner {
selector: 'mat-ink-bar',
host: {
'class': 'mat-ink-bar',
'[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`,
},
})
export class MatInkBar {
constructor(
private _elementRef: ElementRef<HTMLElement>,
private _ngZone: NgZone,
@Inject(_MAT_INK_BAR_POSITIONER) private _inkBarPositioner: _MatInkBarPositioner) { }
@Inject(_MAT_INK_BAR_POSITIONER) private _inkBarPositioner: _MatInkBarPositioner,
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) { }

/**
* Calculates the styles from the provided element in order to align the ink-bar to that element.
Expand Down
5 changes: 4 additions & 1 deletion src/material/tabs/tab-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
</div>
</mat-tab-header>

<div class="mat-tab-body-wrapper" #tabBodyWrapper>
<div
class="mat-tab-body-wrapper"
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
#tabBodyWrapper>
<mat-tab-body role="tabpanel"
*ngFor="let tab of _tabs; let i = index"
[id]="_getTabContentId(i)"
Expand Down
2 changes: 2 additions & 0 deletions src/material/tabs/tab-group.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../core/style/variables';
@import '../core/style/layout-common';
@import '../core/style/noop-animation';
@import './tabs-common';

.mat-tab-group {
Expand Down Expand Up @@ -37,6 +38,7 @@

// The bottom section of the view; contains the tab bodies
.mat-tab-body-wrapper {
@include _noop-animation();
position: relative;
overflow: hidden;
display: flex;
Expand Down
8 changes: 5 additions & 3 deletions src/material/tabs/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import {
QueryList,
ViewChild,
ViewEncapsulation,
InjectionToken,
Inject,
Optional,
Inject,
InjectionToken,
} from '@angular/core';
import {
CanColor,
Expand All @@ -38,6 +38,7 @@ import {
import {merge, Subscription} from 'rxjs';
import {MatTab} from './tab';
import {MatTabHeader} from './tab-header';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';


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

constructor(elementRef: ElementRef,
private _changeDetectorRef: ChangeDetectorRef,
@Inject(MAT_TABS_CONFIG) @Optional() defaultConfig?: MatTabsConfig) {
@Inject(MAT_TABS_CONFIG) @Optional() defaultConfig?: MatTabsConfig,
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
super(elementRef);
this._groupId = nextId++;
this.animationDuration = defaultConfig && defaultConfig.animationDuration ?
Expand Down
7 changes: 6 additions & 1 deletion src/material/tabs/tab-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

<div class="mat-tab-label-container" #tabListContainer
(keydown)="_handleKeydown($event)">
<div class="mat-tab-list" #tabList role="tablist" (cdkObserveContent)="_onContentChanges()">
<div
class="mat-tab-list"
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
#tabList
role="tablist"
(cdkObserveContent)="_onContentChanges()">
<div class="mat-tab-labels">
<ng-content></ng-content>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/material/tabs/tab-header.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import '../core/style/variables';
@import '../core/style/layout-common';
@import '../core/style/vendor-prefixes';
@import '../core/style/noop-animation';
@import './tabs-common';

.mat-tab-header {
Expand Down Expand Up @@ -79,6 +80,7 @@
}

.mat-tab-list {
@include _noop-animation();
flex-grow: 1;
position: relative;
transition: transform 500ms cubic-bezier(0.35, 0, 0.25, 1);
Expand Down
6 changes: 5 additions & 1 deletion src/material/tabs/tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
EventEmitter,
Input,
NgZone,
Inject,
OnDestroy,
Optional,
Output,
Expand All @@ -36,6 +37,7 @@ import {MatInkBar} from './ink-bar';
import {MatTabLabelWrapper} from './tab-label-wrapper';
import {FocusKeyManager} from '@angular/cdk/a11y';
import {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';


/** Config used to bind passive event listeners */
Expand Down Expand Up @@ -165,7 +167,9 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
private _viewportRuler: ViewportRuler,
@Optional() private _dir: Directionality,
private _ngZone: NgZone,
private _platform: Platform) {
private _platform: Platform,
// @breaking-change 9.0.0 `_animationMode` parameter to be made required.
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
super();

// Bind the `mouseleave` event on the outside since it doesn't change anything in the view.
Expand Down
8 changes: 7 additions & 1 deletion src/material/tabs/tab-nav-bar/tab-nav-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {merge, of as observableOf, Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {MatInkBar} from '../ink-bar';
import {FocusMonitor} from '@angular/cdk/a11y';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';


// Boilerplate for applying mixins to MatTabNav.
Expand Down Expand Up @@ -222,7 +223,8 @@ export class MatTabLink extends _MatTabLinkMixinBase
private _tabNavBar: MatTabNav, public _elementRef: ElementRef, ngZone: NgZone,
platform: Platform,
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalRippleOptions: RippleGlobalOptions|null,
@Attribute('tabindex') tabIndex: string, private _focusMonitor: FocusMonitor) {
@Attribute('tabindex') tabIndex: string, private _focusMonitor: FocusMonitor,
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
super();

this._tabLinkRipple = new RippleRenderer(this, ngZone, _elementRef, platform);
Expand All @@ -231,6 +233,10 @@ export class MatTabLink extends _MatTabLinkMixinBase

this.tabIndex = parseInt(tabIndex) || 0;
_focusMonitor.monitor(_elementRef);

if (animationMode === 'NoopAnimations') {
this.rippleConfig.animation = {enterDuration: 0, exitDuration: 0};
}
}

ngOnDestroy() {
Expand Down
11 changes: 7 additions & 4 deletions tools/public_api_guard/material/tabs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface _MatInkBarPositioner {
export declare const MAT_TABS_CONFIG: InjectionToken<{}>;

export declare class MatInkBar {
constructor(_elementRef: ElementRef<HTMLElement>, _ngZone: NgZone, _inkBarPositioner: _MatInkBarPositioner);
_animationMode?: string | undefined;
constructor(_elementRef: ElementRef<HTMLElement>, _ngZone: NgZone, _inkBarPositioner: _MatInkBarPositioner, _animationMode?: string | undefined);
alignToElement(element: HTMLElement): void;
hide(): void;
show(): void;
Expand Down Expand Up @@ -75,6 +76,7 @@ export declare class MatTabContent {
}

export declare class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentInit, AfterContentChecked, OnDestroy, CanColor, CanDisableRipple {
_animationMode?: string | undefined;
_tabBodyWrapper: ElementRef;
_tabHeader: MatTabHeader;
_tabs: QueryList<MatTab>;
Expand All @@ -87,7 +89,7 @@ export declare class MatTabGroup extends _MatTabGroupMixinBase implements AfterC
selectedIndex: number | null;
readonly selectedIndexChange: EventEmitter<number>;
readonly selectedTabChange: EventEmitter<MatTabChangeEvent>;
constructor(elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, defaultConfig?: MatTabsConfig);
constructor(elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, defaultConfig?: MatTabsConfig, _animationMode?: string | undefined);
_focusChanged(index: number): void;
_getTabContentId(i: number): string;
_getTabIndex(tab: MatTab, idx: number): number | null;
Expand All @@ -102,6 +104,7 @@ export declare class MatTabGroup extends _MatTabGroupMixinBase implements AfterC
}

export declare class MatTabHeader extends _MatTabHeaderMixinBase implements AfterContentChecked, AfterContentInit, AfterViewInit, OnDestroy, CanDisableRipple {
_animationMode?: string | undefined;
_disableScrollAfter: boolean;
_disableScrollBefore: boolean;
_inkBar: MatInkBar;
Expand All @@ -116,7 +119,7 @@ export declare class MatTabHeader extends _MatTabHeaderMixinBase implements Afte
scrollDistance: number;
readonly selectFocusedIndex: EventEmitter<number>;
selectedIndex: number;
constructor(_elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, _viewportRuler: ViewportRuler, _dir: Directionality, _ngZone: NgZone, _platform: Platform);
constructor(_elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, _viewportRuler: ViewportRuler, _dir: Directionality, _ngZone: NgZone, _platform: Platform, _animationMode?: string | undefined);
_alignInkBarToSelectedTab(): void;
_checkPaginationEnabled(): void;
_checkScrollingControls(): void;
Expand Down Expand Up @@ -162,7 +165,7 @@ export declare class MatTabLink extends _MatTabLinkMixinBase implements OnDestro
active: boolean;
rippleConfig: RippleConfig & RippleGlobalOptions;
readonly rippleDisabled: boolean;
constructor(_tabNavBar: MatTabNav, _elementRef: ElementRef, ngZone: NgZone, platform: Platform, globalRippleOptions: RippleGlobalOptions | null, tabIndex: string, _focusMonitor: FocusMonitor);
constructor(_tabNavBar: MatTabNav, _elementRef: ElementRef, ngZone: NgZone, platform: Platform, globalRippleOptions: RippleGlobalOptions | null, tabIndex: string, _focusMonitor: FocusMonitor, animationMode?: string);
ngOnDestroy(): void;
}

Expand Down

0 comments on commit 27a08cc

Please sign in to comment.