8
8
9
9
import { Directive , ElementRef , Inject , InjectionToken , NgZone } from '@angular/core' ;
10
10
11
-
12
11
/**
13
12
* Interface for a a MatInkBar positioner method, defining the positioning and width of the ink
14
13
* bar in a set of tabs.
15
14
*/
16
15
// tslint:disable-next-line class-name Using leading underscore to denote internal interface.
17
16
export interface _MatInkBarPositioner {
18
- ( element : HTMLElement ) : { left : string , width : string } ;
17
+ ( element : HTMLElement ) : { left : number , width : number } ;
19
18
}
20
19
21
20
/** Injection token for the MatInkBar's Positioner. */
@@ -31,8 +30,8 @@ export const _MAT_INK_BAR_POSITIONER =
31
30
*/
32
31
export function _MAT_INK_BAR_POSITIONER_FACTORY ( ) : _MatInkBarPositioner {
33
32
const method = ( element : HTMLElement ) => ( {
34
- left : element ? ( element . offsetLeft || 0 ) + 'px' : '0' ,
35
- width : element ? ( element . offsetWidth || 0 ) + 'px' : '0' ,
33
+ left : element ? ( element . offsetLeft || 0 ) : 0 ,
34
+ width : element ? ( element . offsetWidth || 0 ) : 0 ,
36
35
} ) ;
37
36
38
37
return method ;
@@ -50,7 +49,7 @@ export function _MAT_INK_BAR_POSITIONER_FACTORY(): _MatInkBarPositioner {
50
49
} )
51
50
export class MatInkBar {
52
51
constructor (
53
- private _elementRef : ElementRef ,
52
+ private _elementRef : ElementRef < HTMLElement > ,
54
53
private _ngZone : NgZone ,
55
54
@Inject ( _MAT_INK_BAR_POSITIONER ) private _inkBarPositioner : _MatInkBarPositioner ) { }
56
55
@@ -87,9 +86,14 @@ export class MatInkBar {
87
86
*/
88
87
private _setStyles ( element : HTMLElement ) {
89
88
const positions = this . _inkBarPositioner ( element ) ;
90
- const inkBar : HTMLElement = this . _elementRef . nativeElement ;
89
+ const inkBar = this . _elementRef . nativeElement ;
90
+
91
+ // We want to prevent the ink bar from animating on the initial load.
92
+ // Enable animations only if the ink bar has been translated before.
93
+ if ( inkBar . style . transform ) {
94
+ inkBar . classList . add ( 'mat-ink-bar-animations-enabled' ) ;
95
+ }
91
96
92
- inkBar . style . left = positions . left ;
93
- inkBar . style . width = positions . width ;
97
+ inkBar . style . transform = `translateX(${ positions . left } px) scaleX(${ positions . width } )` ;
94
98
}
95
99
}
0 commit comments