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

Commit

Permalink
feat(tabs): it should not select first not active tab as selected
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-f authored and wesleycho committed Mar 16, 2015
1 parent a5a82d9 commit 91b5fb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ angular.module('ui.bootstrap.tabs', [])
tabs.push(tab);
// we can't run the select function on the first tab
// since that would select it twice
if (tabs.length === 1) {
if (tabs.length === 1 && tab.active !== false) {
tab.active = true;
} else if (tab.active) {
ctrl.select(tab);
}
else {
tab.active = false;
}
};

ctrl.removeTab = function removeTab(tab) {
Expand Down
14 changes: 13 additions & 1 deletion src/tabs/test/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,13 @@ describe('tabs', function() {

describe('tabset controller', function() {
function mockTab(isActive) {
var _isActive;
if (isActive || isActive === false) {
_isActive = isActive;
}

return {
active: !!isActive,
active: _isActive,
onSelect : angular.noop,
onDeselect : angular.noop
};
Expand Down Expand Up @@ -459,6 +464,13 @@ describe('tabs', function() {
expect(tab1.active).toBe(true);
});

it('should not select first active === false tab as selected', function() {
var tab = mockTab(false);

ctrl.addTab(tab);
expect(tab.active).toBe(false);
});

it('should select a tab added that\'s already active', function() {
var tab1 = mockTab(), tab2 = mockTab(true);
ctrl.addTab(tab1);
Expand Down

0 comments on commit 91b5fb6

Please sign in to comment.