From d59083b65ea662f7680763cc0d15e6fbc650ddd5 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Fri, 30 Oct 2015 19:57:23 -0700 Subject: [PATCH] fix(tab): fix unexpected routing - Change anchor tag to `div` to prevent unexpected routing being triggered by the browser on generation of anchor tags with nested clickable controls BREAKING CHANGE: This causes the cursor style to be removed from the tab - implement CSS on the `.uib-tab > div` selector, or similar, accordingly Closes #4793 Fixes #3266 --- src/tabs/docs/demo.html | 6 ++++++ src/tabs/test/tabs.spec.js | 36 ++++++++++++++++++------------------ template/tabs/tab.html | 4 ++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/tabs/docs/demo.html b/src/tabs/docs/demo.html index 8a848d398f..4c744d34e7 100644 --- a/src/tabs/docs/demo.html +++ b/src/tabs/docs/demo.html @@ -1,3 +1,9 @@ + +

Select a tab by setting active binding to true:

diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index cbcd9acf54..6c4bb535d2 100644 --- a/src/tabs/test/tabs.spec.js +++ b/src/tabs/test/tabs.spec.js @@ -61,10 +61,10 @@ describe('tabs', function() { it('should create clickable titles', function() { var t = titles(); expect(t.length).toBe(2); - expect(t.find('a').eq(0).text()).toBe('First Tab 1'); + expect(t.find('> div').eq(0).text()).toBe('First Tab 1'); //It should put the uib-tab-heading element into the 'a' title - expect(t.find('a').eq(1).children().is('uib-tab-heading')).toBe(true); - expect(t.find('a').eq(1).children().html()).toBe('Second Tab 2'); + expect(t.find('> div').eq(1).children().is('uib-tab-heading')).toBe(true); + expect(t.find('> div').eq(1).children().html()).toBe('Second Tab 2'); }); it('should bind tabs content and set first tab active', function() { @@ -76,7 +76,7 @@ describe('tabs', function() { }); it('should change active on click', function() { - titles().eq(1).find('a').click(); + titles().eq(1).find('> div').click(); expect(contents().eq(1)).toHaveClass('active'); expect(titles().eq(0)).not.toHaveClass('active'); expect(titles().eq(1)).toHaveClass('active'); @@ -85,17 +85,17 @@ describe('tabs', function() { }); it('should call select callback on select', function() { - titles().eq(1).find('a').click(); + titles().eq(1).find('> div').click(); expect(scope.selectSecond).toHaveBeenCalled(); - titles().eq(0).find('a').click(); + titles().eq(0).find('> div').click(); expect(scope.selectFirst).toHaveBeenCalled(); }); it('should call deselect callback on deselect', function() { - titles().eq(1).find('a').click(); - titles().eq(0).find('a').click(); + titles().eq(1).find('> div').click(); + titles().eq(0).find('> div').click(); expect(scope.deselectSecond).toHaveBeenCalled(); - titles().eq(1).find('a').click(); + titles().eq(1).find('> div').click(); expect(scope.deselectFirst).toHaveBeenCalled(); }); }); @@ -181,13 +181,13 @@ describe('tabs', function() { execOrder = []; // Select second tab - titles().eq(1).find('a').click(); + titles().eq(1).find('> div').click(); expect(execOrder).toEqual([ 'deselect1', 'select2' ]); execOrder = []; // Select again first tab - titles().eq(0).find('a').click(); + titles().eq(0).find('> div').click(); expect(execOrder).toEqual([ 'deselect2', 'select1' ]); }); }); @@ -250,7 +250,7 @@ describe('tabs', function() { }); it('should switch active when clicking', function() { - titles().eq(3).find('a').click(); + titles().eq(3).find('> div').click(); expectTabActive(scope.tabs[3]); }); @@ -317,7 +317,7 @@ describe('tabs', function() { })); function heading() { - return elm.find('ul li a').children(); + return elm.find('ul li > div').children(); } it('should create a heading bound to myHtml', function() { @@ -379,7 +379,7 @@ describe('tabs', function() { it('should preserve correct ordering', function() { function titles() { - return elm.find('ul.nav-tabs li a'); + return elm.find('ul.nav-tabs li > div'); } scope.$apply(); expect(titles().length).toBe(9); @@ -522,7 +522,7 @@ describe('tabs', function() { expectContents(['Hello', 'content 1', 'content 2', 'content 3']); // Select last tab - titles().find('a').eq(3).click(); + titles().find('> div').eq(3).click(); expect(contents().eq(3)).toHaveClass('active'); expect(titles().eq(3)).toHaveClass('active'); @@ -536,7 +536,7 @@ describe('tabs', function() { expect(contents().eq(2)).toHaveClass('active'); // Select 2nd tab ("tab 1") - titles().find('a').eq(1).click(); + titles().find('> div').eq(1).click(); expect(titles().eq(1)).toHaveClass('active'); expect(contents().eq(1)).toHaveClass('active'); @@ -632,10 +632,10 @@ describe('tabs', function() { } it('should not switch active when clicking on title', function() { - titles().eq(2).find('a').click(); + titles().eq(2).find('> div').click(); expectTabActive(scope.tabs[2]); - titles().eq(3).find('a').click(); + titles().eq(3).find('> div').click(); expectTabActive(scope.tabs[2]); }); diff --git a/template/tabs/tab.html b/template/tabs/tab.html index 0d8a42ed6b..b7b83e5eff 100644 --- a/template/tabs/tab.html +++ b/template/tabs/tab.html @@ -1,3 +1,3 @@ -

  • - {{heading}} +
  • +
    {{heading}}