Skip to content

Commit

Permalink
fix(tabs): better handling of animationDuration without units (#14778)
Browse files Browse the repository at this point in the history
Based off of the discussions on #13428. Handles values passed to `animationDuration` that don't have units, rather than allowing them to continue through to  the `BrowserAnimationsModule` and to throw an error.
  • Loading branch information
crisbeto authored and vivian-hu-zz committed Jan 14, 2019
1 parent d83059b commit 6f49813
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/lib/tabs/tab-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ describe('nested MatTabGroup with enabled animations', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [MatTabsModule, BrowserAnimationsModule],
declarations: [NestedTabs]
declarations: [NestedTabs, TabsWithCustomAnimationDuration]
});

TestBed.compileComponents();
Expand All @@ -635,6 +635,14 @@ describe('nested MatTabGroup with enabled animations', () => {
tick();
}).not.toThrow();
}));

it('should not throw when setting an animationDuration without units', fakeAsync(() => {
expect(() => {
let fixture = TestBed.createComponent(TabsWithCustomAnimationDuration);
fixture.detectChanges();
tick();
}).not.toThrow();
}));
});


Expand Down Expand Up @@ -861,3 +869,14 @@ class TabGroupWithAriaInputs {
})
class TabGroupWithIsActiveBinding {
}


@Component({
template: `
<mat-tab-group animationDuration="500">
<mat-tab label="One">Tab one content</mat-tab>
<mat-tab label="Two">Tab two content</mat-tab>
</mat-tab-group>
`,
})
class TabsWithCustomAnimationDuration {}
9 changes: 7 additions & 2 deletions src/lib/tabs/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
/** Position of the tab header. */
@Input() headerPosition: MatTabHeaderPosition = 'above';

/** Duration for the tab animation. Must be a valid CSS value (e.g. 600ms). */
@Input() animationDuration: string;
/** Duration for the tab animation. Will be normalized to milliseconds if no units are set. */
@Input()
get animationDuration(): string { return this._animationDuration; }
set animationDuration(value: string) {
this._animationDuration = /^\d+$/.test(value) ? value + 'ms' : value;
}
private _animationDuration: string;

/** Background color of the tab group. */
@Input()
Expand Down

0 comments on commit 6f49813

Please sign in to comment.