From a20ad74402b559cc30f9274a7c84b6f77c8cdbfd Mon Sep 17 00:00:00 2001 From: crisbeto Date: Thu, 27 Apr 2017 20:25:58 +0200 Subject: [PATCH] fix(tabs): animation error with nested tab groups Fixes an animation error that gets thrown when nesting tab groups. It appears to be due to the animation not having a defined "from" style when going from `void` to something else. Fixes #4277. --- src/lib/tabs/tab-body.ts | 1 + src/lib/tabs/tab-group.spec.ts | 41 +++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/lib/tabs/tab-body.ts b/src/lib/tabs/tab-body.ts index 78daac792432..4a34f03ce789 100644 --- a/src/lib/tabs/tab-body.ts +++ b/src/lib/tabs/tab-body.ts @@ -55,6 +55,7 @@ export type MdTabBodyOriginState = 'left' | 'right'; }, animations: [ trigger('translateTab', [ + state('void', style({transform: 'translate3d(0, 0, 0)'})), state('left', style({transform: 'translate3d(-100%, 0, 0)'})), state('left-origin-center', style({transform: 'translate3d(0, 0, 0)'})), state('right-origin-center', style({transform: 'translate3d(0, 0, 0)'})), diff --git a/src/lib/tabs/tab-group.spec.ts b/src/lib/tabs/tab-group.spec.ts index eb9c443f6ffd..396f794b1d1f 100644 --- a/src/lib/tabs/tab-group.spec.ts +++ b/src/lib/tabs/tab-group.spec.ts @@ -3,7 +3,7 @@ import { } from '@angular/core/testing'; import {MdTabGroup, MdTabsModule, MdTabHeaderPosition} from './index'; import {Component, ViewChild} from '@angular/core'; -import {NoopAnimationsModule} from '@angular/platform-browser/animations'; +import {NoopAnimationsModule, BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {By} from '@angular/platform-browser'; import {Observable} from 'rxjs/Observable'; import {MdTab} from './tab'; @@ -290,6 +290,26 @@ describe('MdTabGroup', () => { } }); + +describe('nested MdTabGroup with enabled animations', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [MdTabsModule.forRoot(), BrowserAnimationsModule], + declarations: [NestedTabs] + }); + + TestBed.compileComponents(); + })); + + it('should not throw when creating a component with nested tab groups', async(() => { + expect(() => { + let fixture = TestBed.createComponent(NestedTabs); + fixture.detectChanges(); + }).not.toThrow(); + })); +}); + + @Component({ template: ` + Tab one content + + Tab two content + + Inner content one + Inner content two + + + + `, +}) +class NestedTabs {} +