@@ -159,9 +159,9 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
159159 * a new selected tab should transition in (from the left or right).
160160 */
161161 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
163163 // 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 ) ;
165165
166166 // If there is a change in selected index, emit a change event. Should not trigger if
167167 // the selected index has not yet been initialized.
@@ -197,7 +197,7 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
197197 // Subscribe to changes in the amount of tabs, in order to be
198198 // able to re-render the content as new tabs are added or removed.
199199 this . _tabsSubscription = this . _tabs . changes . subscribe ( ( ) => {
200- const indexToSelect = this . _clampIndexToSelect ( ) ;
200+ const indexToSelect = this . _clampTabIndex ( this . _indexToSelect ) ;
201201
202202 // Maintain the previously-selected tab if a new tab is added or removed and there is no
203203 // explicit change that selects a different tab.
@@ -263,12 +263,12 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
263263 } ) ;
264264 }
265265
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 {
268268 // Note the `|| 0`, which ensures that values like NaN can't get through
269269 // and which would otherwise throw the component into an infinite loop
270270 // (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 ) ) ;
272272 }
273273
274274 /** Returns a unique id for each tab label element */
0 commit comments