From 19e07c8594b6e2f3797a22940e8fa14bdf22f5d9 Mon Sep 17 00:00:00 2001 From: Tom France Date: Mon, 18 Aug 2014 13:57:11 +0100 Subject: [PATCH 1/2] if tabset is being destroyed, don't 'select' tabs --- src/tabs/tabs.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index e1b5ee8485..f3a903f2db 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -37,14 +37,19 @@ angular.module('ui.bootstrap.tabs', []) ctrl.removeTab = function removeTab(tab) { var index = tabs.indexOf(tab); - //Select a new tab if the tab to be removed is selected - if (tab.active && tabs.length > 1) { + //Select a new tab if the tab to be removed is selected and not destroying + if (tab.active && tabs.length > 1 && !destroyed) { //If this is the last tab, select the previous tab. else, the next tab. var newActiveIndex = index == tabs.length - 1 ? index - 1 : index + 1; ctrl.select(tabs[newActiveIndex]); } tabs.splice(index, 1); }; + + var destroyed; + $scope.$on('$destroy', function() { + destroyed = true; + }); }]) /** From bcdaee3b2793e360557af58fb81dd26d05827fa0 Mon Sep 17 00:00:00 2001 From: Coridyn Fitzgerald-Hood Date: Tue, 30 Sep 2014 15:58:21 +1000 Subject: [PATCH 2/2] test(tabs): don't select tabs when being destroyed --- src/tabs/test/tabs.spec.js | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index bf5e2c671c..622182a19a 100644 --- a/src/tabs/test/tabs.spec.js +++ b/src/tabs/test/tabs.spec.js @@ -513,6 +513,45 @@ describe('tabs', function() { expect(titles().eq(1)).toHaveClass('active'); expect(contents().eq(1)).toHaveClass('active'); })); + + it('should not select tabs when being destroyed', inject(function($controller, $compile, $rootScope){ + var selectList = [], + deselectList = [], + getTab = function(active){ + return { + active: active, + select : function(){ + selectList.push('select'); + }, + deselect : function(){ + deselectList.push('deselect'); + } + }; + }; + + scope = $rootScope.$new(); + scope.tabs = [ + getTab(true), + getTab(false) + ]; + elm = $compile([ + '', + ' ', + ' heading {{index}}', + ' content {{$index}}', + ' ', + '' + ].join('\n'))(scope); + scope.$apply(); + + // The first tab is selected the during the initial $digest. + expect(selectList.length).toEqual(1); + + // Destroy the tabs - we should not trigger selection/deselection any more. + scope.$destroy(); + expect(selectList.length).toEqual(1); + expect(deselectList.length).toEqual(0); + })); }); describe('disabled', function() {