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

Commit ba1f741

Browse files
committed
fix(tabs): if tab is active at start, always select it
Closes #648, #676
1 parent a51c309 commit ba1f741

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/tabs/tabs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function TabsetCtrl($scope, $element) {
3030

3131
ctrl.addTab = function addTab(tab) {
3232
tabs.push(tab);
33-
if (tabs.length == 1 || tab.active) {
33+
if (tabs.length === 1 || tab.active) {
3434
ctrl.select(tab);
3535
}
3636
};
@@ -202,6 +202,7 @@ function($parse, $http, $templateCache, $compile) {
202202
scope.$parent.$watch(getActive, function updateActive(value) {
203203
scope.active = !!value;
204204
});
205+
scope.active = getActive(scope.$parent);
205206
} else {
206207
setActive = getActive = angular.noop;
207208
}
@@ -211,8 +212,7 @@ function($parse, $http, $templateCache, $compile) {
211212
if (active) {
212213
tabsetCtrl.select(scope);
213214
scope.onSelect();
214-
}
215-
else {
215+
} else {
216216
scope.onDeselect();
217217
}
218218
});

src/tabs/test/tabsSpec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ describe('tabs', function() {
107107
beforeEach(inject(function($compile, $rootScope) {
108108
scope = $rootScope.$new();
109109

110-
function makeTab() {
110+
function makeTab(active) {
111111
return {
112-
active: false,
112+
active: !!active,
113113
select: jasmine.createSpy()
114114
};
115115
}
116116
scope.tabs = [
117-
makeTab(), makeTab(), makeTab(), makeTab()
117+
makeTab(), makeTab(), makeTab(true), makeTab()
118118
];
119119
elm = $compile([
120120
'<tabset>',
@@ -140,7 +140,7 @@ describe('tabs', function() {
140140
if (activeTab === tab) {
141141
expect(tab.active).toBe(true);
142142
//It should only call select ONCE for each select
143-
expect(tab.select.callCount).toBe(1);
143+
expect(tab.select).toHaveBeenCalled();
144144
expect(_titles.eq(i)).toHaveClass('active');
145145
expect(contents().eq(i).text().trim()).toBe('content ' + i);
146146
expect(contents().eq(i)).toHaveClass('active');
@@ -151,9 +151,9 @@ describe('tabs', function() {
151151
});
152152
}
153153

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

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

0 commit comments

Comments
 (0)