Skip to content

Commit 94221c4

Browse files
committed
Tabs: Use aria-controls instead of the anchor's href to match against location.hash. Fixes #8660 - Tabs: Set initial active tab from location hash for ajax tabs.
1 parent 1ee090e commit 94221c4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tests/unit/tabs/tabs_options.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var disabled = TestHelpers.tabs.disabled,
77
module( "tabs: options" );
88

99
test( "{ active: default }", function() {
10-
expect( 4 );
10+
expect( 6 );
1111

1212
var element = $( "#tabs1" ).tabs();
1313
equal( element.tabs( "option", "active" ), 0, "should be 0 by default" );
@@ -19,6 +19,12 @@ test( "{ active: default }", function() {
1919
equal( element.tabs( "option", "active" ), 2, "should be 2 based on URL" );
2020
state( element, 0, 0, 1 );
2121
element.tabs( "destroy" );
22+
23+
location.hash = "#custom-id";
24+
element = $( "#tabs2" ).tabs();
25+
equal( element.tabs( "option", "active" ), 3, "should be 3 based on URL" );
26+
state( element, 0, 0, 0, 1, 0 );
27+
element.tabs( "destroy" );
2228
location.hash = "#";
2329
});
2430

ui/jquery.ui.tabs.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ $.widget( "ui.tabs", {
5151
var panel,
5252
that = this,
5353
options = this.options,
54-
active = options.active;
54+
active = options.active,
55+
locationHash = location.hash.substring( 1 );
5556

5657
this.running = false;
5758

@@ -80,9 +81,9 @@ $.widget( "ui.tabs", {
8081

8182
if ( active === null ) {
8283
// check the fragment identifier in the URL
83-
if ( location.hash ) {
84-
this.anchors.each(function( i, anchor ) {
85-
if ( anchor.hash === location.hash ) {
84+
if ( locationHash ) {
85+
this.tabs.each(function( i, tab ) {
86+
if ( $( tab ).attr( "aria-controls" ) === locationHash ) {
8687
active = i;
8788
return false;
8889
}

0 commit comments

Comments
 (0)