Skip to content
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

fix(tabs): better handling of animationDuration without units #14778

Merged
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
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