diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index d5b9ed12ae..b0444ba4d7 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -177,8 +177,9 @@ function($parse, $http, $templateCache, $compile) { transclude: true, scope: { heading: '@', - onSelect: '&select' //This callback is called in contentHeadingTransclude + onSelect: '&select', //This callback is called in contentHeadingTransclude //once it inserts the tab's content into the dom + onDeselect: '&deselect' }, controller: function() { //Empty controller so other directives can require being 'under' a tab @@ -202,6 +203,9 @@ function($parse, $http, $templateCache, $compile) { tabsetCtrl.select(scope); scope.onSelect(); } + else { + scope.onDeselect(); + } }); scope.disabled = false; @@ -227,7 +231,7 @@ function($parse, $http, $templateCache, $compile) { //We need to transclude later, once the content container is ready. - //when this link happens, we're inside a tab heading. + //when this link happens, we're inside a tab heading. scope.$transcludeFn = transclude; }; } diff --git a/src/tabs/test/tabsSpec.js b/src/tabs/test/tabsSpec.js index d0f0d9d842..c5310e05f7 100644 --- a/src/tabs/test/tabsSpec.js +++ b/src/tabs/test/tabsSpec.js @@ -24,7 +24,7 @@ describe('tabs', function() { } } - + describe('basics', function() { beforeEach(inject(function($compile, $rootScope) { @@ -33,14 +33,16 @@ describe('tabs', function() { scope.second = '2'; scope.actives = {}; scope.selectFirst = jasmine.createSpy(); - scope.selectSecond = jasmine.createSpy(); + scope.selectSecond = jasmine.createSpy(); + scope.deselectFirst = jasmine.createSpy(); + scope.deselectSecond = jasmine.createSpy(); elm = $compile([ '
', ' ', - ' ', + ' ', ' first content is {{first}}', ' ', - ' ', + ' ', ' Second Tab {{second}}', ' second content is {{second}}', ' ', @@ -90,6 +92,14 @@ describe('tabs', function() { expect(scope.selectFirst).toHaveBeenCalled(); }); + it('should call deselect callback on deselect', function() { + titles().eq(1).find('a').click(); + titles().eq(0).find('a').click(); + expect(scope.deselectSecond).toHaveBeenCalled(); + titles().eq(1).find('a').click(); + expect(scope.deselectFirst).toHaveBeenCalled(); + }); + }); describe('ng-repeat', function() { @@ -208,7 +218,7 @@ describe('tabs', function() { expect(heading().eq(2).text()).toBe('2'); expect(heading().eq(3).text()).toBe('3'); }); - + }); //Tests that http://git.io/lG6I9Q is fixed