Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(tabs): reordering tabs should now work
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Messerle committed May 6, 2015
1 parent 48c7c44 commit 5bc3f23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/tabs/js/tabDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ function MdTab () {

scope.$watch('active', function (active) { if (active) ctrl.select(data.getIndex()); });
scope.$watch('disabled', function () { ctrl.refreshIndex(); });
scope.$watch(
function () {
var tabs = element.parent()[0].getElementsByTagName('md-tab');
return Array.prototype.indexOf.call(tabs, element[0]);
},
function (newIndex) {
data.index = newIndex;
ctrl.updateTabOrder();
});
scope.$on('$destroy', function () { ctrl.removeTab(data); });

function getLabel () {
Expand Down
14 changes: 13 additions & 1 deletion src/components/tabs/js/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
ctrl.offsetLeft = 0;
ctrl.hasContent = false;
ctrl.hasFocus = false;
ctrl.lastClick = false;
ctrl.lastClick = true;

ctrl.redirectFocus = redirectFocus;
ctrl.attachRipple = attachRipple;
Expand All @@ -36,6 +36,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
ctrl.refreshIndex = refreshIndex;
ctrl.incrementSelectedIndex = incrementSelectedIndex;
ctrl.updateInkBarStyles = updateInkBarStyles;
ctrl.updateTabOrder = $mdUtil.debounce(updateTabOrder, 100);

init();

Expand Down Expand Up @@ -90,6 +91,17 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
ctrl.lastClick = false;
}

function updateTabOrder () {
var selectedItem = ctrl.tabs[$scope.selectedIndex],
focusItem = ctrl.tabs[ctrl.focusIndex];
ctrl.tabs = ctrl.tabs.sort(function (a, b) {
return a.index - b.index;
});
$scope.selectedIndex = ctrl.tabs.indexOf(selectedItem);
ctrl.focusIndex = ctrl.tabs.indexOf(focusItem);
$timeout(updateInkBarStyles, 0, false);
}

function incrementSelectedIndex (inc, focus) {
var newIndex,
index = focus ? ctrl.focusIndex : $scope.selectedIndex;
Expand Down

0 comments on commit 5bc3f23

Please sign in to comment.