@@ -50,6 +50,12 @@ export interface MatTabGroupBaseHeader {
5050/** Possible positions for the tab header. */
5151export type MatTabHeaderPosition = 'above' | 'below' ;
5252
53+ /** Possible values for the animation duration of a tab group. */
54+ export type MatTabGroupAnimationDuration =
55+ | string
56+ | number
57+ | { body : string | number ; header : string | number } ;
58+
5359/** Boolean constant that determines whether the tab group supports the `backgroundColor` input */
5460const ENABLE_BACKGROUND_INPUT = true ;
5561
@@ -79,7 +85,8 @@ const ENABLE_BACKGROUND_INPUT = true;
7985 '[class.mat-mdc-tab-group-inverted-header]' : 'headerPosition === "below"' ,
8086 '[class.mat-mdc-tab-group-stretch-tabs]' : 'stretchTabs' ,
8187 '[attr.mat-align-tabs]' : 'alignTabs' ,
82- '[style.--mat-tab-animation-duration]' : 'animationDuration' ,
88+ '[style.--mat-tab-body-animation-duration]' : '_bodyAnimationDuration' ,
89+ '[style.--mat-tab-header-animation-duration]' : '_headerAnimationDuration' ,
8390 } ,
8491 imports : [
8592 MatTabHeader ,
@@ -100,6 +107,8 @@ export class MatTabGroup
100107 private _tabLabelSubscription = Subscription . EMPTY ;
101108 private _tabBodySubscription = Subscription . EMPTY ;
102109 private _diAnimationsDisabled = _animationsDisabled ( ) ;
110+ protected _bodyAnimationDuration ! : string ;
111+ protected _headerAnimationDuration ! : string ;
103112
104113 /**
105114 * All tabs inside the tab group. This includes tabs that belong to groups that are nested
@@ -170,14 +179,20 @@ export class MatTabGroup
170179
171180 /** Duration for the tab animation. Will be normalized to milliseconds if no units are set. */
172181 @Input ( )
173- get animationDuration ( ) : string {
182+ get animationDuration ( ) : MatTabGroupAnimationDuration {
174183 return this . _animationDuration ;
175184 }
176- set animationDuration ( value : string | number ) {
177- const stringValue = value + '' ;
178- this . _animationDuration = / ^ \d + $ / . test ( stringValue ) ? value + 'ms' : stringValue ;
185+ set animationDuration ( value : MatTabGroupAnimationDuration ) {
186+ this . _animationDuration = value ;
187+
188+ if ( value && typeof value === 'object' ) {
189+ this . _bodyAnimationDuration = normalizeDuration ( value . body ) ;
190+ this . _headerAnimationDuration = normalizeDuration ( value . header ) ;
191+ } else {
192+ this . _headerAnimationDuration = this . _bodyAnimationDuration = normalizeDuration ( value ) ;
193+ }
179194 }
180- private _animationDuration ! : string ;
195+ private _animationDuration ! : MatTabGroupAnimationDuration ;
181196
182197 /**
183198 * `tabindex` to be set on the inner element that wraps the tab content. Can be used for improved
@@ -577,11 +592,11 @@ export class MatTabGroup
577592 }
578593 }
579594
580- protected _animationsDisabled ( ) : boolean {
595+ protected _bodyAnimationsDisabled ( ) : boolean {
581596 return (
582597 this . _diAnimationsDisabled ||
583- this . animationDuration === '0' ||
584- this . animationDuration === '0ms'
598+ this . _bodyAnimationDuration === '0' ||
599+ this . _bodyAnimationDuration === '0ms'
585600 ) ;
586601 }
587602}
@@ -593,3 +608,9 @@ export class MatTabChangeEvent {
593608 /** Reference to the currently-selected tab. */
594609 tab ! : MatTab ;
595610}
611+
612+ /** Normalizes an animation duration value. */
613+ function normalizeDuration ( value : string | number ) : string {
614+ const stringValue = value + '' ;
615+ return / ^ \d + $ / . test ( stringValue ) ? value + 'ms' : stringValue ;
616+ }
0 commit comments