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

Commit

Permalink
feat(tabs): added onDeselect callback, used similarly as onSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
vli-say authored and pkozlowski-opensource committed Jul 25, 2013
1 parent 682ae66 commit fe47c9b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -202,6 +203,9 @@ function($parse, $http, $templateCache, $compile) {
tabsetCtrl.select(scope);
scope.onSelect();
}
else {
scope.onDeselect();
}
});

scope.disabled = false;
Expand All @@ -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;
};
}
Expand Down
20 changes: 15 additions & 5 deletions src/tabs/test/tabsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('tabs', function() {
}
}


describe('basics', function() {

beforeEach(inject(function($compile, $rootScope) {
Expand All @@ -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([
'<div>',
' <tabset class="hello" data-pizza="pepperoni">',
' <tab heading="First Tab {{first}}" active="actives.one" select="selectFirst()">',
' <tab heading="First Tab {{first}}" active="actives.one" select="selectFirst()" deselect="deselectFirst()">',
' first content is {{first}}',
' </tab>',
' <tab active="actives.two" select="selectSecond()">',
' <tab active="actives.two" select="selectSecond()" deselect="deselectSecond()">',
' <tab-heading><b>Second</b> Tab {{second}}</tab-heading>',
' second content is {{second}}',
' </tab>',
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fe47c9b

Please sign in to comment.