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

Commit d59083b

Browse files
committed
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
1 parent df211bd commit d59083b

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

src/tabs/docs/demo.html

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<style>
2+
.uib-tab > div {
3+
cursor: pointer;
4+
}
5+
</style>
6+
17
<div ng-controller="TabsDemoCtrl">
28
<p>Select a tab by setting active binding to true:</p>
39
<p>

src/tabs/test/tabs.spec.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ describe('tabs', function() {
6161
it('should create clickable titles', function() {
6262
var t = titles();
6363
expect(t.length).toBe(2);
64-
expect(t.find('a').eq(0).text()).toBe('First Tab 1');
64+
expect(t.find('> div').eq(0).text()).toBe('First Tab 1');
6565
//It should put the uib-tab-heading element into the 'a' title
66-
expect(t.find('a').eq(1).children().is('uib-tab-heading')).toBe(true);
67-
expect(t.find('a').eq(1).children().html()).toBe('<b>Second</b> Tab 2');
66+
expect(t.find('> div').eq(1).children().is('uib-tab-heading')).toBe(true);
67+
expect(t.find('> div').eq(1).children().html()).toBe('<b>Second</b> Tab 2');
6868
});
6969

7070
it('should bind tabs content and set first tab active', function() {
@@ -76,7 +76,7 @@ describe('tabs', function() {
7676
});
7777

7878
it('should change active on click', function() {
79-
titles().eq(1).find('a').click();
79+
titles().eq(1).find('> div').click();
8080
expect(contents().eq(1)).toHaveClass('active');
8181
expect(titles().eq(0)).not.toHaveClass('active');
8282
expect(titles().eq(1)).toHaveClass('active');
@@ -85,17 +85,17 @@ describe('tabs', function() {
8585
});
8686

8787
it('should call select callback on select', function() {
88-
titles().eq(1).find('a').click();
88+
titles().eq(1).find('> div').click();
8989
expect(scope.selectSecond).toHaveBeenCalled();
90-
titles().eq(0).find('a').click();
90+
titles().eq(0).find('> div').click();
9191
expect(scope.selectFirst).toHaveBeenCalled();
9292
});
9393

9494
it('should call deselect callback on deselect', function() {
95-
titles().eq(1).find('a').click();
96-
titles().eq(0).find('a').click();
95+
titles().eq(1).find('> div').click();
96+
titles().eq(0).find('> div').click();
9797
expect(scope.deselectSecond).toHaveBeenCalled();
98-
titles().eq(1).find('a').click();
98+
titles().eq(1).find('> div').click();
9999
expect(scope.deselectFirst).toHaveBeenCalled();
100100
});
101101
});
@@ -181,13 +181,13 @@ describe('tabs', function() {
181181
execOrder = [];
182182

183183
// Select second tab
184-
titles().eq(1).find('a').click();
184+
titles().eq(1).find('> div').click();
185185
expect(execOrder).toEqual([ 'deselect1', 'select2' ]);
186186

187187
execOrder = [];
188188

189189
// Select again first tab
190-
titles().eq(0).find('a').click();
190+
titles().eq(0).find('> div').click();
191191
expect(execOrder).toEqual([ 'deselect2', 'select1' ]);
192192
});
193193
});
@@ -250,7 +250,7 @@ describe('tabs', function() {
250250
});
251251

252252
it('should switch active when clicking', function() {
253-
titles().eq(3).find('a').click();
253+
titles().eq(3).find('> div').click();
254254
expectTabActive(scope.tabs[3]);
255255
});
256256

@@ -317,7 +317,7 @@ describe('tabs', function() {
317317
}));
318318

319319
function heading() {
320-
return elm.find('ul li a').children();
320+
return elm.find('ul li > div').children();
321321
}
322322

323323
it('should create a heading bound to myHtml', function() {
@@ -379,7 +379,7 @@ describe('tabs', function() {
379379

380380
it('should preserve correct ordering', function() {
381381
function titles() {
382-
return elm.find('ul.nav-tabs li a');
382+
return elm.find('ul.nav-tabs li > div');
383383
}
384384
scope.$apply();
385385
expect(titles().length).toBe(9);
@@ -522,7 +522,7 @@ describe('tabs', function() {
522522
expectContents(['Hello', 'content 1', 'content 2', 'content 3']);
523523

524524
// Select last tab
525-
titles().find('a').eq(3).click();
525+
titles().find('> div').eq(3).click();
526526
expect(contents().eq(3)).toHaveClass('active');
527527
expect(titles().eq(3)).toHaveClass('active');
528528

@@ -536,7 +536,7 @@ describe('tabs', function() {
536536
expect(contents().eq(2)).toHaveClass('active');
537537

538538
// Select 2nd tab ("tab 1")
539-
titles().find('a').eq(1).click();
539+
titles().find('> div').eq(1).click();
540540
expect(titles().eq(1)).toHaveClass('active');
541541
expect(contents().eq(1)).toHaveClass('active');
542542

@@ -632,10 +632,10 @@ describe('tabs', function() {
632632
}
633633

634634
it('should not switch active when clicking on title', function() {
635-
titles().eq(2).find('a').click();
635+
titles().eq(2).find('> div').click();
636636
expectTabActive(scope.tabs[2]);
637637

638-
titles().eq(3).find('a').click();
638+
titles().eq(3).find('> div').click();
639639
expectTabActive(scope.tabs[2]);
640640
});
641641

template/tabs/tab.html

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

0 commit comments

Comments
 (0)