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

Commit

Permalink
fix(tabs): resolves issue with nested tabs
Browse files Browse the repository at this point in the history
Fixes #4989. Closes #5719.
  • Loading branch information
Robert Messerle authored and ThomasBurleson committed Nov 25, 2015
1 parent 7d8bc2d commit 20ba8a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/components/tabs/js/tabDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ function MdTab () {
require: '^?mdTabs',
terminal: true,
compile: function (element, attr) {
var label = element.find('md-tab-label'),
body = element.find('md-tab-body');
var label = firstChild(element, 'md-tab-label'),
body = firstChild(element, 'md-tab-body');

if (label.length == 0) {
label = angular.element('<md-tab-label></md-tab-label>');
Expand Down Expand Up @@ -88,8 +88,8 @@ function MdTab () {
function postLink (scope, element, attr, ctrl) {
if (!ctrl) return;
var index = ctrl.getTabElementIndex(element),
body = element.find('md-tab-body').eq(0).remove(),
label = element.find('md-tab-label').eq(0).remove(),
body = firstChild(element, 'md-tab-body').remove(),
label = firstChild(element, 'md-tab-label').remove(),
data = ctrl.insertTab({
scope: scope,
parent: scope.$parent,
Expand All @@ -114,6 +114,14 @@ function MdTab () {
}
);
scope.$on('$destroy', function () { ctrl.removeTab(data); });
}

function firstChild (element, tagName) {
var children = element[0].children;
for (var i = 0, len = children.length; i < len; i++) {
var child = children[i];
if (child.tagName === tagName.toUpperCase()) return angular.element(child);
}
return angular.element();
}
}
21 changes: 21 additions & 0 deletions src/components/tabs/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,25 @@ describe('<md-tabs>', function () {
expect(element.find('md-tabs-content-wrapper').hasClass('ng-hide')).toBe(true);
}));
});

describe('nested tabs', function () {
it('should properly nest tabs', inject(function () {
var template = '' +
'<md-tabs>' +
' <md-tab label="one">' +
' <md-tabs>' +
' <md-tab><md-tab-label>a</md-tab-label></md-tab>' +
' <md-tab><md-tab-label>b</md-tab-label></md-tab>' +
' <md-tab><md-tab-label>c</md-tab-label></md-tab>' +
' </md-tabs>' +
' </md-tab>' +
' <md-tab label="two">two</md-tab>' +
'</md-tabs>';
var element = setup(template);
// first item should be 'one'
expect(element.find('md-tab-item').eq(0).text()).toBe('one');
// first item in nested tabs should be 'a'
expect(element.find('md-tabs').find('md-tab-item').eq(0).text()).toBe('a');
}));
});
});

0 comments on commit 20ba8a5

Please sign in to comment.