@@ -159,9 +159,9 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
159
159
* a new selected tab should transition in (from the left or right).
160
160
*/
161
161
ngAfterContentChecked ( ) {
162
- // Clamp the `indexToSelect` not immediately in the setter because it can happen that
162
+ // Don't clamp the `indexToSelect` immediately in the setter because it can happen that
163
163
// the amount of tabs changes before the actual change detection runs.
164
- const indexToSelect = this . _indexToSelect = this . _clampIndexToSelect ( ) ;
164
+ const indexToSelect = this . _indexToSelect = this . _clampTabIndex ( this . _indexToSelect ) ;
165
165
166
166
// If there is a change in selected index, emit a change event. Should not trigger if
167
167
// the selected index has not yet been initialized.
@@ -197,7 +197,7 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
197
197
// Subscribe to changes in the amount of tabs, in order to be
198
198
// able to re-render the content as new tabs are added or removed.
199
199
this . _tabsSubscription = this . _tabs . changes . subscribe ( ( ) => {
200
- const indexToSelect = this . _clampIndexToSelect ( ) ;
200
+ const indexToSelect = this . _clampTabIndex ( this . _indexToSelect ) ;
201
201
202
202
// Maintain the previously-selected tab if a new tab is added or removed and there is no
203
203
// explicit change that selects a different tab.
@@ -263,12 +263,12 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
263
263
} ) ;
264
264
}
265
265
266
- /** Clamps the indexToSelect to the bounds of 0 and the tabs length. */
267
- private _clampIndexToSelect ( ) : number {
266
+ /** Clamps the given index to the bounds of 0 and the tabs length. */
267
+ private _clampTabIndex ( index : number | null ) : number {
268
268
// Note the `|| 0`, which ensures that values like NaN can't get through
269
269
// and which would otherwise throw the component into an infinite loop
270
270
// (since Math.max(NaN, 0) === NaN).
271
- return Math . min ( this . _tabs . length - 1 , Math . max ( this . _indexToSelect || 0 , 0 ) ) ;
271
+ return Math . min ( this . _tabs . length - 1 , Math . max ( index || 0 , 0 ) ) ;
272
272
}
273
273
274
274
/** Returns a unique id for each tab label element */
0 commit comments