From ba1f741dff4b6eb3c624f7020e663e562129cc79 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Sat, 27 Jul 2013 14:23:18 -0400 Subject: [PATCH] fix(tabs): if tab is active at start, always select it Closes #648, #676 --- src/tabs/tabs.js | 6 +++--- src/tabs/test/tabsSpec.js | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index c8c4b37322..125c7c3a89 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -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); } }; @@ -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; } @@ -211,8 +212,7 @@ function($parse, $http, $templateCache, $compile) { if (active) { tabsetCtrl.select(scope); scope.onSelect(); - } - else { + } else { scope.onDeselect(); } }); diff --git a/src/tabs/test/tabsSpec.js b/src/tabs/test/tabsSpec.js index 93c0e51cd4..e8a9822fef 100644 --- a/src/tabs/test/tabsSpec.js +++ b/src/tabs/test/tabsSpec.js @@ -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([ '', @@ -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'); @@ -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() {