Skip to content

fix(tabs): animation running after initialization #12549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/lib/tabs/tab-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,33 @@ describe('MatTabBody', () => {
describe('when initialized as center', () => {
let fixture: ComponentFixture<SimpleTabBodyApp>;

it('should be center position if origin is unchanged', () => {
fixture = TestBed.createComponent(SimpleTabBodyApp);
fixture.componentInstance.position = 0;
fixture.detectChanges();

expect(fixture.componentInstance.tabBody._position).toBe('center');
});

it('should be center position if origin is explicitly set to null', () => {
fixture = TestBed.createComponent(SimpleTabBodyApp);
fixture.componentInstance.position = 0;

// It can happen that the `origin` is explicitly set to null through the Angular input
// binding. This test should ensure that the body does properly such origin value.
// The `MatTab` class sets the origin by default to null. See related issue: #12455
fixture.componentInstance.origin = null;
fixture.detectChanges();

expect(fixture.componentInstance.tabBody._position).toBe('center');
});

describe('in LTR direction', () => {

beforeEach(() => {
dir = 'ltr';
fixture = TestBed.createComponent(SimpleTabBodyApp);
});

it('should be center position without origin', () => {
fixture.componentInstance.position = 0;
fixture.detectChanges();

expect(fixture.componentInstance.tabBody._position).toBe('center');
});

it('should be left-origin-center position with negative or zero origin', () => {
fixture.componentInstance.position = 0;
fixture.componentInstance.origin = 0;
Expand Down Expand Up @@ -176,7 +190,7 @@ describe('MatTabBody', () => {
class SimpleTabBodyApp implements AfterContentInit {
content: TemplatePortal;
position: number;
origin: number;
origin: number | null;

@ViewChild(MatTabBody) tabBody: MatTabBody;
@ViewChild(TemplateRef) template: TemplateRef<any>;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tabs/tab-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class MatTabBody implements OnInit, OnDestroy {
* special position states that transition the tab from the left or right before centering.
*/
ngOnInit() {
if (this._position == 'center' && this.origin !== undefined) {
if (this._position == 'center' && this.origin != null) {
this._position = this._computePositionFromOrigin();
}
}
Expand Down