@@ -147,7 +147,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
147
147
ctrl . lastSelectedIndex = oldValue ;
148
148
ctrl . updateInkBarStyles ( ) ;
149
149
updateHeightFromContent ( ) ;
150
- adjustOffset ( ) ;
150
+ adjustOffset ( newValue ) ;
151
151
$scope . $broadcast ( '$mdTabsChanged' ) ;
152
152
ctrl . tabs [ oldValue ] && ctrl . tabs [ oldValue ] . scope . deselect ( ) ;
153
153
ctrl . tabs [ newValue ] && ctrl . tabs [ newValue ] . scope . select ( ) ;
@@ -384,7 +384,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
384
384
function shouldPaginate ( ) {
385
385
if ( $scope . noPagination || ! loaded ) return false ;
386
386
var canvasWidth = $element . prop ( 'clientWidth' ) ;
387
- angular . forEach ( elements . tabs , function ( tab ) { canvasWidth -= tab . offsetWidth ; } ) ;
387
+ angular . forEach ( elements . dummies , function ( tab ) { canvasWidth -= tab . offsetWidth ; } ) ;
388
388
return canvasWidth < 0 ;
389
389
}
390
390
@@ -432,6 +432,9 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
432
432
function updatePagination ( ) {
433
433
ctrl . shouldPaginate = shouldPaginate ( ) ;
434
434
ctrl . shouldCenterTabs = shouldCenterTabs ( ) ;
435
+ $timeout ( function ( ) {
436
+ adjustOffset ( $scope . selectedIndex ) ;
437
+ } ) ;
435
438
}
436
439
437
440
/**
@@ -474,9 +477,10 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
474
477
/**
475
478
* Forces the pagination to move the focused tab into view.
476
479
*/
477
- function adjustOffset ( ) {
480
+ function adjustOffset ( index ) {
478
481
if ( ctrl . shouldCenterTabs ) return ;
479
- var tab = elements . tabs [ ctrl . focusIndex ] ,
482
+ if ( index == null ) index = ctrl . focusIndex ;
483
+ var tab = elements . tabs [ index ] ,
480
484
left = tab . offsetLeft ,
481
485
right = tab . offsetWidth + left ;
482
486
ctrl . offsetLeft = Math . max ( ctrl . offsetLeft , fixOffset ( right - elements . canvas . clientWidth ) ) ;
0 commit comments