Skip to content

Commit 111e71c

Browse files
committed
Tabs: Added aria-labelledby to panels and tabs. Added aria-disabled to tabs. Clean up ARIA attributes on destroy.
1 parent b8fcc39 commit 111e71c

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

ui/jquery.ui.tabs.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,21 +322,22 @@ $.widget( "ui.tabs", {
322322

323323
this.panels = $();
324324

325-
this.anchors.each(function( i, a ) {
326-
var selector, panel, id,
327-
tab = $( a ).closest( "li" );
325+
this.anchors.each(function( i, anchor ) {
326+
var selector, panel, panelId,
327+
anchorId = $( anchor ).uniqueId().attr( "id" ),
328+
tab = $( anchor ).closest( "li" );
328329

329330
// inline tab
330-
if ( isLocal( a ) ) {
331-
selector = a.hash;
331+
if ( isLocal( anchor ) ) {
332+
selector = anchor.hash;
332333
panel = that.element.find( that._sanitizeSelector( selector ) );
333334
// remote tab
334335
} else {
335-
id = that._tabId( tab );
336-
selector = "#" + id;
336+
panelId = that._tabId( tab );
337+
selector = "#" + panelId;
337338
panel = that.element.find( selector );
338339
if ( !panel.length ) {
339-
panel = that._createPanel( id );
340+
panel = that._createPanel( panelId );
340341
panel.insertAfter( that.panels[ i - 1 ] || that.list );
341342
}
342343
panel.attr( "aria-live", "polite" );
@@ -347,7 +348,11 @@ $.widget( "ui.tabs", {
347348
}
348349
tab
349350
.data( "ui-tabs-aria-controls", tab.attr( "aria-controls" ) )
350-
.attr( "aria-controls", selector.substring( 1 ) );
351+
.attr({
352+
"aria-controls": selector.substring( 1 ),
353+
"aria-labelledby": anchorId
354+
});
355+
panel.attr( "aria-labelledby", anchorId );
351356
});
352357

353358
this.panels
@@ -378,8 +383,15 @@ $.widget( "ui.tabs", {
378383

379384
// disable tabs
380385
for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
381-
$( li ).toggleClass( "ui-state-disabled",
382-
( disabled === true || $.inArray( i, disabled ) !== -1 ) );
386+
if ( disabled === true || $.inArray( i, disabled ) !== -1 ) {
387+
$( li )
388+
.addClass( "ui-state-disabled" )
389+
.attr( "aria-disabled", "true" );
390+
} else {
391+
$( li )
392+
.removeClass( "ui-state-disabled" )
393+
.removeAttr( "aria-disabled" );
394+
}
383395
}
384396

385397
this.options.disabled = disabled;
@@ -613,7 +625,8 @@ $.widget( "ui.tabs", {
613625
.removeAttr( "tabIndex" )
614626
.unbind( ".tabs" )
615627
.removeData( "href.tabs" )
616-
.removeData( "load.tabs" );
628+
.removeData( "load.tabs" )
629+
.removeUniqueId();
617630

618631
this.lis.unbind( ".tabs" ).add( this.panels ).each(function() {
619632
if ( $.data( this, "ui-tabs-destroy" ) ) {
@@ -632,7 +645,12 @@ $.widget( "ui.tabs", {
632645
].join( " " ) )
633646
.removeAttr( "tabIndex" )
634647
.removeAttr( "aria-live" )
635-
.removeAttr( "aria-busy" );
648+
.removeAttr( "aria-busy" )
649+
.removeAttr( "aria-selected" )
650+
.removeAttr( "aria-labelledby" )
651+
.removeAttr( "aria-hidden" )
652+
.removeAttr( "aria-expanded" )
653+
.removeAttr( "role" );
636654
}
637655
});
638656

0 commit comments

Comments
 (0)