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

Commit 241fea8

Browse files
ksieburgwesleycho
authored andcommitted
feat(tabs): pass the selected index to onDeselect
- Add the index of the tab the user attempted to open to the onDeselect call Closes #5820 Closes #5821
1 parent f0e661c commit 241fea8

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/tabs/docs/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ AngularJS version of the tabs directive.
3333

3434
* `deselect()`
3535
<small class="badge">$</small> -
36-
An optional expression called when tab is deactivated. Supports $event in template for expression. You may call `$event.preventDefault()` in this event handler to prevent a tab change from occurring.
36+
An optional expression called when tab is deactivated. Supports `$event` and `$selectedIndex` in template for expression. You may call `$event.preventDefault()` in this event handler to prevent a tab change from occurring. The `$selectedIndex` can be used to determine which tab was attempted to be opened.
3737

3838
* `disable`
3939
<small class="badge">$</small>

src/tabs/tabs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ angular.module('ui.bootstrap.tabs', [])
1111
var previousSelected = ctrl.tabs[previousIndex];
1212
if (previousSelected) {
1313
previousSelected.tab.onDeselect({
14-
$event: evt
14+
$event: evt,
15+
$selectedIndex: index
1516
});
1617
if (evt && evt.isDefaultPrevented()) {
1718
return;

src/tabs/test/tabs.spec.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ describe('tabs', function() {
4646
};
4747
elm = $compile([
4848
'<uib-tabset class="hello" data-pizza="pepperoni" active="active">',
49-
' <uib-tab index="1" heading="First Tab {{first}}" classes="{{firstClass}}" select="selectFirst($event)" deselect="deselectFirst($event)">',
49+
' <uib-tab index="1" heading="First Tab {{first}}" classes="{{firstClass}}" select="selectFirst($event)" deselect="deselectFirst($event, $selectedIndex)">',
5050
' first content is {{first}}',
5151
' </uib-tab>',
52-
' <uib-tab index="2" classes="{{secondClass}}" select="selectSecond($event)" deselect="deselectSecond($event)">',
52+
' <uib-tab index="2" classes="{{secondClass}}" select="selectSecond($event)" deselect="deselectSecond($event, $selectedIndex)">',
5353
' <uib-tab-heading><b>Second</b> Tab {{second}}</uib-tab-heading>',
5454
' second content is {{second}}',
5555
' </uib-tab>',
56-
' <uib-tab index="3" classes="{{thirdClass}}" deselect="deselectThird($event)">',
56+
' <uib-tab index="3" classes="{{thirdClass}}" deselect="deselectThird($event, $selectedIndex)">',
5757
' <uib-tab-heading><b>Second</b> Tab {{third}}</uib-tab-heading>',
5858
' third content is {{third}}',
5959
' </uib-tab>',
@@ -118,12 +118,15 @@ describe('tabs', function() {
118118
titles().eq(1).find('> a').click();
119119
expect(scope.deselectFirst).toHaveBeenCalled();
120120
expect(scope.deselectFirst.calls.argsFor(0)[0].target).toBe(titles().eq(1).find('> a')[0]);
121+
expect(scope.deselectFirst.calls.argsFor(0)[1]).toBe(1);
121122
titles().eq(0).find('> a').click();
122123
expect(scope.deselectSecond).toHaveBeenCalled();
123124
expect(scope.deselectSecond.calls.argsFor(0)[0].target).toBe(titles().eq(0).find('> a')[0]);
125+
expect(scope.deselectSecond.calls.argsFor(0)[1]).toBe(0);
124126
titles().eq(1).find('> a').click();
125127
expect(scope.deselectFirst.calls.count()).toBe(2);
126128
expect(scope.deselectFirst.calls.argsFor(1)[0].target).toBe(titles().eq(1).find('> a')[0]);
129+
expect(scope.deselectFirst.calls.argsFor(1)[1]).toBe(1);
127130
});
128131

129132
it('should prevent tab deselection when $event.preventDefault() is called', function() {

0 commit comments

Comments
 (0)