Skip to content

Commit 2798084

Browse files
devversionjosephperrott
authored andcommitted
fix(tabs): animation running after initialization (#12549)
1 parent 6c91902 commit 2798084

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,33 @@ describe('MatTabBody', () => {
3333
describe('when initialized as center', () => {
3434
let fixture: ComponentFixture<SimpleTabBodyApp>;
3535

36+
it('should be center position if origin is unchanged', () => {
37+
fixture = TestBed.createComponent(SimpleTabBodyApp);
38+
fixture.componentInstance.position = 0;
39+
fixture.detectChanges();
40+
41+
expect(fixture.componentInstance.tabBody._position).toBe('center');
42+
});
43+
44+
it('should be center position if origin is explicitly set to null', () => {
45+
fixture = TestBed.createComponent(SimpleTabBodyApp);
46+
fixture.componentInstance.position = 0;
47+
48+
// It can happen that the `origin` is explicitly set to null through the Angular input
49+
// binding. This test should ensure that the body does properly such origin value.
50+
// The `MatTab` class sets the origin by default to null. See related issue: #12455
51+
fixture.componentInstance.origin = null;
52+
fixture.detectChanges();
53+
54+
expect(fixture.componentInstance.tabBody._position).toBe('center');
55+
});
56+
3657
describe('in LTR direction', () => {
58+
3759
beforeEach(() => {
3860
dir = 'ltr';
3961
fixture = TestBed.createComponent(SimpleTabBodyApp);
4062
});
41-
42-
it('should be center position without origin', () => {
43-
fixture.componentInstance.position = 0;
44-
fixture.detectChanges();
45-
46-
expect(fixture.componentInstance.tabBody._position).toBe('center');
47-
});
48-
4963
it('should be left-origin-center position with negative or zero origin', () => {
5064
fixture.componentInstance.position = 0;
5165
fixture.componentInstance.origin = 0;
@@ -176,7 +190,7 @@ describe('MatTabBody', () => {
176190
class SimpleTabBodyApp implements AfterContentInit {
177191
content: TemplatePortal;
178192
position: number;
179-
origin: number;
193+
origin: number | null;
180194

181195
@ViewChild(MatTabBody) tabBody: MatTabBody;
182196
@ViewChild(TemplateRef) template: TemplateRef<any>;

src/lib/tabs/tab-body.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class MatTabBody implements OnInit, OnDestroy {
173173
* special position states that transition the tab from the left or right before centering.
174174
*/
175175
ngOnInit() {
176-
if (this._position == 'center' && this.origin !== undefined) {
176+
if (this._position == 'center' && this.origin != null) {
177177
this._position = this._computePositionFromOrigin();
178178
}
179179
}

0 commit comments

Comments
 (0)