Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 6d45f10

Browse files
author
Robert Messerle
committed
fix(tabs): programmatically changing tabs will now adjust pagination to show the selected tab
Also adjusts for window resize of pagination toggling. Closes #3139
1 parent 09694bc commit 6d45f10

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/components/tabs/js/tabsController.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
147147
ctrl.lastSelectedIndex = oldValue;
148148
ctrl.updateInkBarStyles();
149149
updateHeightFromContent();
150-
adjustOffset();
150+
adjustOffset(newValue);
151151
$scope.$broadcast('$mdTabsChanged');
152152
ctrl.tabs[oldValue] && ctrl.tabs[oldValue].scope.deselect();
153153
ctrl.tabs[newValue] && ctrl.tabs[newValue].scope.select();
@@ -384,7 +384,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
384384
function shouldPaginate () {
385385
if ($scope.noPagination || !loaded) return false;
386386
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; });
388388
return canvasWidth < 0;
389389
}
390390

@@ -432,6 +432,9 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
432432
function updatePagination () {
433433
ctrl.shouldPaginate = shouldPaginate();
434434
ctrl.shouldCenterTabs = shouldCenterTabs();
435+
$timeout(function () {
436+
adjustOffset($scope.selectedIndex);
437+
});
435438
}
436439

437440
/**
@@ -474,9 +477,10 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
474477
/**
475478
* Forces the pagination to move the focused tab into view.
476479
*/
477-
function adjustOffset () {
480+
function adjustOffset (index) {
478481
if (ctrl.shouldCenterTabs) return;
479-
var tab = elements.tabs[ctrl.focusIndex],
482+
if (index == null) index = ctrl.focusIndex;
483+
var tab = elements.tabs[index],
480484
left = tab.offsetLeft,
481485
right = tab.offsetWidth + left;
482486
ctrl.offsetLeft = Math.max(ctrl.offsetLeft, fixOffset(right - elements.canvas.clientWidth));

src/components/tabs/js/tabsDirective.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function MdTabs ($mdTheming, $mdUtil, $compile) {
162162
</md-pagination-wrapper>\
163163
<div class="md-visually-hidden md-dummy-wrapper">\
164164
<md-dummy-tab\
165+
class="md-tab"\
165166
tabindex="-1"\
166167
id="tab-item-{{tab.id}}"\
167168
role="tab"\

src/components/tabs/tabs.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ md-tabs {
6060
md-tabs-wrapper {
6161
border-width: 0 0 1px;
6262
border-style: solid;
63-
.md-tab {
64-
padding-bottom: 11px;
65-
}
6663
}
6764
&:not(.md-dynamic-height) {
6865
md-tabs-content-wrapper {

0 commit comments

Comments
 (0)