File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -622,7 +622,7 @@ describe('nested MatTabGroup with enabled animations', () => {
622
622
beforeEach ( fakeAsync ( ( ) => {
623
623
TestBed . configureTestingModule ( {
624
624
imports : [ MatTabsModule , BrowserAnimationsModule ] ,
625
- declarations : [ NestedTabs ]
625
+ declarations : [ NestedTabs , TabsWithCustomAnimationDuration ]
626
626
} ) ;
627
627
628
628
TestBed . compileComponents ( ) ;
@@ -635,6 +635,14 @@ describe('nested MatTabGroup with enabled animations', () => {
635
635
tick ( ) ;
636
636
} ) . not . toThrow ( ) ;
637
637
} ) ) ;
638
+
639
+ it ( 'should not throw when setting an animationDuration without units' , fakeAsync ( ( ) => {
640
+ expect ( ( ) => {
641
+ let fixture = TestBed . createComponent ( TabsWithCustomAnimationDuration ) ;
642
+ fixture . detectChanges ( ) ;
643
+ tick ( ) ;
644
+ } ) . not . toThrow ( ) ;
645
+ } ) ) ;
638
646
} ) ;
639
647
640
648
@@ -861,3 +869,14 @@ class TabGroupWithAriaInputs {
861
869
} )
862
870
class TabGroupWithIsActiveBinding {
863
871
}
872
+
873
+
874
+ @Component ( {
875
+ template : `
876
+ <mat-tab-group animationDuration="500">
877
+ <mat-tab label="One">Tab one content</mat-tab>
878
+ <mat-tab label="Two">Tab two content</mat-tab>
879
+ </mat-tab-group>
880
+ ` ,
881
+ } )
882
+ class TabsWithCustomAnimationDuration { }
Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ import {MatTabHeader} from './tab-header';
43
43
/** Used to generate unique ID's for each tab component */
44
44
let nextId = 0 ;
45
45
46
+ /** Regex used to check whether a value has CSS units. */
47
+ const cssUnitPattern = / ( [ A - Z a - z % ] + ) $ / ;
48
+
46
49
/** A simple change event emitted on focus or selection changes. */
47
50
export class MatTabChangeEvent {
48
51
/** Index of the currently-selected tab. */
@@ -129,8 +132,14 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
129
132
/** Position of the tab header. */
130
133
@Input ( ) headerPosition : MatTabHeaderPosition = 'above' ;
131
134
132
- /** Duration for the tab animation. Must be a valid CSS value (e.g. 600ms). */
133
- @Input ( ) animationDuration : string ;
135
+ /** Duration for the tab animation. Will be normalized to milliseconds if no units are set. */
136
+ @Input ( )
137
+ get animationDuration ( ) : string { return this . _animationDuration ; }
138
+ set animationDuration ( value : string ) {
139
+ this . _animationDuration = ( typeof value === 'number' || ! cssUnitPattern . test ( value ) ) ?
140
+ value + 'ms' : value ;
141
+ }
142
+ private _animationDuration : string ;
134
143
135
144
/** Background color of the tab group. */
136
145
@Input ( )
You can’t perform that action at this time.
0 commit comments