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

Commit

Permalink
fix(tabs): tabs will no longer assume that all tabs have no content i…
Browse files Browse the repository at this point in the history
…f the first one doesn't

Closes #2398
  • Loading branch information
Robert Messerle committed Apr 20, 2015
1 parent 0e2ccd2 commit 1b789fe
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/components/tabs/js/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ctrl.lastSelectedIndex = null;
ctrl.focusIndex = 0;
ctrl.offsetLeft = 0;
ctrl.hasContent = true;
ctrl.hasContent = false;
ctrl.hasFocus = false;
ctrl.lastClick = false;

Expand Down Expand Up @@ -46,11 +46,16 @@
$scope.$watch('selectedIndex', handleSelectedIndexChange);
$scope.$watch('$mdTabsCtrl.focusIndex', handleFocusIndexChange);
$scope.$watch('$mdTabsCtrl.offsetLeft', handleOffsetChange);
$scope.$watch('$mdTabsCtrl.hasContent', handleHasContent);
angular.element($window).on('resize', function () { $scope.$apply(handleWindowResize); });
$timeout(updateInkBarStyles, 0, false);
$timeout(updateHeightFromContent, 0, false);
}

function handleHasContent (hasContent) {
$element[hasContent ? 'removeClass' : 'hasClass']('md-no-tab-content');
}

function getElements () {
var elements = {};

Expand Down Expand Up @@ -147,19 +152,24 @@
id: $mdUtil.nextUid()
},
tab = angular.extend(proto, tabData);
if (!tabData.template) {
ctrl.hasContent = false;
$element.addClass('md-no-tab-content');
}
if (angular.isDefined(index)) {
ctrl.tabs.splice(index, 0, tab);
} else {
ctrl.tabs.push(tab);
}
processQueue();
updateHasContent();
return tab;
}

function updateHasContent () {
var hasContent = false;
angular.forEach(ctrl.tabs, function (tab) {
if (tab.template) hasContent = true;
});
ctrl.hasContent = hasContent;
}

function removeTab (tabData) {
ctrl.tabs.splice(tabData.getIndex(), 1);
refreshIndex();
Expand Down Expand Up @@ -211,7 +221,7 @@
if (!$scope.dynamicHeight) return $element.css('height', '');
if (!ctrl.tabs.length) return queue.push(updateHeightFromContent);
var tabContent = elements.contents[$scope.selectedIndex],
contentHeight = tabContent.offsetHeight,
contentHeight = tabContent ? tabContent.offsetHeight : 0,
tabsHeight = elements.wrapper.offsetHeight,
newHeight = contentHeight + tabsHeight,
currentHeight = $element.prop('clientHeight');
Expand Down

1 comment on commit 1b789fe

@thomasphan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

Looks like handleHasContent() should 'addClass' instead of 'hasClass'.

Thanks!

Please sign in to comment.