Skip to content

Commit fbfd032

Browse files
crisbetokara
authored andcommitted
chore(tabs): revert workaround for angular < 2.3 (#4076)
1 parent fe7570a commit fbfd032

File tree

3 files changed

+3
-45
lines changed

3 files changed

+3
-45
lines changed

src/lib/tabs/tab-body.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="mat-tab-body-content" #content
2-
[@translateTab]="_canBeAnimated ? _position : null"
2+
[@translateTab]="_position"
33
(@translateTab.start)="_onTranslateTabStarted($event)"
44
(@translateTab.done)="_onTranslateTabComplete($event)">
55
<ng-template cdkPortalHost></ng-template>

src/lib/tabs/tab-body.spec.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,6 @@ describe('MdTabBody', () => {
170170
}));
171171
});
172172

173-
it('should toggle the canBeAnimated flag', () => {
174-
let fixture: ComponentFixture<SimpleTabBodyApp>;
175-
let tabBody: MdTabBody;
176-
177-
fixture = TestBed.createComponent(SimpleTabBodyApp);
178-
tabBody = fixture.componentInstance.mdTabBody;
179-
180-
expect(tabBody._canBeAnimated).toBe(false);
181-
182-
fixture.detectChanges();
183-
184-
expect(tabBody._canBeAnimated).toBe(true);
185-
});
186173
});
187174

188175

src/lib/tabs/tab-body.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import {
77
OnInit,
88
ElementRef,
99
Optional,
10-
ChangeDetectorRef,
1110
AfterViewChecked,
12-
AfterContentChecked,
1311
} from '@angular/core';
1412
import {
1513
trigger,
@@ -75,7 +73,7 @@ export type MdTabBodyOriginState = 'left' | 'right';
7573
])
7674
]
7775
})
78-
export class MdTabBody implements OnInit, AfterViewChecked, AfterContentChecked {
76+
export class MdTabBody implements OnInit, AfterViewChecked {
7977
/** The portal host inside of this container into which the tab body content will be loaded. */
8078
@ViewChild(PortalHostDirective) _portalHost: PortalHostDirective;
8179

@@ -102,9 +100,6 @@ export class MdTabBody implements OnInit, AfterViewChecked, AfterContentChecked
102100
}
103101
}
104102

105-
/** Whether the element is allowed to be animated. */
106-
_canBeAnimated: boolean = false;
107-
108103
/** The origin position from which this tab should appear when it is centered into view. */
109104
_origin: MdTabBodyOriginState;
110105

@@ -120,10 +115,7 @@ export class MdTabBody implements OnInit, AfterViewChecked, AfterContentChecked
120115
}
121116
}
122117

123-
constructor(
124-
@Optional() private _dir: Dir,
125-
private _elementRef: ElementRef,
126-
private _changeDetectorRef: ChangeDetectorRef) { }
118+
constructor(@Optional() private _dir: Dir, private _elementRef: ElementRef) { }
127119

128120
/**
129121
* After initialized, check if the content is centered and has an origin. If so, set the
@@ -145,27 +137,6 @@ export class MdTabBody implements OnInit, AfterViewChecked, AfterContentChecked
145137
}
146138
}
147139

148-
/**
149-
* After the content has been checked, determines whether the element should be allowed to
150-
* animate. This has to be limited, because under a specific set of circumstances (see #2151),
151-
* the animations can be triggered too early, which either crashes Chrome by putting it into an
152-
* infinite loop (with Angular < 2.3.0) or throws an error because the element doesn't have a
153-
* computed style (with Angular > 2.3.0). This can alternatively be determined by checking the
154-
* transform: canBeAnimated = getComputedStyle(element) !== '', however document.contains should
155-
* be faster since it doesn't cause a reflow.
156-
*/
157-
ngAfterContentChecked() {
158-
// TODO: This can safely be removed after we stop supporting Angular < 2.4.2. The fix landed via
159-
// https://github.com/angular/angular/commit/21030e9a1cf30e8101399d8535ed72d847a23ba6
160-
if (!this._canBeAnimated) {
161-
this._canBeAnimated = document.body.contains(this._elementRef.nativeElement);
162-
163-
if (this._canBeAnimated) {
164-
this._changeDetectorRef.markForCheck();
165-
}
166-
}
167-
}
168-
169140
_onTranslateTabStarted(e: AnimationEvent) {
170141
if (this._isCenterPosition(e.toState)) {
171142
this.onCentering.emit(this._elementRef.nativeElement.clientHeight);

0 commit comments

Comments
 (0)