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

Commit

Permalink
fix(tabs): if tab is active at start, always select it
Browse files Browse the repository at this point in the history
Closes #648, #676
  • Loading branch information
ajoslin committed Jul 27, 2013
1 parent a51c309 commit ba1f741
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function TabsetCtrl($scope, $element) {

ctrl.addTab = function addTab(tab) {
tabs.push(tab);
if (tabs.length == 1 || tab.active) {
if (tabs.length === 1 || tab.active) {
ctrl.select(tab);
}
};
Expand Down Expand Up @@ -202,6 +202,7 @@ function($parse, $http, $templateCache, $compile) {
scope.$parent.$watch(getActive, function updateActive(value) {
scope.active = !!value;
});
scope.active = getActive(scope.$parent);
} else {
setActive = getActive = angular.noop;
}
Expand All @@ -211,8 +212,7 @@ function($parse, $http, $templateCache, $compile) {
if (active) {
tabsetCtrl.select(scope);
scope.onSelect();
}
else {
} else {
scope.onDeselect();
}
});
Expand Down
12 changes: 6 additions & 6 deletions src/tabs/test/tabsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ describe('tabs', function() {
beforeEach(inject(function($compile, $rootScope) {
scope = $rootScope.$new();

function makeTab() {
function makeTab(active) {
return {
active: false,
active: !!active,
select: jasmine.createSpy()
};
}
scope.tabs = [
makeTab(), makeTab(), makeTab(), makeTab()
makeTab(), makeTab(), makeTab(true), makeTab()
];
elm = $compile([
'<tabset>',
Expand All @@ -140,7 +140,7 @@ describe('tabs', function() {
if (activeTab === tab) {
expect(tab.active).toBe(true);
//It should only call select ONCE for each select
expect(tab.select.callCount).toBe(1);
expect(tab.select).toHaveBeenCalled();
expect(_titles.eq(i)).toHaveClass('active');
expect(contents().eq(i).text().trim()).toBe('content ' + i);
expect(contents().eq(i)).toHaveClass('active');
Expand All @@ -151,9 +151,9 @@ describe('tabs', function() {
});
}

it('should make tab titles with first content and first active', function() {
it('should make tab titles and set active tab active', function() {
expect(titles().length).toBe(scope.tabs.length);
expectTabActive(scope.tabs[0]);
expectTabActive(scope.tabs[2]);
});

it('should switch active when clicking', function() {
Expand Down

0 comments on commit ba1f741

Please sign in to comment.