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

Commit db06631

Browse files
committed
feat(tab): add select expressions
- Add support for event and tab being available in select/deselect callbacks
1 parent 54c51c4 commit db06631

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

Diff for: src/tabs/docs/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AngularJS version of the tabs directive.
2929

3030
* `deselect()`
3131
<small class="badge">$</small> -
32-
An optional expression called when tab is deactivated.
32+
An optional expression called when tab is deactivated. Supports $event and $tab in template for expression.
3333

3434
* `disable`
3535
<small class="badge">$</small>
@@ -45,7 +45,7 @@ AngularJS version of the tabs directive.
4545

4646
* `select()`
4747
<small class="badge">$</small> -
48-
An optional expression called when tab is activated.
48+
An optional expression called when tab is activated. Supports $event and $tab in template for expression.
4949

5050
* `template-url`
5151
_(Default: `uib/template/tabs/tab.html`)_ -

Diff for: src/tabs/tabs.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ angular.module('ui.bootstrap.tabs', [])
55
oldIndex;
66
ctrl.tabs = [];
77

8-
ctrl.select = function(index) {
8+
ctrl.select = function(index, evt) {
99
if (!destroyed) {
1010
var previousIndex = findTabIndex(oldIndex);
1111
var previousSelected = ctrl.tabs[previousIndex];
1212
if (previousSelected) {
13-
previousSelected.tab.onDeselect();
13+
previousSelected.tab.onDeselect({
14+
$event: evt,
15+
$tab: ctrl.tabs[previousIndex].tab
16+
});
1417
previousSelected.tab.active = false;
1518
}
1619

1720
var selected = ctrl.tabs[index];
1821
if (selected) {
19-
selected.tab.onSelect();
22+
selected.tab.onSelect({
23+
$event: evt,
24+
$tab: selected
25+
});
2026
selected.tab.active = true;
2127
ctrl.active = selected.index;
2228
oldIndex = selected.index;
@@ -132,7 +138,7 @@ angular.module('ui.bootstrap.tabs', [])
132138
});
133139
}
134140

135-
scope.select = function() {
141+
scope.select = function(evt) {
136142
if (!scope.disabled) {
137143
var index;
138144
for (var i = 0; i < tabsetCtrl.tabs.length; i++) {
@@ -142,7 +148,7 @@ angular.module('ui.bootstrap.tabs', [])
142148
}
143149
}
144150

145-
tabsetCtrl.select(index);
151+
tabsetCtrl.select(index, evt);
146152
}
147153
};
148154

Diff for: template/tabs/tab.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<li ng-class="{active: active, disabled: disabled}" class="uib-tab">
2-
<a href ng-click="select()" uib-tab-heading-transclude>{{heading}}</a>
2+
<a href ng-click="select($event)" uib-tab-heading-transclude>{{heading}}</a>
33
</li>

0 commit comments

Comments
 (0)