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

Commit fe47c9b

Browse files
vli-saypkozlowski-opensource
authored andcommitted
feat(tabs): added onDeselect callback, used similarly as onSelect
1 parent 682ae66 commit fe47c9b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/tabs/tabs.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ function($parse, $http, $templateCache, $compile) {
177177
transclude: true,
178178
scope: {
179179
heading: '@',
180-
onSelect: '&select' //This callback is called in contentHeadingTransclude
180+
onSelect: '&select', //This callback is called in contentHeadingTransclude
181181
//once it inserts the tab's content into the dom
182+
onDeselect: '&deselect'
182183
},
183184
controller: function() {
184185
//Empty controller so other directives can require being 'under' a tab
@@ -202,6 +203,9 @@ function($parse, $http, $templateCache, $compile) {
202203
tabsetCtrl.select(scope);
203204
scope.onSelect();
204205
}
206+
else {
207+
scope.onDeselect();
208+
}
205209
});
206210

207211
scope.disabled = false;
@@ -227,7 +231,7 @@ function($parse, $http, $templateCache, $compile) {
227231

228232

229233
//We need to transclude later, once the content container is ready.
230-
//when this link happens, we're inside a tab heading.
234+
//when this link happens, we're inside a tab heading.
231235
scope.$transcludeFn = transclude;
232236
};
233237
}

src/tabs/test/tabsSpec.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('tabs', function() {
2424
}
2525
}
2626

27-
27+
2828
describe('basics', function() {
2929

3030
beforeEach(inject(function($compile, $rootScope) {
@@ -33,14 +33,16 @@ describe('tabs', function() {
3333
scope.second = '2';
3434
scope.actives = {};
3535
scope.selectFirst = jasmine.createSpy();
36-
scope.selectSecond = jasmine.createSpy();
36+
scope.selectSecond = jasmine.createSpy();
37+
scope.deselectFirst = jasmine.createSpy();
38+
scope.deselectSecond = jasmine.createSpy();
3739
elm = $compile([
3840
'<div>',
3941
' <tabset class="hello" data-pizza="pepperoni">',
40-
' <tab heading="First Tab {{first}}" active="actives.one" select="selectFirst()">',
42+
' <tab heading="First Tab {{first}}" active="actives.one" select="selectFirst()" deselect="deselectFirst()">',
4143
' first content is {{first}}',
4244
' </tab>',
43-
' <tab active="actives.two" select="selectSecond()">',
45+
' <tab active="actives.two" select="selectSecond()" deselect="deselectSecond()">',
4446
' <tab-heading><b>Second</b> Tab {{second}}</tab-heading>',
4547
' second content is {{second}}',
4648
' </tab>',
@@ -90,6 +92,14 @@ describe('tabs', function() {
9092
expect(scope.selectFirst).toHaveBeenCalled();
9193
});
9294

95+
it('should call deselect callback on deselect', function() {
96+
titles().eq(1).find('a').click();
97+
titles().eq(0).find('a').click();
98+
expect(scope.deselectSecond).toHaveBeenCalled();
99+
titles().eq(1).find('a').click();
100+
expect(scope.deselectFirst).toHaveBeenCalled();
101+
});
102+
93103
});
94104

95105
describe('ng-repeat', function() {
@@ -208,7 +218,7 @@ describe('tabs', function() {
208218
expect(heading().eq(2).text()).toBe('2');
209219
expect(heading().eq(3).text()).toBe('3');
210220
});
211-
221+
212222
});
213223

214224
//Tests that http://git.io/lG6I9Q is fixed

0 commit comments

Comments
 (0)