@@ -76,8 +76,8 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
76
76
/** Subject that emits when the component has been destroyed. */
77
77
private readonly _onDestroy = new Subject < void > ( ) ;
78
78
79
- _activeLinkChanged : boolean ;
80
- _activeLinkElement : ElementRef ;
79
+ private _activeLinkChanged : boolean ;
80
+ private _activeLinkElement : ElementRef | null ;
81
81
82
82
@ViewChild ( MatInkBar ) _inkBar : MatInkBar ;
83
83
@@ -118,21 +118,22 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
118
118
super ( elementRef ) ;
119
119
}
120
120
121
- /** Notifies the component that the active link has been changed. */
121
+ /**
122
+ * Notifies the component that the active link has been changed.
123
+ * @deletion -target 7.0.0 `element` parameter to be removed.
124
+ */
122
125
updateActiveLink ( element : ElementRef ) {
123
- this . _activeLinkChanged = this . _activeLinkElement != element ;
124
- this . _activeLinkElement = element ;
125
-
126
- if ( this . _activeLinkChanged ) {
127
- this . _changeDetectorRef . markForCheck ( ) ;
128
- }
126
+ // Note: keeping the `element` for backwards-compat, but isn't being used for anything.
127
+ this . _activeLinkChanged = ! ! element ;
128
+ this . _changeDetectorRef . markForCheck ( ) ;
129
129
}
130
130
131
131
ngAfterContentInit ( ) : void {
132
132
this . _ngZone . runOutsideAngular ( ( ) => {
133
133
const dirChange = this . _dir ? this . _dir . change : observableOf ( null ) ;
134
134
135
- return merge ( dirChange , this . _viewportRuler . change ( 10 ) ) . pipe ( takeUntil ( this . _onDestroy ) )
135
+ return merge ( dirChange , this . _viewportRuler . change ( 10 ) )
136
+ . pipe ( takeUntil ( this . _onDestroy ) )
136
137
. subscribe ( ( ) => this . _alignInkBar ( ) ) ;
137
138
} ) ;
138
139
@@ -142,6 +143,9 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
142
143
/** Checks if the active link has been changed and, if so, will update the ink bar. */
143
144
ngAfterContentChecked ( ) : void {
144
145
if ( this . _activeLinkChanged ) {
146
+ const activeTab = this . _tabLinks . find ( tab => tab . active ) ;
147
+
148
+ this . _activeLinkElement = activeTab ? activeTab . _elementRef : null ;
145
149
this . _alignInkBar ( ) ;
146
150
this . _activeLinkChanged = false ;
147
151
}
@@ -155,7 +159,10 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
155
159
/** Aligns the ink bar to the active link. */
156
160
_alignInkBar ( ) : void {
157
161
if ( this . _activeLinkElement ) {
162
+ this . _inkBar . show ( ) ;
158
163
this . _inkBar . alignToElement ( this . _activeLinkElement . nativeElement ) ;
164
+ } else {
165
+ this . _inkBar . hide ( ) ;
159
166
}
160
167
}
161
168
@@ -202,8 +209,8 @@ export class MatTabLink extends _MatTabLinkMixinBase
202
209
@Input ( )
203
210
get active ( ) : boolean { return this . _isActive ; }
204
211
set active ( value : boolean ) {
205
- this . _isActive = value ;
206
- if ( value ) {
212
+ if ( value !== this . _isActive ) {
213
+ this . _isActive = value ;
207
214
this . _tabNavBar . updateActiveLink ( this . _elementRef ) ;
208
215
}
209
216
}
@@ -223,7 +230,7 @@ export class MatTabLink extends _MatTabLinkMixinBase
223
230
}
224
231
225
232
constructor ( private _tabNavBar : MatTabNav ,
226
- private _elementRef : ElementRef ,
233
+ public _elementRef : ElementRef ,
227
234
ngZone : NgZone ,
228
235
platform : Platform ,
229
236
@Optional ( ) @Inject ( MAT_RIPPLE_GLOBAL_OPTIONS ) globalOptions : RippleGlobalOptions ,
0 commit comments