Skip to content

Commit 7023ed4

Browse files
committed
Tabs: Account for non-tab list items on init. Fixes #8568 - jQuery ui tabs: wrong default active li if ul contains extraneous elements.
1 parent 01e3af4 commit 7023ed4

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

tests/unit/tabs/tabs.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ <h2 id="qunit-userAgent"></h2>
145145
</div>
146146
</div>
147147

148+
<div id="tabs9">
149+
<ul>
150+
<li>not a tab</li>
151+
<li><a href="#tabs9-1">tab</a></li>
152+
</ul>
153+
<div id="tabs9-1"></div>
154+
</div>
155+
148156
</div>
149157
</body>
150158
</html>

tests/unit/tabs/tabs_core.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ test( "disconnected from DOM", function() {
4444
equal( element.find( ".ui-tabs-panel" ).length, 3, "should initialize panels" );
4545
});
4646

47+
test( "non-tab list items", function() {
48+
expect( 2 );
49+
50+
var element = $( "#tabs9" ).tabs();
51+
equal( element.tabs( "option", "active" ), 0, "defaults to first tab" );
52+
equal( element.find( ".ui-tabs-nav li.ui-state-active" ).index(), 1,
53+
"first actual tab is active" );
54+
});
55+
4756
test( "aria-controls", function() {
4857
expect( 7 );
4958
var element = $( "#tabs1" ).tabs(),

tests/unit/tabs/tabs_deprecated.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ <h2 id="qunit-userAgent"></h2>
144144
</div>
145145
</div>
146146

147+
<div id="tabs9">
148+
<ul>
149+
<li>not a tab</li>
150+
<li><a href="#tabs9-1">tab</a></li>
151+
</ul>
152+
<div id="tabs9-1"></div>
153+
</div>
154+
147155
</div>
148156
</body>
149157
</html>

ui/jquery.ui.tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ $.widget( "ui.tabs", {
102102

103103
// handle numbers: negative, out of range
104104
if ( active !== false ) {
105-
active = this.tabs.eq( active ).index();
105+
active = this.tabs.index( this.tabs.eq( active ) );
106106
if ( active === -1 ) {
107107
active = options.collapsible ? false : 0;
108108
}

0 commit comments

Comments
 (0)