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

Commit

Permalink
fix(tabs): id's should no longer cause issues when used within tab la…
Browse files Browse the repository at this point in the history
…bels or contents

Closes #2326
  • Loading branch information
Robert Messerle committed Apr 15, 2015
1 parent 659aff6 commit ea185ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
18 changes: 5 additions & 13 deletions src/components/tabs/js/tabDirective.js
Expand Up @@ -82,28 +82,20 @@
scope.deselect = scope.deselect || angular.noop;
scope.select = scope.select || angular.noop;


scope.$watch('active', function (active) { if (active) ctrl.select(data.getIndex()); });
scope.$watch('disabled', function () { ctrl.refreshIndex(); });
scope.$watch(getTemplate, function (template, oldTemplate) {
if (template === oldTemplate) return;
data.template = template;
ctrl.updateInkBarStyles();
});
scope.$watch(getLabel, function (label, oldLabel) {
if (label === oldLabel) return;
data.label = label;
ctrl.updateInkBarStyles();
});
scope.$on('$destroy', function () { ctrl.removeTab(data); });

function getLabel () {
return attr.label || (element.find('md-tab-label')[0] || element[0]).innerHTML;
}

function getTemplate () {
var content = element.find('md-tab-template');
return content.length ? content.html() : attr.label ? element.html() : null;
var content = element.find('md-tab-template'),
template = content.length ? content.html() : attr.label ? element.html() : null;
if (content.length) content.remove();
else element.empty();
return template;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/tabs/js/tabsController.js
Expand Up @@ -128,7 +128,7 @@
function handleWindowResize () {
ctrl.lastSelectedIndex = $scope.selectedIndex;
updateInkBarStyles();
ctrl.offsetLeft = shouldPaginate() ? fixOffset(ctrl.offsetLeft) : 0;
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
}

function insertTab (tabData, index) {
Expand Down Expand Up @@ -291,7 +291,7 @@
}

function fixOffset (value) {
if (!elements.tabs.length) return;
if (!elements.tabs.length || !shouldPaginate()) return 0;
var lastTab = elements.tabs[elements.tabs.length - 1],
totalWidth = lastTab.offsetLeft + lastTab.offsetWidth;
value = Math.max(0, value);
Expand Down

0 comments on commit ea185ea

Please sign in to comment.