From e675ea12983611a53ad9af5a92a63162fb1bf3f1 Mon Sep 17 00:00:00 2001 From: Karl Sieburg Date: Tue, 19 Apr 2016 10:40:09 -0400 Subject: [PATCH] feat(tabs): pass the selected tab index to onDeselect - Add the index of the tab the user attempted to open to the onDeselect call, which allows the user to directed to the selected tab after some work is performed. - Closes #5820 --- src/tabs/tabs.js | 3 ++- src/tabs/test/tabs.spec.js | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index b020ef0345..211fa6c994 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, + selectedTabIndex: index }); if (evt && evt.isDefaultPrevented()) { return; diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index 9e89846bd6..66f5501b92 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() {