diff --git a/src/tabs/docs/readme.md b/src/tabs/docs/readme.md index d7681a95be..56b1547cb8 100644 --- a/src/tabs/docs/readme.md +++ b/src/tabs/docs/readme.md @@ -33,7 +33,7 @@ AngularJS version of the tabs directive. * `deselect()` $ - - 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. + 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. * `disable` $ diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index b020ef0345..81a71050b8 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -11,7 +11,8 @@ angular.module('ui.bootstrap.tabs', []) var previousSelected = ctrl.tabs[previousIndex]; if (previousSelected) { previousSelected.tab.onDeselect({ - $event: evt + $event: evt, + $selectedIndex: index }); if (evt && evt.isDefaultPrevented()) { return; diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index 9e89846bd6..cf965afa32 100644 --- a/src/tabs/test/tabs.spec.js +++ b/src/tabs/test/tabs.spec.js @@ -46,14 +46,14 @@ describe('tabs', function() { }; elm = $compile([ '', - ' ', + ' ', ' first content is {{first}}', ' ', - ' ', + ' ', ' Second Tab {{second}}', ' second content is {{second}}', ' ', - ' ', + ' ', ' Second Tab {{third}}', ' third content is {{third}}', ' ', @@ -118,12 +118,15 @@ describe('tabs', function() { titles().eq(1).find('> a').click(); expect(scope.deselectFirst).toHaveBeenCalled(); expect(scope.deselectFirst.calls.argsFor(0)[0].target).toBe(titles().eq(1).find('> a')[0]); + expect(scope.deselectFirst.calls.argsFor(0)[1]).toBe(1); titles().eq(0).find('> a').click(); expect(scope.deselectSecond).toHaveBeenCalled(); expect(scope.deselectSecond.calls.argsFor(0)[0].target).toBe(titles().eq(0).find('> a')[0]); + expect(scope.deselectSecond.calls.argsFor(0)[1]).toBe(0); titles().eq(1).find('> a').click(); expect(scope.deselectFirst.calls.count()).toBe(2); expect(scope.deselectFirst.calls.argsFor(1)[0].target).toBe(titles().eq(1).find('> a')[0]); + expect(scope.deselectFirst.calls.argsFor(1)[1]).toBe(1); }); it('should prevent tab deselection when $event.preventDefault() is called', function() {